Skip to content

Commit 7fa57da

Browse files
committed
Remove timeout logic
1 parent 40f0576 commit 7fa57da

1 file changed

Lines changed: 77 additions & 111 deletions

File tree

  • src/artifacts-helper/scripts

src/artifacts-helper/scripts/az

Lines changed: 77 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -5,86 +5,86 @@
55

66
# If ACTIONS_ID_TOKEN_REQUEST_URL is set, we are in GitHub Actions - skip interception
77
if [ -n "${ACTIONS_ID_TOKEN_REQUEST_URL}" ]; then
8-
source "$(dirname "$0")"/resolve-shim.sh
9-
AZ_EXE="$(resolve_shim)"
10-
exec "${AZ_EXE}" "$@"
8+
source "$(dirname "$0")"/resolve-shim.sh
9+
AZ_EXE="$(resolve_shim)"
10+
exec "${AZ_EXE}" "$@"
1111
fi
1212

1313
source "$(dirname "$0")"/resolve-shim.sh
1414

1515
# Well-known resource type mappings (az account get-access-token --resource-type)
1616
declare -A RESOURCE_TYPE_MAP=(
17-
["arm"]="https://management.azure.com"
18-
["aad-graph"]="https://graph.windows.net"
19-
["ms-graph"]="https://graph.microsoft.com"
20-
["batch"]="https://batch.core.windows.net"
21-
["data-lake"]="https://datalake.azure.net"
22-
["media"]="https://rest.media.azure.net"
23-
["oss-rdbms"]="https://ossrdbms-aad.database.windows.net"
17+
["arm"]="https://management.azure.com"
18+
["aad-graph"]="https://graph.windows.net"
19+
["ms-graph"]="https://graph.microsoft.com"
20+
["batch"]="https://batch.core.windows.net"
21+
["data-lake"]="https://datalake.azure.net"
22+
["media"]="https://rest.media.azure.net"
23+
["oss-rdbms"]="https://ossrdbms-aad.database.windows.net"
2424
)
2525

