check if reference exists in key group before adding, skip if it does
This commit is contained in:
@@ -1,10 +1,8 @@
|
|||||||
keys:
|
keys:
|
||||||
hosts:
|
hosts:
|
||||||
- &laptop age1ldgnl53dmvl4fjz6hgdj0cvensagddn3ltpmxfm72m8q273w75fsk42p8v
|
- &laptop age1ldgnl53dmvl4fjz6hgdj0cvensagddn3ltpmxfm72m8q273w75fsk42p8v
|
||||||
- &nixos-homelab-00 age1kc49egwnslqjjy7yknlv9spxa2xvrq4l6alxumu54ez8vwvf3e2q5ff63k
|
|
||||||
creation_rules:
|
creation_rules:
|
||||||
- path_regex: secrets/[^/]+\.(yaml|json|env|ini)$
|
- path_regex: secrets/[^/]+\.(yaml|json|env|ini)$
|
||||||
key_groups:
|
key_groups:
|
||||||
- age:
|
- age:
|
||||||
- *laptop
|
- *laptop
|
||||||
- *nixos-homelab-00
|
|
||||||
|
|||||||
+8
-4
@@ -14,7 +14,7 @@ function sops_update_age_key() {
|
|||||||
keyname="$1"
|
keyname="$1"
|
||||||
key="$2"
|
key="$2"
|
||||||
|
|
||||||
if [[ -n $(yq ".keys.hosts[] | select(anchor == \"$keyname\")" "${SOPS_FILE}") ]]; then
|
if [[ -n $(yq ".keys.hosts[] | select(anchor == \"$keyname\")" "${SOPS_FILE}") ]]; then
|
||||||
echo "Updating existing ${keyname} key"
|
echo "Updating existing ${keyname} key"
|
||||||
yq -i "(.keys.hosts[] | select(anchor == \"$keyname\")) = \"$key\"" "$SOPS_FILE"
|
yq -i "(.keys.hosts[] | select(anchor == \"$keyname\")) = \"$key\"" "$SOPS_FILE"
|
||||||
else
|
else
|
||||||
@@ -27,9 +27,13 @@ function sops_update_age_key() {
|
|||||||
function sops_add_host_to_key_groups() {
|
function sops_add_host_to_key_groups() {
|
||||||
h="\"$1\"" # quoted hostname for yaml
|
h="\"$1\"" # quoted hostname for yaml
|
||||||
|
|
||||||
echo "Adding key to key group"
|
if [[ -z $(yq "select(.creation_rules[].key_groups[].age[] == $h)" "$SOPS_FILE") ]]; then
|
||||||
yq -i ".creation_rules[].key_groups[].age += [ $h ]" "$SOPS_FILE"
|
echo "Adding key to key group"
|
||||||
yq -i ".creation_rules[].key_groups[].age[-1] alias = $h" "$SOPS_FILE"
|
yq -i ".creation_rules[].key_groups[].age += [ $h ]" "$SOPS_FILE"
|
||||||
|
yq -i ".creation_rules[].key_groups[].age[-1] alias = $h" "$SOPS_FILE"
|
||||||
|
else
|
||||||
|
echo "Reference already exists in key group"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Use generated ssh key generate age key, and update sops
|
# Use generated ssh key generate age key, and update sops
|
||||||
|
|||||||
Reference in New Issue
Block a user