nuno revisó este gist 1 month ago. Ir a la revisión
1 file changed, 54 insertions
gistfile1.txt(archivo creado)
| @@ -0,0 +1,54 @@ | |||
| 1 | + | function cmd::identity::_show() { | |
| 2 | + | local name="" | |
| 3 | + | while [[ $# -gt 0 ]]; do | |
| 4 | + | case "$1" in | |
| 5 | + | --name) name="$2"; shift 2 ;; | |
| 6 | + | --help) cmd::identity::help; return ;; | |
| 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 | + | identity::require_exists "$name" || return 1 | |
| 13 | + | ||
| 14 | + | # Gather identity-level metadata | |
| 15 | + | local policy strict auto rules_list peer_count | |
| 16 | + | policy=$(identity::policy "$name") | |
| 17 | + | strict=$(identity::rule_flags "$name" "strict_rule") | |
| 18 | + | auto=$(identity::rule_flags "$name" "auto_apply") | |
| 19 | + | rules_list=$(identity::rules "$name" | tr '\n' ',' | sed 's/,$//' | sed 's/,/, /g') | |
| 20 | + | ||
| 21 | + | local data | |
| 22 | + | data=$(identity::show_data "$name") | |
| 23 | + | peer_count=$(echo "$data" | grep '^peer_count|' | cut -d'|' -f2) | |
| 24 | + | ||
| 25 | + | # Precompute handshakes once for all peers in this identity | |
| 26 | + | declare -A _id_handshakes=() | |
| 27 | + | while IFS=$'\t' read -r pk ts; do | |
| 28 | + | [[ -n "$pk" ]] && _id_handshakes["$pk"]="$ts" | |
| 29 | + | done < <(wg show "$(config::interface)" latest-handshakes 2>/dev/null) | |
| 30 | + | ||
| 31 | + | # Header | |
| 32 | + | echo "" | |
| 33 | + | ui::row "Identity" "$name" | |
| 34 | + | ui::row "Policy" "$policy" | |
| 35 | + | ui::row "Rules" "${rules_list:-—}" | |
| 36 | + | ui::row "Strict rule" "$(ui::bool "$strict")" | |
| 37 | + | ui::row "Auto apply" "$(ui::bool "$auto")" | |
| 38 | + | ui::row "Peers" "$peer_count" | |
| 39 | + | echo "" | |
| 40 | + | ||
| 41 | + | # Device list | |
| 42 | + | while IFS='|' read -r key val type_val index_val; do | |
| 43 | + | case "$key" in | |
| 44 | + | name|peer_count) ;; | |
| 45 | + | device) | |
| 46 | + | local status="" | |
| 47 | + | status=$(cmd::identity::_device_status "$val" _id_handshakes) | |
| 48 | + | ui::identity::device_row "$val" "$type_val" "$index_val" "$status" | |
| 49 | + | ;; | |
| 50 | + | esac | |
| 51 | + | done <<< "$data" | |
| 52 | + | ||
| 53 | + | echo "" | |
| 54 | + | } | |
Siguiente
Anterior