-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add scripts to fetch access token for artifacts (#105)
Co-authored-by: Bhaven Dedhia <[email protected]>
- Loading branch information
Showing
3 changed files
with
76 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
param ( | ||
[Parameter(Mandatory = $true)] | ||
[string]$subscriptionId | ||
) | ||
|
||
# Set tokenId | ||
$tokenId = 0 | ||
|
||
# Get the bearer token | ||
try { | ||
$bearerToken = $(az account get-access-token -s $subscriptionId -o tsv).split()[0] | ||
} catch { | ||
Write-Host "Failed to retrieve the bearer token." | ||
exit 1 | ||
} | ||
|
||
# Query the token | ||
try { | ||
$response = Invoke-WebRequest -Uri "https://face-sdk-gating-helper-2.azurewebsites.net/sdk/subscriptions/${subscriptionId}/tokens?id=${tokenId}" -Method GET -Headers @{"Authorization"="Bearer ${bearerToken}"} | ||
$statusCode = $response.StatusCode | ||
if ($statusCode -eq 200) { | ||
Write-Host "Token exists." | ||
$response.Content | ConvertFrom-Json | Format-List | ||
} else { | ||
Write-Host "Token does not exist. Status code: $statusCode" | ||
Write-Host "Generating a new token..." | ||
$response = Invoke-RestMethod -Uri "https://face-sdk-gating-helper-2.azurewebsites.net/sdk/subscriptions/${subscriptionId}/tokens?id=${tokenId}" -Method POST -Headers @{"Authorization"="Bearer ${bearerToken}"} | ||
Write-Host "Token generated successfully." | ||
$response | Format-List | ||
} | ||
} catch { | ||
Write-Host "Error: $_.Exception.Message" | ||
Write-Host "Generating a new token..." | ||
$response = Invoke-RestMethod -Uri "https://face-sdk-gating-helper-2.azurewebsites.net/sdk/subscriptions/${subscriptionId}/tokens?id=${tokenId}" -Method POST -Headers @{"Authorization"="Bearer ${bearerToken}"} | ||
Write-Host "Token generated successfully." | ||
$response | Format-List | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/bin/bash | ||
|
||
# Check if the required parameter is provided | ||
if [ -z "$1" ]; then | ||
echo "Usage: $0 <subscriptionId>" | ||
exit 1 | ||
fi | ||
|
||
subscriptionId=$1 | ||
tokenId=0 | ||
|
||
# Get the bearer token | ||
bearerToken=$(az account get-access-token -s $subscriptionId -o tsv | cut -f1) | ||
|
||
# Check if bearerToken was successfully retrieved | ||
if [ -z "$bearerToken" ]; then | ||
echo "Error: Failed to retrieve the bearer token." | ||
exit 1 | ||
fi | ||
|
||
# Query the token | ||
response=$(curl -s -o /dev/null -w "%{http_code}" -X GET --header "Authorization: Bearer ${bearerToken}" "https://face-sdk-gating-helper-2.azurewebsites.net/sdk/subscriptions/${subscriptionId}/tokens?id=${tokenId}") | ||
|
||
if [ "$response" -eq 200 ]; then | ||
echo "Token exists." | ||
curl -s -X GET --header "Authorization: Bearer ${bearerToken}" "https://face-sdk-gating-helper-2.azurewebsites.net/sdk/subscriptions/${subscriptionId}/tokens?id=${tokenId}" | ||
else | ||
echo "Token does not exist. Status code: $response" | ||
echo "Generating a new token..." | ||
curl -s -X POST --header "Authorization: Bearer ${bearerToken}" "https://face-sdk-gating-helper-2.azurewebsites.net/sdk/subscriptions/${subscriptionId}/tokens?id=${tokenId}" | ||
fi |