Skip to content

Commit 279265f

Browse files
committed
readd , , and
1 parent 1c1dfb2 commit 279265f

1 file changed

Lines changed: 22 additions & 25 deletions

File tree

  • src/artifacts-helper/scripts

src/artifacts-helper/scripts/az

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,8 @@
22
# Azure CLI shim for GitHub Codespaces
33
# Intercepts 'az account get-access-token' requests and uses azure-auth-helper
44
# to acquire tokens via the ado-codespaces-auth VS Code extension.
5-
#
6-
# This enables DefaultAzureCredential's AzureCliCredential to work in Codespaces
7-
# without requiring 'az login' (which times out waiting for browser auth).
8-
#
9-
# To install: Copy this to /usr/local/share/codespace-shims/az
10-
# The shims directory should already be in PATH for Codespaces.
115

12-
# If ACTIONS_ID_TOKEN_REQUEST_URL is set, we're in GitHub Actions - skip interception
6+
# If ACTIONS_ID_TOKEN_REQUEST_URL is set, we are in GitHub Actions - skip interception
137
if [ -n "${ACTIONS_ID_TOKEN_REQUEST_URL}" ]; then
148
source "$(dirname $0)"/resolve-shim.sh
159
AZ_EXE="$(resolve_shim)"
@@ -31,23 +25,16 @@ declare -A RESOURCE_TYPE_MAP=(
3125

3226
# Check if this is a get-access-token request that we should intercept
3327
if [[ "$1" == "account" && "$2" == "get-access-token" ]]; then
34-
# Parse arguments to extract --resource, --scope, or --resource-type
3528
resource=""
3629
scope=""
3730
resource_type=""
3831
prev=""
39-
32+
4033
for arg in "${@:3}"; do
4134
case "$prev" in
42-
--resource)
43-
resource="$arg"
44-
;;
45-
--scope)
46-
scope="$arg"
47-
;;
48-
--resource-type)
49-
resource_type="$arg"
50-
;;
35+
--resource) resource="$arg" ;;
36+
--scope) scope="$arg" ;;
37+
--resource-type) resource_type="$arg" ;;
5138
esac
5239
prev="$arg"
5340
done
@@ -58,12 +45,10 @@ if [[ "$1" == "account" && "$2" == "get-access-token" ]]; then
5845
fi
5946

6047
# Determine the scope to request
61-
# Priority: explicit --scope > --resource/.default > --resource-type/.default
6248
request_scope=""
6349
if [[ -n "$scope" ]]; then
6450
request_scope="$scope"
6551
elif [[ -n "$resource" ]]; then
66-
# Append /.default if not already present
6752
if [[ "$resource" == *"/.default" ]]; then
6853
request_scope="$resource"
6954
else
@@ -73,21 +58,33 @@ if [[ "$1" == "account" && "$2" == "get-access-token" ]]; then
7358

7459
# If we have a scope and azure-auth-helper exists, use it
7560
if [[ -n "$request_scope" && -f "${HOME}/azure-auth-helper" ]]; then
76-
# Get token from azure-auth-helper
7761
token=$("${HOME}/azure-auth-helper" get-access-token "$request_scope" 2>/dev/null)
78-
exit_code=$?
62+
if [[ $? -eq 0 && -n "$token" ]]; then
63+
# Calculate expiry timestamps (conservative 1 hour estimate)
64+
# expires_on = POSIX timestamp, expiresOn = local datetime
65+
if date --version >/dev/null 2>&1; then
66+
# GNU date (Linux)
67+
expires_on=$(date -d "+1 hour" "+%s")
68+
expires_on_datetime=$(date -d "+1 hour" "+%Y-%m-%d %H:%M:%S.000000")
69+
else
70+
# BSD date (macOS)
71+
expires_on=$(date -v+1H "+%s")
72+
expires_on_datetime=$(date -v+1H "+%Y-%m-%d %H:%M:%S.000000")
73+
fi
7974

80-
if [[ $exit_code -eq 0 && -n "$token" ]]; then
81-
# Return in az CLI JSON format
75+
# Return in az CLI JSON format (matching real az CLI output)
8276
cat <<EOF
8377
{
8478
"accessToken": "${token}",
79+
"expiresOn": "${expires_on_datetime}",
80+
"expires_on": ${expires_on},
81+
"subscription": "",
82+
"tenant": "",
8583
"tokenType": "Bearer"
8684
}
8785
EOF
8886
exit 0
8987
fi
90-
# Fall through to real az CLI if azure-auth-helper fails
9188
fi
9289
fi
9390

0 commit comments

Comments
 (0)