Skip to content
This repository has been archived by the owner on Jan 25, 2023. It is now read-only.

Add support for defining encryption key #11

Merged
merged 7 commits into from
May 24, 2018

Conversation

thevilledev
Copy link
Contributor

Adds a CLI flag for defining encryption keys to Consul configuration. This is a non-breaking change as encrypt key uses an empty string as a default value.

Copy link
Collaborator

@josh-padnick josh-padnick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for submitting this PR! As it's been about 4 weeks since we're responding, I'll go ahead and commit these changes to your branch as a PR there so you can easily add them here.

@@ -150,6 +151,7 @@ function generate_consul_config {
local readonly user="$4"
local readonly cluster_tag_name="$5"
local readonly cluster_size_instance_metadata_key_name="$6"
local readonly encrypt="$7"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use a var name like encrypt_key so users don't confuse this with a boolean.

@@ -341,7 +354,8 @@ function run {
"$config_dir" \
"$user" \
"$cluster_tag_name" \
"$CLUSTER_SIZE_INSTANCE_METADATA_KEY_NAME"
"$CLUSTER_SIZE_INSTANCE_METADATA_KEY_NAME" \
"$encrypt"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My concern with this line is that if we add any additional vars in the future and $encrypt is empty, the Bash function will ignore $encrypt entirely and the function arguments won't be passed to the correct argument position. Therefore, we need a null equivalent in Bash, but since Bash doesn't give us one, we should define a readonly var at the top like this:

readonly EMPTY_VAL="__EMPTY__"

Then we replace

local encrypt=""

with

local encrypt="$EMPTY_VAL"

Finally, we can update the code as follows:

# old
local encrypt_config=""
if [[ "$encrypt" != "" ]]; then
  encrypt_config="\"encrypt\": \"$encrypt\","
fi

...

   "ui": true,
   $encrypt_config,

...
# new
if [[ "$encrypt" == "$EMPTY_VAL" ]]; then
  encrypt=""
fi

...

   "ui": true,
   "encrypt": "$encrypt",

...

@josh-padnick
Copy link
Collaborator

Alright, just uploaded the changes and manually validated so we're good now. Merging!

@josh-padnick josh-padnick merged commit 448f86c into hashicorp:master May 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants