From 6a158af5be776ec9311f81cd6051f041854acc5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Cunha?= Date: Fri, 20 Dec 2024 14:15:33 +0100 Subject: [PATCH] Add support for flow style arrays We allow users to manually populate secrets that we inject into the rails secret. But we were not supporting the flow style array format, only sequence style. Changelog: fixed --- .../shared-secrets/_generate_secrets.sh.tpl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/templates/shared-secrets/_generate_secrets.sh.tpl b/templates/shared-secrets/_generate_secrets.sh.tpl index eecf56e702..b27dec0e0b 100644 --- a/templates/shared-secrets/_generate_secrets.sh.tpl +++ b/templates/shared-secrets/_generate_secrets.sh.tpl @@ -25,6 +25,21 @@ function fetch_rails_value(){ if [ "${value}" != "null" ]; then echo "${value}"; fi } +# Converts yaml flow style arrays into sequence style. +# If a sequence style is passed, it returns the same sequence. +# If empty is passed it return empty. +# ARG1 [required]: the array, flow or sequence style +# ARG2 [optional]: indentation number (default 0). +# Example, array_to_sequence [1, 2, 3] becomes: +# - 1 +# - 2 +# - 3 +array_to_sequence() { + local array="$1" + local indent="${2:0}" + echo "$array" | yq eval ".[] | \"$(printf '%*s' "$indent" '')- \" + ." - +} + # Args: secretname function label_secret(){ local secret_name=$1 @@ -168,7 +183,9 @@ if [ -n "$env" ]; then encrypted_settings_key_base=$(fetch_rails_value secrets.yml "${env}.encrypted_settings_key_base") active_record_encryption_primary_keys=$(fetch_rails_value secrets.yml "${env}.active_record_encryption_primary_key") + active_record_encryption_primary_keys=$(array_to_sequence "$active_record_encryption_primary_keys") active_record_encryption_deterministic_keys=$(fetch_rails_value secrets.yml "${env}.active_record_encryption_deterministic_key") + active_record_encryption_deterministic_keys=$(array_to_sequence "$active_record_encryption_deterministic_keys") active_record_encryption_key_derivation_salt=$(fetch_rails_value secrets.yml "${env}.active_record_encryption_key_derivation_salt") fi; -- GitLab