2626
# Check if this is a get-access-token request that we should intercept
2727
if [[ "$1" == "account" && "$2" == "get-access-token" ]]; then
28-
resource=""
29-
scope=""
30-
resource_type=""
31-
prev=""
32-
33-
for arg in "${@:3}"; do
34-
case "$arg" in
35-
--resource=*) resource="${arg#--resource=}" ;;
36-
--scope=*) scope="${arg#--scope=}" ;;
37-
--resource-type=*) resource_type="${arg#--resource-type=}" ;;
38-
*)
39-
case "$prev" in
40-
--resource) resource="$arg" ;;
41-
--scope) scope="$arg" ;;
42-
--resource-type) resource_type="$arg" ;;
43-
esac
44-
;;
45-
esac
46-
prev="$arg"
47-
done
48-
49-
# Resolve resource-type to resource URL if specified
50-
if [[ -n "$resource_type" && -z "$resource" ]]; then
51-
resource="${RESOURCE_TYPE_MAP[$resource_type]}"
52-
fi
53-
54-
# Determine the scope to request
55-
request_scope=""
56-
if [[ -n "$scope" ]]; then
57-
request_scope="$scope"
58-
elif [[ -n "$resource" ]]; then
59-
if [[ "$resource" == *"/.default" ]]; then
60-
request_scope="$resource"
61-
else
62-
request_scope="${resource}/.default"
63-
fi
28+
resource=""
29+
scope=""
30+
resource_type=""
31+
prev=""
32+
33+
for arg in "${@:3}"; do
34+
case "$arg" in
35+
--resource=*) resource="${arg#--resource=}" ;;
36+
--scope=*) scope="${arg#--scope=}" ;;
37+
--resource-type=*) resource_type="${arg#--resource-type=}" ;;
38+
*)
39+
case "$prev" in
40+
--resource) resource="$arg" ;;
41+
--scope) scope="$arg" ;;
42+
--resource-type) resource_type="$arg" ;;
43+
esac
44+
;;
45+
esac
46+
prev="$arg"
47+
done
48+
49+
# Resolve resource-type to resource URL if specified
50+
if [[ -n "$resource_type" && -z "$resource" ]]; then
51+
resource="${RESOURCE_TYPE_MAP[$resource_type]}"
52+
fi
53+
54+
# Determine the scope to request
55+
request_scope=""
56+
if [[ -n "$scope" ]]; then
57+
request_scope="$scope"
58+
elif [[ -n "$resource" ]]; then
59+
if [[ "$resource" == *"/.default" ]]; then
60+
request_scope="$resource"
61+
else
62+
request_scope="${resource}/.default"
6463
fi
65-
66-
# If we have a scope and azure-auth-helper exists, use it
67-
if [[ -n "$request_scope" && -f "${HOME}/azure-auth-helper" ]]; then
68-
token=$("${HOME}/azure-auth-helper" get-access-token "$request_scope" 2>/dev/null)
69-
if [[ $? -eq 0 && -n "$token" ]]; then
70-
# Escape token for safe JSON embedding (handle backslashes and quotes)
71-
escaped_token="${token//\\/\\\\}"
72-
escaped_token="${escaped_token//\"/\\\"}"
73-
74-
# Calculate expiry timestamps (conservative 1 hour estimate)
75-
# expires_on = POSIX timestamp, expiresOn = local datetime
76-
if date --version >/dev/null 2>&1; then
77-
# GNU date (Linux)
78-
expires_on=$(date -d "+1 hour" "+%s")
79-
expires_on_datetime=$(date -d "+1 hour" "+%Y-%m-%d %H:%M:%S.000000")
80-
else
81-
# BSD date (macOS)
82-
expires_on=$(date -v+1H "+%s")
83-
expires_on_datetime=$(date -v+1H "+%Y-%m-%d %H:%M:%S.000000")
84-
fi
85-
86-
# Return in az CLI JSON format (matching real az CLI output)
87-
cat <<EOF
64+
fi
65+
66+
# If we have a scope and azure-auth-helper exists, use it
67+
if [[ -n "$request_scope" && -f "${HOME}/azure-auth-helper" ]]; then
68+
token=$("${HOME}/azure-auth-helper" get-access-token "$request_scope" 2>/dev/null)
69+
if [[ $? -eq 0 && -n "$token" ]]; then
70+
# Escape token for safe JSON embedding (handle backslashes and quotes)
71+
escaped_token="${token//\\/\\\\}"
72+
escaped_token="${escaped_token//\"/\\\"}"
73+
74+
# Calculate expiry timestamps (conservative 1 hour estimate)
75+
# expires_on = POSIX timestamp, expiresOn = local datetime
76+
if date --version >/dev/null 2>&1; then
77+
# GNU date (Linux)
78+
expires_on=$(date -d "+1 hour" "+%s")
79+
expires_on_datetime=$(date -d "+1 hour" "+%Y-%m-%d %H:%M:%S.000000")
80+
else
81+
# BSD date (macOS)
82+
expires_on=$(date -v+1H "+%s")
83+
expires_on_datetime=$(date -v+1H "+%Y-%m-%d %H:%M:%S.000000")
84+
fi
85+
86+
# Return in az CLI JSON format (matching real az CLI output)
87+
cat <<EOF
8888
{
8989
"accessToken": "${escaped_token}",
9090
"expiresOn": "${expires_on_datetime}",
@@ -94,53 +94,19 @@ if [[ "$1" == "account" && "$2" == "get-access-token" ]]; then
9494
"tokenType": "Bearer"
9595
}
9696
EOF
97-
exit 0
98-
fi
99-
fi
100-
fi
101-
102-
# Fall through to real az CLI for all other commands
103-
# Before fallthrough, set AZURE_DEVOPS_EXT_PAT if ado-auth-helper is available
104-
# This enables 'az devops' commands to authenticate automatically
105-
if [[ -z "${AZURE_DEVOPS_EXT_PAT}" ]]; then
106-
MAX_WAIT=${MAX_WAIT:-180}
107-
ELAPSED=0
108-
109-
if [[ "${ARTIFACTS_HELPER_VERBOSE}" == "true" ]]; then
110-
echo "::step::Waiting for AzDO Authentication Helper for az devops..." >&2
111-
fi
112-
113-
while [[ $ELAPSED -lt $MAX_WAIT ]]; do
114-
if [[ -f "${HOME}/ado-auth-helper" ]]; then
115-
AZURE_DEVOPS_EXT_PAT=$("${HOME}/ado-auth-helper" get-access-token 2>/dev/null)
116-
if [[ $? -eq 0 && -n "$AZURE_DEVOPS_EXT_PAT" ]]; then
117-
export AZURE_DEVOPS_EXT_PAT
118-
if [[ "${ARTIFACTS_HELPER_VERBOSE}" == "true" ]]; then
119-
echo "::step::✓ AZURE_DEVOPS_EXT_PAT set successfully" >&2
120-
fi
121-
break
122-
fi
123-
fi
124-
sleep 2
125-
ELAPSED=$((ELAPSED + 2))
126-
127-
# Progress indicator every 20 seconds (verbose only)
128-
if [[ "${ARTIFACTS_HELPER_VERBOSE}" == "true" && $((ELAPSED % 20)) -eq 0 ]]; then
129-
echo " Still waiting... (${ELAPSED}s elapsed)" >&2
130-
fi
131-
done
132-
133-
# Always show timeout warnings regardless of verbose setting, as this indicates a potential issue
134-
if [[ $ELAPSED -ge $MAX_WAIT ]]; then
135-
echo "::warning::AzDO Authentication Helper not found after ${MAX_WAIT} seconds" >&2
136-
echo "Continuing without AZURE_DEVOPS_EXT_PAT..." >&2
97+
exit 0
13798
fi
99+
fi
138100
fi
139101

102+
# Fall through to real az CLI for all other commands.
140103
AZ_EXE="$(resolve_shim)"
141104
if [[ -n "$AZ_EXE" ]]; then
105+
# If AZURE_DEVOPS_EXT_PAT is not already set, try to acquire it from ado-auth-helper
106+
# so that 'az devops' commands authenticate automatically.
107+
AZURE_DEVOPS_EXT_PAT="${AZURE_DEVOPS_EXT_PAT:-$("${HOME}/ado-auth-helper" get-access-token 2>/dev/null)}" \
142108
exec "${AZ_EXE}" "$@"
143109
else
144-
echo "Error: Azure CLI not found in PATH" >&2
145-
exit 1
110+
echo "Error: Azure CLI not found in PATH" >&2
111+
exit 1
146112
fi

0 commit comments

Comments
 (0)