Skip to content

Commit

Permalink
Merge pull request #21 from hortonworks/CB-12968
Browse files Browse the repository at this point in the history
CB-12968 Fail fast when account group or key is not found
  • Loading branch information
Bajzathd authored Jun 9, 2021
2 parents 2c74eb9 + e6dd9b3 commit a6bd3b2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ RUN apk update && apk add bash coreutils jq curl

ADD ./azure-copy /bin/

RUN curl -Lsf https://github.com/hortonworks/pollprogress/releases/download/v0.2.2/pollprogress_0.2.2_Linux_x86_64.tgz | tar -xz -C /bin
RUN curl -Lsf https://github.com/hortonworks/pollprogress/releases/download/0.2.3/pollprogress_0.2.3_Linux_x86_64.tgz | tar -xz -C /bin
ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/azure/bin

ENTRYPOINT ["/bin/pollprogress"]
23 changes: 19 additions & 4 deletions azure-copy
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ azure_login() {
fi
}

_delete_azure_storage_account_list() {
rm "$STORAGE_ACCOUNT_LIST_FILE"
}

azure_storage_account_list() {
STORAGE_ACCOUNT_LIST_FILE=$(mktemp)
az storage account list --output json > "$STORAGE_ACCOUNT_LIST_FILE"
trap _delete_azure_storage_account_list EXIT
}

export_fns() {
Expand Down Expand Up @@ -102,7 +107,13 @@ azure_blob_copy() {
}

_azure_get_account_group() {
cat "$STORAGE_ACCOUNT_LIST_FILE" | jq '.[]|select(.name|startswith("'${1:? storage account}'"))|.resourceGroup' -r |head -1
declare storage=${1:? storage account}
local account_group=$(cat "$STORAGE_ACCOUNT_LIST_FILE" | jq '.[]|select(.name|startswith("'${storage}'"))|.resourceGroup' -r | head -1)
if [[ -z "$account_group" ]]; then
debug "Failed to get account group for storage account ${storage}"
exit 1
fi
echo $account_group
}

_azure_get_account_key() {
Expand All @@ -113,7 +124,12 @@ _azure_get_account_key() {
group=$(_azure_get_account_group ${storage})
fi

az storage account keys list --resource-group $group --account-name $storage --output json | jq -r '.[0].value'
local account_key=$(az storage account keys list --resource-group $group --account-name $storage --output json | jq -r '.[0].value')
if [[ -z "$account_key" ]]; then
debug "Failed to get account key for storage account ${storage} in group ${group}"
exit 1
fi
echo $account_key
}

azure_latest_vhd_by_prefix() {
Expand All @@ -134,7 +150,6 @@ main() {
azure_login
azure_storage_account_list
azure_copy_everywhere
rm "$STORAGE_ACCOUNT_LIST_FILE"
}

[[ "$0" == "$BASH_SOURCE" ]] && main "$@" || :
[[ "$0" == "$BASH_SOURCE" ]] && main "$@"

0 comments on commit a6bd3b2

Please sign in to comment.