nuno ревизій цього gist 1 month ago. До ревизії
1 file changed, 68 insertions
gistfile1.txt(файл створено)
| @@ -0,0 +1,68 @@ | |||
| 1 | + | function cmd::export::_full() { | |
| 2 | + | local no_config="${1:-false}" no_peers="${2:-false}" | |
| 3 | + | ||
| 4 | + | local sections=() | |
| 5 | + | ||
| 6 | + | # Config | |
| 7 | + | if ! $no_config; then | |
| 8 | + | local config_json="{}" | |
| 9 | + | [[ -f "$(ctx::config_file)" ]] && config_json=$(cmd::export::_compact_json "$(ctx::config_file)") | |
| 10 | + | sections+=("\"config\":${config_json}") | |
| 11 | + | fi | |
| 12 | + | ||
| 13 | + | # Peers | |
| 14 | + | if ! $no_peers; then | |
| 15 | + | local -a peer_jsons=() | |
| 16 | + | for conf in "$(ctx::clients)"/*.conf; do | |
| 17 | + | [[ -f "$conf" ]] || continue | |
| 18 | + | local pname | |
| 19 | + | pname=$(basename "$conf" .conf) | |
| 20 | + | local peer_export | |
| 21 | + | peer_export=$(cmd::export::_peer_data "$pname") | |
| 22 | + | [[ -n "$peer_export" ]] && peer_jsons+=("$peer_export") | |
| 23 | + | done | |
| 24 | + | local peers_array | |
| 25 | + | peers_array=$(printf '%s\n' "${peer_jsons[@]:-}" | paste -sd ',' -) | |
| 26 | + | sections+=("\"peers\":[${peers_array:-}]") | |
| 27 | + | fi | |
| 28 | + | ||
| 29 | + | # Rules — raw JSON files | |
| 30 | + | local -a rule_jsons=() | |
| 31 | + | for rule_file in "$(ctx::rules)"/*.rule "$(ctx::rules)/base"/*.rule; do | |
| 32 | + | [[ -f "$rule_file" ]] || continue | |
| 33 | + | rule_jsons+=("$(cmd::export::_compact_json "$rule_file")") | |
| 34 | + | done | |
| 35 | + | local rules_array | |
| 36 | + | rules_array=$(printf '%s\n' "${rule_jsons[@]:-}" | paste -sd ',' -) | |
| 37 | + | sections+=("\"rules\":[${rules_array:-}]") | |
| 38 | + | ||
| 39 | + | # Identities | |
| 40 | + | local -a id_jsons=() | |
| 41 | + | for id_file in "$(ctx::identities)"/*.identity; do | |
| 42 | + | [[ -f "$id_file" ]] || continue | |
| 43 | + | id_jsons+=("$(cmd::export::_compact_json "$id_file")") | |
| 44 | + | done | |
| 45 | + | local ids_array | |
| 46 | + | ids_array=$(printf '%s\n' "${id_jsons[@]:-}" | paste -sd ',' -) | |
| 47 | + | sections+=("\"identities\":[${ids_array:-}]") | |
| 48 | + | ||
| 49 | + | # Groups | |
| 50 | + | local -a grp_jsons=() | |
| 51 | + | for grp_file in "$(ctx::groups)"/*.group; do | |
| 52 | + | [[ -f "$grp_file" ]] || continue | |
| 53 | + | grp_jsons+=("$(cmd::export::_compact_json "$grp_file")") | |
| 54 | + | done | |
| 55 | + | local grps_array | |
| 56 | + | grps_array=$(printf '%s\n' "${grp_jsons[@]:-}" | paste -sd ',' -) | |
| 57 | + | sections+=("\"groups\":[${grps_array:-}]") | |
| 58 | + | ||
| 59 | + | # Flat JSON files | |
| 60 | + | [[ -f "$(ctx::policies)" ]] && sections+=("\"policies\":$(cat "$(ctx::policies)")") | |
| 61 | + | [[ -f "$(ctx::subnets)" ]] && sections+=("\"subnets\":$(cat "$(ctx::subnets)")") | |
| 62 | + | [[ -f "$(ctx::net)" ]] && sections+=("\"services\":$(cat "$(ctx::net)")") | |
| 63 | + | [[ -f "$(ctx::hosts)" ]] && sections+=("\"hosts\":$(cat "$(ctx::hosts)")") | |
| 64 | + | ||
| 65 | + | local data | |
| 66 | + | data=$(printf '%s\n' "${sections[@]}" | paste -sd ',' -) | |
| 67 | + | cmd::export::_envelope "full" "{${data}}" | |
| 68 | + | } | |
Новіше
Пізніше