provisioning-catalog/playbooks/bootstrap_initial/steps/emit_audit.nu

24 lines
766 B
Text
Raw Permalink Normal View History

#!/usr/bin/env nu
def main [
--workspace: string = ""
--event-type: string = "bootstrap_complete"
--dry-run
]: nothing -> nothing {
let ws = if ($workspace | is-not-empty) { $workspace } else { $env.PLAYBOOK_PARAM_WORKSPACE? | default "unknown" }
let subject = $"ops.audit.($ws)"
let payload = { event_type: $event_type, workspace: $ws, timestamp: (date now | format date "%Y-%m-%dT%H:%M:%SZ") } | to json
if $dry_run {
print $"[dry-run] would publish to ($subject): ($payload)"
return
}
let r = do { ^nats pub $subject $payload } | complete
if $r.exit_code != 0 {
print $"WARNING: audit emit failed: ($r.stderr | str trim)"
} else {
print $"audit event published to ($subject)"
}
}