Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update get-fileshare-signed-url.sh script content #1568

Conversation

jenkins-infra-updatecli[bot]
Copy link
Contributor

Update get-fileshare-signed-url.sh script content

Update script content

1 file(s) updated with "#!/bin/bash\n# Purpose: Shell script to get a file share URL signed with a short-lived SAS token\n# --\n# Description: This script uses either a service principal or either a storage account access key to generate a SAS token\n# and returns the file share URL composed of the storage resource URI and the SAS token.\n# Ref: https://learn.microsoft.com/en-us/azure/storage/common/storage-sas-overview\n# --\n# Usage:\n# - Return a file share signed URL: ./get-fileshare-signed-url.sh\n# - Interact with a file share and azcopy: azcopy list \"$(./get-fileshare-signed-url.sh)\"\n# --\n# Required parameters defined as environment variables:\n# - STORAGE_FILESHARE: the file share name\n# - STORAGE_NAME: the storage account name where the file share is located\n# - STORAGE_DURATION_IN_MINUTE: lifetime of the short-lived SAS token, in minute\n# - STORAGE_PERMISSIONS: the permission(s) granted on the file share, any of \"dlrw\" (note: the order matters)\n#\n# Depending on wether you want to use a service principal or an access key to generate the SAS token, you'll also need either:\n# - AZURE_STORAGE_KEY: the storage account access key\n# or\n# - JENKINS_INFRA_FILESHARE_CLIENT_ID: the service principal app registration client id\n# - JENKINS_INFRA_FILESHARE_CLIENT_SECRET: the service principal client secret\n# - JENKINS_INFRA_FILESHARE_TENANT_ID: the file share tenant id\n# --------------------------------------------------------------------------------\nset -Eeu -o pipefail\n\n# Don't print any trace\nset +x\n\n: \"${STORAGE_FILESHARE?}\" \"${STORAGE_NAME?}\" \"${STORAGE_DURATION_IN_MINUTE?}\" \"${STORAGE_PERMISSIONS?}\"\n\n# Ensure the script is re-entrant by using unique temporary `az` configuration directory for each call\n# Ref. https://learn.microsoft.com/en-us/cli/azure/use-azure-cli-successfully?tabs=bash%2Cbash2#concurrent-execution\nAZURE_CONFIG_DIR=\"$(mktemp -d)\"\nexport AZURE_CONFIG_DIR\n\naccountKeyArg=()\nshouldLogout=\"true\"\n# If a storage account key env var exists, use it instead of a service principal to generate a file share SAS token\nif [[ -n \"${AZURE_STORAGE_KEY:=\"\"}\" ]]; then\n accountKeyArg=(\"--account-key\" \"${AZURE_STORAGE_KEY}\")\n shouldLogout=\"false\"\nelse\n # If there is no account key env var defined, require env vars needed to use a service principal\n : \"${JENKINS_INFRA_FILESHARE_CLIENT_ID?}\" \"${JENKINS_INFRA_FILESHARE_CLIENT_SECRET?}\" \"${JENKINS_INFRA_FILESHARE_TENANT_ID?}\"\n\n # Login without the JSON output from az\n az login --service-principal \\\n --user \"${JENKINS_INFRA_FILESHARE_CLIENT_ID}\" \\\n --password \"${JENKINS_INFRA_FILESHARE_CLIENT_SECRET}\" \\\n --tenant \"${JENKINS_INFRA_FILESHARE_TENANT_ID}\" > /dev/null\nfi\n\n# date(1) isn't GNU compliant on MacOS, using gdate(1) in that case\n[[ \"$(uname || true)\" == \"Darwin\" ]] && dateCmd=\"gdate\" || dateCmd=\"date\"\nexpiry=\"$(\"${dateCmd}\" --utc --date \"+ ${STORAGE_DURATION_IN_MINUTE} minutes\" +\"%Y-%m-%dT%H:%MZ\")\"\n\n# Generate a SAS token, remove double quotes around it and replace potential '/' by '%2F'\ntoken=\"$(az storage share generate-sas \"${accountKeyArg[@]}\" \\\n--name \"${STORAGE_FILESHARE}\" \\\n--account-name \"${STORAGE_NAME}\" \\\n--https-only \\\n--permissions \"${STORAGE_PERMISSIONS}\" \\\n--expiry \"${expiry}\" \\\n--only-show-errors \\\n| sed 's/\\\"//g' \\\n| sed 's|/|%2F|g')\"\n\n[[ \"${shouldLogout}\" == \"true\" ]] && az logout\n\necho \"https://${STORAGE_NAME}.file.core.windows.net/${STORAGE_FILESHARE}/?${token}\"\n": * provisioning/get-fileshare-signed-url.sh

Jenkins pipeline link
Updatecli logo

Created automatically by Updatecli

Options:

Most of Updatecli configuration is done via its manifest(s).

  • If you close this pull request, Updatecli will automatically reopen it, the next time it runs.
  • If you close this pull request and delete the base branch, Updatecli will automatically recreate it, erasing all previous commits made.

Feel free to report any issues at github.com/updatecli/updatecli.
If you find this tool useful, do not hesitate to star our GitHub repository as a sign of appreciation, and/or to tell us directly on our chat!

Made with ❤️️ by updatecli
@dduportal dduportal enabled auto-merge (squash) December 2, 2024 20:52
@dduportal dduportal disabled auto-merge December 4, 2024 06:58
@dduportal dduportal merged commit 840fbfb into main Dec 4, 2024
1 of 2 checks passed
@dduportal dduportal deleted the updatecli_main_f3523bdf33dc26cfc9fd2d0706db3c7127f3542375bb5a60b752d30e380c2d9d branch December 4, 2024 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants