Skip to content

Commit 2e8b574

Browse files
committed
more flexible user options for gocd encryption #17556
1 parent 60fabd4 commit 2e8b574

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### 0.6.2 (2019-Apr-22)
2+
3+
* more flexible user options for gocd encryption in encrypt_with_gocd_top
4+
15
### 0.6.1 (2019-Apr-22)
26

37
* setup publish task

src/secret-ops

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,24 @@ function secret_ops::encrypt_with_gocd_common {
5252
# Encrypts any string, uses GoCD server.
5353
function secret_ops::encrypt_with_gocd_top {
5454
local variable_to_encrypt=${1?variable_to_encrypt not set}
55-
56-
url_dir="${USER}"
57-
if [[ "${USER}" == "go" ]]; then
58-
url_dir="gocd"
55+
local user=${2:-}
56+
url_dir=$user
57+
if [ -z ${user} ]; then
58+
user="$(whoami)"
59+
url_dir=$user
60+
if [[ "${url_dir}" == "go" ]]; then
61+
url_dir="gocd"
62+
fi
63+
fi
64+
if [ -z ${url_dir} ]; then
65+
echo "Unknown user name"
66+
exit 5
5967
fi
6068
local my_gocd_pass
6169
my_gocd_pass=$(vault read -field=value secret/${url_dir}/gocd_password)
6270
if [[ $? != "0" ]]; then exit 1; fi
6371

64-
secret_ops::encrypt_with_gocd_common "${variable_to_encrypt}" "go.ai-traders.com" "-u ${USER}:${my_gocd_pass}"
72+
secret_ops::encrypt_with_gocd_common "${variable_to_encrypt}" "go.ai-traders.com" "-u ${user}:${my_gocd_pass}"
6573
}
6674
function secret_ops::encrypt_with_gocd_base {
6775
local variable_to_encrypt=${1?variable_to_encrypt not set}

tasks

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ case "${command}" in
6565
--file secret-ops.tar.gz
6666
;;
6767
generate_vault_token)
68-
set -e
6968
vault_token=$(vault token create -ttl=48h -policy=gocd -field token -metadata gocd_renew=true)
7069
secured_token_gocd=$(secret_ops::encrypt_with_gocd_top "${vault_token}")
7170
echo "Generated token: ${vault_token} and encrypted by GoCD server"

test/bats/01.bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ load '/opt/bats-assert/load.bash'
1010
}
1111

1212
@test "secret_ops::encrypt_with_gocd_top fails if USER cannot read secret" {
13-
run /bin/bash -c "source src/secret-ops && USER=dummy secret_ops::encrypt_with_gocd_top mydata"
13+
run /bin/bash -c "source src/secret-ops && secret_ops::encrypt_with_gocd_top mydata dummy"
1414
# do not test for output, because it may be different on workstation and on
1515
# go-agent (due to different vault policies)
1616
assert_equal "$status" 1

0 commit comments

Comments
 (0)