Refactor telemetry checks, relax method validation
Reformat telemetry pre-checks in misc/api.func for clearer multi-line condition handling and remove stray whitespace around the curl response logging. Tweak misc/build.func comment line (minor encoding/visual cleanup). In misc/data/service.go remove the strict allowedMethod map and its validation so the 'method' field is treated as optional/flexible; keep sanitization and numeric validations unchanged. These changes improve readability and allow custom method values without breaking behavior.
This commit is contained in:
parent
7c3688cd0a
commit
ce375b02aa
@ -192,9 +192,18 @@ post_to_api() {
|
|||||||
echo "[DEBUG] post_to_api() called" >&2
|
echo "[DEBUG] post_to_api() called" >&2
|
||||||
|
|
||||||
# Silent fail - telemetry should never break scripts
|
# Silent fail - telemetry should never break scripts
|
||||||
command -v curl &>/dev/null || { echo "[DEBUG] curl not found, skipping" >&2; return 0; }
|
command -v curl &>/dev/null || {
|
||||||
[[ "${DIAGNOSTICS:-no}" == "no" ]] && { echo "[DEBUG] DIAGNOSTICS=no, skipping" >&2; return 0; }
|
echo "[DEBUG] curl not found, skipping" >&2
|
||||||
[[ -z "${RANDOM_UUID:-}" ]] && { echo "[DEBUG] RANDOM_UUID empty, skipping" >&2; return 0; }
|
return 0
|
||||||
|
}
|
||||||
|
[[ "${DIAGNOSTICS:-no}" == "no" ]] && {
|
||||||
|
echo "[DEBUG] DIAGNOSTICS=no, skipping" >&2
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
[[ -z "${RANDOM_UUID:-}" ]] && {
|
||||||
|
echo "[DEBUG] RANDOM_UUID empty, skipping" >&2
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
echo "[DEBUG] Checks passed: DIAGNOSTICS=$DIAGNOSTICS RANDOM_UUID=$RANDOM_UUID NSAPP=$NSAPP" >&2
|
echo "[DEBUG] Checks passed: DIAGNOSTICS=$DIAGNOSTICS RANDOM_UUID=$RANDOM_UUID NSAPP=$NSAPP" >&2
|
||||||
|
|
||||||
@ -234,7 +243,7 @@ EOF
|
|||||||
http_code=$(curl -sS -w "%{http_code}" -m "${TELEMETRY_TIMEOUT}" -X POST "${TELEMETRY_URL}" \
|
http_code=$(curl -sS -w "%{http_code}" -m "${TELEMETRY_TIMEOUT}" -X POST "${TELEMETRY_URL}" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d "$JSON_PAYLOAD" -o /dev/stderr 2>&1) || true
|
-d "$JSON_PAYLOAD" -o /dev/stderr 2>&1) || true
|
||||||
|
|
||||||
echo "[DEBUG] HTTP response code: $http_code" >&2
|
echo "[DEBUG] HTTP response code: $http_code" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1882,7 +1882,7 @@ advanced_settings() {
|
|||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
# ══════════════<E29590><E29590>════════════════════════════════════════════════════════════
|
# ══════════════<E29590><E29590><EFBFBD>════════════════════════════════════════════════════════════
|
||||||
# STEP 3: Container ID
|
# STEP 3: Container ID
|
||||||
# ═══════════════════════════════════════════════════════════════════════════
|
# ═══════════════════════════════════════════════════════════════════════════
|
||||||
3)
|
3)
|
||||||
|
|||||||
@ -320,9 +320,6 @@ var (
|
|||||||
"fedora": true, "rocky": true, "alma": true, "centos": true,
|
"fedora": true, "rocky": true, "alma": true, "centos": true,
|
||||||
"opensuse": true, "gentoo": true, "openeuler": true,
|
"opensuse": true, "gentoo": true, "openeuler": true,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allowed values for 'method' field
|
|
||||||
allowedMethod = map[string]bool{"default": true, "advanced": true, "": true}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func sanitizeShort(s string, max int) string {
|
func sanitizeShort(s string, max int) string {
|
||||||
@ -371,10 +368,8 @@ func validate(in *TelemetryIn) error {
|
|||||||
return errors.New("invalid os_type")
|
return errors.New("invalid os_type")
|
||||||
}
|
}
|
||||||
|
|
||||||
// method is optional but if provided must be valid
|
// method is optional and flexible - just sanitized, no strict validation
|
||||||
if !allowedMethod[in.Method] {
|
// Values like "default", "advanced", "mydefaults-global", "mydefaults-app" are all valid
|
||||||
return errors.New("invalid method")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate numeric ranges
|
// Validate numeric ranges
|
||||||
if in.CTType < 0 || in.CTType > 2 {
|
if in.CTType < 0 || in.CTType > 2 {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user