-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathazure-env.sh
More file actions
executable file
·89 lines (76 loc) · 2.82 KB
/
Copy pathazure-env.sh
File metadata and controls
executable file
·89 lines (76 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env bash
# Azure environment helper.
# Behavior:
# - If mode is `emulator`, export Azurite-compatible credentials for floci-az.
# - If mode is `login`, verify az CLI login and export subscription.
# - Otherwise, auto-detect based on AZURE_ENDPOINT_URL.
set -euo pipefail
_is_sourced() {
(return 0 2>/dev/null)
}
_done() {
if _is_sourced; then
return "$1" 2>/dev/null || true
else
exit "$1"
fi
}
usage() {
cat <<'USAGE' >&2
Usage: source scripts/azure-env.sh [mode]
Modes:
emulator|floci-az Export emulator credentials (AZURE_ENDPOINT_URL defaults to http://127.0.0.1:4577)
login Verify az CLI login and export AZURE_SUBSCRIPTION_ID
(no args) Auto-detect: prefer emulator endpoint, then az CLI
USAGE
_done 1
}
AZURITE_ACCOUNT="devstoreaccount1"
AZURITE_KEY="Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="
MODE=${1:-}
if [[ -n "$MODE" && ("$MODE" == "-h" || "$MODE" == "--help") ]]; then
usage
fi
case "$MODE" in
emulator|floci-az)
export AZURE_ENDPOINT_URL=${AZURE_ENDPOINT_URL:-http://127.0.0.1:4577}
export AZURE_STORAGE_ACCOUNT="$AZURITE_ACCOUNT"
export AZURE_STORAGE_KEY="$AZURITE_KEY"
export AZURE_STORAGE_CONNECTION_STRING="DefaultEndpointsProtocol=http;AccountName=${AZURITE_ACCOUNT};AccountKey=${AZURITE_KEY};BlobEndpoint=${AZURE_ENDPOINT_URL}/${AZURITE_ACCOUNT};QueueEndpoint=${AZURE_ENDPOINT_URL}/${AZURITE_ACCOUNT}"
echo "Set emulator creds for floci-az (${AZURE_ENDPOINT_URL})" >&2
_done 0
;;
login)
if ! command -v az &>/dev/null; then
echo "ERROR: Azure CLI not found. Install: https://aka.ms/installazurecli" >&2
_done 1
fi
if ! az account show > /dev/null 2>&1; then
echo "ERROR: Not logged in. Run: az login" >&2
_done 1
fi
export AZURE_SUBSCRIPTION_ID=$(az account show --query id -o tsv)
echo "Azure subscription: $(az account show --query name -o tsv) (${AZURE_SUBSCRIPTION_ID})" >&2
_done 0
;;
"")
if [[ -n "${AZURE_ENDPOINT_URL:-}" && "${AZURE_ENDPOINT_URL}" =~ ^http://127\.0\.0\.1 ]]; then
export AZURE_STORAGE_ACCOUNT="$AZURITE_ACCOUNT"
export AZURE_STORAGE_KEY="$AZURITE_KEY"
export AZURE_STORAGE_CONNECTION_STRING="DefaultEndpointsProtocol=http;AccountName=${AZURITE_ACCOUNT};AccountKey=${AZURITE_KEY};BlobEndpoint=${AZURE_ENDPOINT_URL}/${AZURITE_ACCOUNT};QueueEndpoint=${AZURE_ENDPOINT_URL}/${AZURITE_ACCOUNT}"
echo "Auto-detected emulator endpoint; exported Azurite creds" >&2
_done 0
fi
if command -v az &>/dev/null && az account show > /dev/null 2>&1; then
export AZURE_SUBSCRIPTION_ID=$(az account show --query id -o tsv)
echo "Using Azure CLI login: $(az account show --query name -o tsv)" >&2
_done 0
fi
echo "No AZURE_ENDPOINT_URL or az CLI login detected; set up credentials first." >&2
_done 0
;;
*)
echo "Unknown mode: $MODE" >&2
usage
;;
esac