Ultima attività 1 month ago

nuno ha revisionato questo gist 1 month ago. Vai alla revisione

1 file changed, 40 insertions

gistfile1.txt(file creato)

@@ -0,0 +1,40 @@
1 + function cmd::identity::_rule_assign() {
2 + local name="" rule=""
3 + while [[ $# -gt 0 ]]; do
4 + case "$1" in
5 + --name) name="$2"; shift 2 ;;
6 + --rule) rule="$2"; shift 2 ;;
7 + *) log::error "Unknown flag: $1"; return 1 ;;
8 + esac
9 + done
10 +
11 + [[ -z "$name" ]] && { log::error "Missing required flag: --name"; return 1; }
12 + [[ -z "$rule" ]] && { log::error "Missing required flag: --rule"; return 1; }
13 + identity::require_exists "$name" || return 1
14 + rule::exists "$rule" || { log::error "Rule not found: ${rule}"; return 1; }
15 +
16 + local exit_code
17 + identity::add_rule "$name" "$rule"
18 + exit_code=$?
19 +
20 + if [[ $exit_code -eq 2 ]]; then
21 + log::warn "Rule '${rule}' is already assigned to identity '${name}'"
22 + return 0
23 + fi
24 +
25 + log::ok "Rule '${rule}' assigned to identity '${name}'"
26 +
27 + # Reapply rules if auto_apply
28 + local auto
29 + auto=$(identity::rule_flags "$name" "auto_apply")
30 + if [[ "$auto" != "false" ]]; then
31 + log::info "Reapplying rules for all peers in identity '${name}'..."
32 + identity::reapply_rules "$name"
33 + log::ok "Rules reapplied"
34 + fi
35 +
36 + # Warn about strict_rule
37 + if policy::strict_rule "$(identity::policy "$name")"; then
38 + log::warn "Strict rule is enabled for identity '${name}' — peer rules will not be additive"
39 + fi
40 + }
Più nuovi Più vecchi