From db69e437d53591e07ebac3318de5f4507a17e8dc Mon Sep 17 00:00:00 2001 From: Greg Karekinian Date: Sat, 11 Jul 2026 20:08:58 +0200 Subject: [PATCH] Remove sanitize node script and pre-commit hook This is no longer needed with the properly set allowed attributes --- .githooks/pre-commit | 40 -------------------- README.md | 4 -- scripts/util/sanitize_node.sh | 69 ----------------------------------- 3 files changed, 113 deletions(-) delete mode 100755 .githooks/pre-commit delete mode 100755 scripts/util/sanitize_node.sh diff --git a/.githooks/pre-commit b/.githooks/pre-commit deleted file mode 100755 index e97f9cb..0000000 --- a/.githooks/pre-commit +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -SCRIPT="$(git rev-parse --show-toplevel)/scripts/util/sanitize_node.sh" - -FILES=$(git diff --cached --name-only --diff-filter=ACM -- 'nodes/*.json' || true) - -[[ -z "$FILES" ]] && exit 0 - -DIRTY=0 - -while IFS= read -r file; do - staged_tmp=$(mktemp) - sanitized_tmp=$(mktemp) - - # 1. get staged version - git show ":$file" > "$staged_tmp" - - # 2. sanitize IN PLACE (on temp copy) - cp "$staged_tmp" "$sanitized_tmp" - "$SCRIPT" "$sanitized_tmp" - - # 3. if sanitizer changed file, update working tree - if ! diff -q "$staged_tmp" "$sanitized_tmp" >/dev/null; then - cp "$sanitized_tmp" "$file" - echo "Sanitized: $file" - DIRTY=1 - fi - - rm -f "$staged_tmp" "$sanitized_tmp" - -done <<< "$FILES" - -if [[ "$DIRTY" -ne 0 ]]; then - echo "" - echo "Commit paused, sanitized files must be re-staged." - exit 1 -fi - -exit 0 diff --git a/README.md b/README.md index 1fcb982..e7b2df0 100644 --- a/README.md +++ b/README.md @@ -28,10 +28,6 @@ Clone this repository, `cd` into it, and run: bundle install -### Enable Git hooks - - git config core.hooksPath .githooks - ## Common tasks ### Bootstrap a new host server diff --git a/scripts/util/sanitize_node.sh b/scripts/util/sanitize_node.sh deleted file mode 100755 index 99d4ec3..0000000 --- a/scripts/util/sanitize_node.sh +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/env bash -# Strip the top-level "override" and "default" attributes from Chef node JSON files. -# -# Usage: -# ./scripts/util/strip_node_attrs.sh [ ...] -# ./scripts/util/strip_node_attrs.sh --all -# -# A may be a bare node name (e.g. "prometheus-1"), a path relative to the -# repository root (e.g. "nodes/prometheus-1.json"), or an absolute path. -# -# Exit codes: -# 0 - all target files processed successfully -# 1 - one or more targets could not be processed (missing args, missing jq, -# file not found, invalid JSON, or write failure) - -set -uo pipefail - -command -v jq >/dev/null 2>&1 || exit 1 - -root="$(git rev-parse --show-toplevel 2>/dev/null)" || root="$(pwd)" - -targets=() -if [ "$#" -eq 0 ]; then - exit 1 -fi - -for arg in "$@"; do - if [ "$arg" = "--all" ]; then - shopt -s nullglob - for f in "$root"/nodes/*.json; do - targets+=("$f") - done - shopt -u nullglob - continue - fi - - if [[ "$arg" == */* ]]; then - if [[ "$arg" = /* ]]; then - targets+=("$arg") - else - targets+=("$root/$arg") - fi - else - targets+=("$root/nodes/$arg.json") - fi -done - -if [ "${#targets[@]}" -eq 0 ]; then - exit 1 -fi - -rc=0 -for file in "${targets[@]}"; do - [ -f "$file" ] || { rc=1; continue; } - - jq -e . "$file" >/dev/null 2>&1 || { rc=1; continue; } - - tmp="$(mktemp "${file}.XXXXXX")" || { rc=1; continue; } - if jq --indent 2 'del(.override, .default)' "$file" > "$tmp" 2>/dev/null; then - truncate -s -1 "$tmp" 2>/dev/null || true - mv "$tmp" "$file" || { rm -f "$tmp"; rc=1; continue; } - else - rm -f "$tmp" - rc=1 - continue - fi -done - -exit "$rc"