gistfile1.txt
· 1.7 KiB · Text
Sin formato
function cmd::identity::_show() {
local name=""
while [[ $# -gt 0 ]]; do
case "$1" in
--name) name="$2"; shift 2 ;;
--help) cmd::identity::help; return ;;
*) log::error "Unknown flag: $1"; return 1 ;;
esac
done
[[ -z "$name" ]] && { log::error "Missing required flag: --name"; return 1; }
identity::require_exists "$name" || return 1
# Gather identity-level metadata
local policy strict auto rules_list peer_count
policy=$(identity::policy "$name")
strict=$(identity::rule_flags "$name" "strict_rule")
auto=$(identity::rule_flags "$name" "auto_apply")
rules_list=$(identity::rules "$name" | tr '\n' ',' | sed 's/,$//' | sed 's/,/, /g')
local data
data=$(identity::show_data "$name")
peer_count=$(echo "$data" | grep '^peer_count|' | cut -d'|' -f2)
# Precompute handshakes once for all peers in this identity
declare -A _id_handshakes=()
while IFS=$'\t' read -r pk ts; do
[[ -n "$pk" ]] && _id_handshakes["$pk"]="$ts"
done < <(wg show "$(config::interface)" latest-handshakes 2>/dev/null)
# Header
echo ""
ui::row "Identity" "$name"
ui::row "Policy" "$policy"
ui::row "Rules" "${rules_list:-—}"
ui::row "Strict rule" "$(ui::bool "$strict")"
ui::row "Auto apply" "$(ui::bool "$auto")"
ui::row "Peers" "$peer_count"
echo ""
# Device list
while IFS='|' read -r key val type_val index_val; do
case "$key" in
name|peer_count) ;;
device)
local status=""
status=$(cmd::identity::_device_status "$val" _id_handshakes)
ui::identity::device_row "$val" "$type_val" "$index_val" "$status"
;;
esac
done <<< "$data"
echo ""
}
| 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 | } |