use op cli to fetch secrets for connect
This commit is contained in:
@@ -31,7 +31,7 @@ unset_prev_secrets() {
|
|||||||
# Install op-cli
|
# Install op-cli
|
||||||
install_op_cli() {
|
install_op_cli() {
|
||||||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||||
curl -sSfLo op.zip "https://cache.agilebits.com/dist/1P/op2/pkg/v2.6.0-beta.06/op_linux_amd64_v2.6.0-beta.06.zip"
|
curl -sSfLo op.zip "https://cache.agilebits.com/dist/1P/op2/pkg/v2.7.1-beta.01/op_linux_amd64_v2.7.1-beta.01.zip"
|
||||||
unzip -od /usr/local/bin/ op.zip && rm op.zip
|
unzip -od /usr/local/bin/ op.zip && rm op.zip
|
||||||
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||||
curl -sSfLo op.tar.gz "https://cache.agilebits.com/dist/1P/op2/pkg/v2.6.0-beta.06/1password-cli_v2.6.0-beta.06_darwin_amd64.tar.gz"
|
curl -sSfLo op.tar.gz "https://cache.agilebits.com/dist/1P/op2/pkg/v2.6.0-beta.06/1password-cli_v2.6.0-beta.06_darwin_amd64.tar.gz"
|
||||||
@@ -89,24 +89,13 @@ populating_secret() {
|
|||||||
|
|
||||||
# Load environment variables using op cli. Iterate over them to find 1Password references, load the secret values,
|
# Load environment variables using op cli. Iterate over them to find 1Password references, load the secret values,
|
||||||
# and make them available as environment variables in the next steps.
|
# and make them available as environment variables in the next steps.
|
||||||
extract_using_service_account() {
|
extract_secrets() {
|
||||||
IFS=$'\n'
|
IFS=$'\n'
|
||||||
for env_var in $(op env ls); do
|
for env_var in $(op env ls); do
|
||||||
populating_secret $env_var
|
populating_secret $env_var
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# Load environment variables using connect service. Iterate over hem to find 1Password references, load the secret values,
|
|
||||||
# and make them available as environment variables in the next steps.
|
|
||||||
extract_using_connect() {
|
|
||||||
IFS=$'\n'
|
|
||||||
|
|
||||||
for possible_ref in $(printenv | grep "=op://" | grep -v "^#"); do
|
|
||||||
env_var=$(echo "$possible_ref" | cut -d '=' -f1)
|
|
||||||
populating_secret $env_var
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
read -r -a managed_variables <<< "$(printenv $managed_variables_var)"
|
read -r -a managed_variables <<< "$(printenv $managed_variables_var)"
|
||||||
|
|
||||||
if [ -z "$OP_CONNECT_TOKEN" ] || [ -z "$OP_CONNECT_HOST" ]; then
|
if [ -z "$OP_CONNECT_TOKEN" ] || [ -z "$OP_CONNECT_HOST" ]; then
|
||||||
@@ -122,12 +111,7 @@ printf "Authenticated with %s \n" $auth_type
|
|||||||
|
|
||||||
unset_prev_secrets
|
unset_prev_secrets
|
||||||
install_op_cli
|
install_op_cli
|
||||||
|
extract_secrets
|
||||||
if [ "$auth_type" == "$SERVICE_ACCOUNT" ]; then
|
|
||||||
extract_using_service_account
|
|
||||||
elif [ "$auth_type" == "$CONNECT" ]; then
|
|
||||||
extract_using_connect
|
|
||||||
fi
|
|
||||||
|
|
||||||
unset IFS
|
unset IFS
|
||||||
# Add extra env var that lists which secrets are managed by 1Password so that in a later step
|
# Add extra env var that lists which secrets are managed by 1Password so that in a later step
|
||||||
|
|||||||
Reference in New Issue
Block a user