Skip to content

Commit e28960d

Browse files
authored
Merge pull request #4 from 1Password/item-and-vault-names
2 parents 7bf534f + 8d95cf6 commit e28960d

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ jobs:
3939
run: printenv
4040
- name: Assert removed secrets
4141
run: ./tests/assert-env-unset.sh
42-
- name: Load secret again
42+
- name: Load secrets by vault and item titles
4343
uses: ./ # 1password/load-secrets-action@<version>
4444
env:
45-
SECRET: op://v5pz6venw4roosmkzdq2nhpv6u/hrgkzhrlvscomepxlgafb2m3ca/password
46-
SECRET_IN_SECTION: op://v5pz6venw4roosmkzdq2nhpv6u/hrgkzhrlvscomepxlgafb2m3ca/test-section/password
47-
MULTILINE_SECRET: op://v5pz6venw4roosmkzdq2nhpv6u/ghtz3jvcc6dqmzc53d3r3eskge/notesPlain
45+
SECRET: op://acceptance-tests/test-secret/password
46+
SECRET_IN_SECTION: op://acceptance-tests/test-secret/test-section/password
47+
MULTILINE_SECRET: op://acceptance-tests/multiline-secret/notesPlain
4848
- name: Print environment variables with masked secrets
4949
run: printenv
5050
- name: Assert test secret values again

entrypoint.sh

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ if [ "$INPUT_UNSET_PREVIOUS" == "true" ]; then
2727
managed_variables=()
2828
fi
2929

30+
curl_headers=(-H "Content-Type: application/json" -H "Authorization: Bearer $OP_CONNECT_TOKEN")
31+
3032
# Iterate over environment varables to find 1Password references, load the secret values,
3133
# and make them available as environment variables in the next steps.
3234
IFS=$'\n'
@@ -70,8 +72,27 @@ for possible_ref in $(printenv | grep "=op://" | grep -v "^#"); do
7072
section=""
7173
fi
7274

75+
if [[ $(echo -n $(echo $vault | grep "^[a-z0-9]*$") | wc -c) -ne 26 ]]; then
76+
echo "Getting vault ID from vault name: $vault"
77+
vault=$(curl -sSf "${curl_headers[@]}" "$OP_CONNECT_HOST/v1/vaults?filter=name%20eq%20%22$vault%22" | jq -r '.[0] | .id')
78+
if [ -z "$vault" ]; then
79+
echo "Could not find vault ID for vault: $vault"
80+
exit 1
81+
fi
82+
fi
83+
84+
if [[ $(echo -n $(echo $item | grep "^[a-z0-9]*$") | wc -c) -ne 26 ]]; then
85+
echo "Getting item ID from vault $vault..."
86+
item=$(curl -sSf "${curl_headers[@]}" "$OP_CONNECT_HOST/v1/vaults/$vault/items?filter=title%20eq%20%22$item%22" | jq -r '.[0] | .id')
87+
if [ -z "$item" ]; then
88+
echo "Could not find item ID for item: $item"
89+
exit 1
90+
fi
91+
fi
92+
7393
echo "Loading item $item from vault $vault..."
74-
item_json=$(curl -sSf -H "Content-Type: application/json" -H "Authorization: Bearer $OP_CONNECT_TOKEN" "$OP_CONNECT_HOST/v1/vaults/$vault/items/$item")
94+
item_json=$(curl -sSf "${curl_headers[@]}" "$OP_CONNECT_HOST/v1/vaults/$vault/items/$item")
95+
7596
jq_field_selector=".id == \"$field\" or .label == \"$field\""
7697
jq_section_selector=".section == null"
7798

0 commit comments

Comments
 (0)