From 890bd4e5952ad62b3d6cb29ff7c9a2c117ef413c Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Wed, 6 May 2020 10:11:13 +0200 Subject: [PATCH] new: [rsync-backup-target] prevent duplicate key for different identifier Signed-off-by: Valentin Lab --- rsync-backup-target/hooks/init | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/rsync-backup-target/hooks/init b/rsync-backup-target/hooks/init index 77e111f..04fee96 100755 --- a/rsync-backup-target/hooks/init +++ b/rsync-backup-target/hooks/init @@ -29,9 +29,14 @@ local_path_key=/etc/rsync/keys host_path_key="$SERVICE_CONFIGSTORE${local_path_key}" key_nb=0 -volume_keys=() -all_keys=" " +## ident are unique by construction (they are struct keys) +## but keys need to be also unique +declare -A keys while read-0 ident key; do + if [ "${keys[$key]}" ]; then + err "Duplicate key: key for ident '$ident' is same as ident '${keys["$key"]}'." + exit 1 + fi if ! [[ "$ident" =~ ^[a-zA-Z0-9._-]+$ ]]; then err "Invalid identifier '$ident'," \ "please use only alphanumerical char, dots, dash or underscores." @@ -39,10 +44,9 @@ while read-0 ident key; do fi debug "Creating access key for ${ident}" || true echo "$key" | file_put "$host_path_key/${ident}.pub" + keys["$key"]="$ident" done < <(echo "$keys" | shyaml key-values-0) -volume_keys+=("$host_path_key:$local_path_key:ro") - init-config-add "\ $SERVICE_NAME: volumes: