azure-deploy-cli 0.1.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- azure_deploy_cli/__init__.py +44 -0
- azure_deploy_cli/_version.py +34 -0
- azure_deploy_cli/aca/aca_cli.py +518 -0
- azure_deploy_cli/aca/bash/aca-cert/create.sh +203 -0
- azure_deploy_cli/aca/bash/aca-cert/destroy.sh +44 -0
- azure_deploy_cli/aca/deploy_aca.py +794 -0
- azure_deploy_cli/aca/model.py +35 -0
- azure_deploy_cli/cli.py +66 -0
- azure_deploy_cli/identity/__init__.py +36 -0
- azure_deploy_cli/identity/group.py +84 -0
- azure_deploy_cli/identity/identity_cli.py +453 -0
- azure_deploy_cli/identity/managed_identity.py +177 -0
- azure_deploy_cli/identity/models.py +167 -0
- azure_deploy_cli/identity/py.typed +0 -0
- azure_deploy_cli/identity/role.py +338 -0
- azure_deploy_cli/identity/service_principal.py +268 -0
- azure_deploy_cli/py.typed +0 -0
- azure_deploy_cli/utils/__init__.py +0 -0
- azure_deploy_cli/utils/azure_cli.py +96 -0
- azure_deploy_cli/utils/docker.py +137 -0
- azure_deploy_cli/utils/env.py +108 -0
- azure_deploy_cli/utils/key_vault.py +11 -0
- azure_deploy_cli/utils/logging.py +125 -0
- azure_deploy_cli/utils/py.typed +0 -0
- azure_deploy_cli-0.1.6.dist-info/METADATA +678 -0
- azure_deploy_cli-0.1.6.dist-info/RECORD +30 -0
- azure_deploy_cli-0.1.6.dist-info/WHEEL +5 -0
- azure_deploy_cli-0.1.6.dist-info/entry_points.txt +3 -0
- azure_deploy_cli-0.1.6.dist-info/licenses/LICENSE +373 -0
- azure_deploy_cli-0.1.6.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
###############################################################################
|
|
4
|
+
# Azure Container App Certificate Binding Script
|
|
5
|
+
# Cr. to: https://gist.github.com/LynnAU/131426847d2793c76e36548f9937f966#file-create-sh
|
|
6
|
+
#
|
|
7
|
+
# This script binds managed certificates to Azure Container App domains.
|
|
8
|
+
# It validates DNS ASUID records, creates managed certificates if needed,
|
|
9
|
+
# and binds them to custom domains.
|
|
10
|
+
###############################################################################
|
|
11
|
+
|
|
12
|
+
# Parse command line arguments
|
|
13
|
+
while [[ $# -gt 0 ]]; do
|
|
14
|
+
case $1 in
|
|
15
|
+
--custom-domains)
|
|
16
|
+
CUSTOM_DOMAINS="$2"
|
|
17
|
+
shift 2
|
|
18
|
+
;;
|
|
19
|
+
--container-app-name)
|
|
20
|
+
CONTAINER_APP_NAME="$2"
|
|
21
|
+
shift 2
|
|
22
|
+
;;
|
|
23
|
+
--resource-group)
|
|
24
|
+
RESOURCE_GROUP="$2"
|
|
25
|
+
shift 2
|
|
26
|
+
;;
|
|
27
|
+
--env-resource-group)
|
|
28
|
+
ENV_RESOURCE_GROUP="$2"
|
|
29
|
+
shift 2
|
|
30
|
+
;;
|
|
31
|
+
--container-app-env-name)
|
|
32
|
+
CONTAINER_APP_ENV_NAME="$2"
|
|
33
|
+
shift 2
|
|
34
|
+
;;
|
|
35
|
+
--help)
|
|
36
|
+
cat <<EOF
|
|
37
|
+
Usage: $0 [OPTIONS]
|
|
38
|
+
|
|
39
|
+
Bind managed certificates to Azure Container App custom domains.
|
|
40
|
+
|
|
41
|
+
OPTIONS:
|
|
42
|
+
--custom-domains DOMAINS Comma-separated list of custom domains (required)
|
|
43
|
+
--container-app-name NAME Container App name (required)
|
|
44
|
+
--resource-group GROUP Resource group name (required)
|
|
45
|
+
--env-resource-group ENV_GROUP Environment resource group name (required)
|
|
46
|
+
--container-app-env-name ENV_NAME Container App Environment name (required)
|
|
47
|
+
--help Display this help message
|
|
48
|
+
|
|
49
|
+
EXAMPLES:
|
|
50
|
+
$0 \\
|
|
51
|
+
--custom-domains "example.com,www.example.com" \\
|
|
52
|
+
--container-app-name my-app \\
|
|
53
|
+
--resource-group my-rg \\
|
|
54
|
+
--env-resource-group my-env-rg \\
|
|
55
|
+
--container-app-env-name my-env
|
|
56
|
+
|
|
57
|
+
EOF
|
|
58
|
+
exit 0
|
|
59
|
+
;;
|
|
60
|
+
*)
|
|
61
|
+
echo "Unknown option: $1"
|
|
62
|
+
exit 1
|
|
63
|
+
;;
|
|
64
|
+
esac
|
|
65
|
+
done
|
|
66
|
+
|
|
67
|
+
# Validate required arguments
|
|
68
|
+
if [[ -z "$CUSTOM_DOMAINS" ]] || [[ -z "$CONTAINER_APP_NAME" ]] || \
|
|
69
|
+
[[ -z "$RESOURCE_GROUP" ]] || [[ -z "$ENV_RESOURCE_GROUP" ]] || \
|
|
70
|
+
[[ -z "$CONTAINER_APP_ENV_NAME" ]]; then
|
|
71
|
+
echo "Error: Missing required arguments"
|
|
72
|
+
echo "Usage: $0 --custom-domains DOMAINS --container-app-name NAME --resource-group GROUP --env-resource-group ENV_GROUP --container-app-env-name ENV_NAME"
|
|
73
|
+
echo "Use --help for more information"
|
|
74
|
+
exit 1
|
|
75
|
+
fi
|
|
76
|
+
|
|
77
|
+
# functions below taken from: https://stackoverflow.com/a/25515370
|
|
78
|
+
yell() { echo "$0: $*" >&2; }
|
|
79
|
+
die() {
|
|
80
|
+
yell "$*"
|
|
81
|
+
exit 111
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
bind() {
|
|
85
|
+
CUSTOM_DOMAIN=$1
|
|
86
|
+
echo "binding domain: $CUSTOM_DOMAIN"
|
|
87
|
+
# az --verison
|
|
88
|
+
# use dig to verify the asuid txt record exists on the DNS host
|
|
89
|
+
# azure requires this to exist prior to adding the domain
|
|
90
|
+
# azure's dns can also be slow, so best to check propagation
|
|
91
|
+
tries=0
|
|
92
|
+
until [ "$tries" -ge 12 ]; do
|
|
93
|
+
[[ ! -z $(dig @8.8.8.8 txt asuid.$CUSTOM_DOMAIN +short) ]] && break
|
|
94
|
+
tries=$((tries + 1))
|
|
95
|
+
sleep 10
|
|
96
|
+
done
|
|
97
|
+
if [ "$tries" -ge 12 ]; then
|
|
98
|
+
die "'asuid.${CUSTOM_DOMAIN}' txt record does not exist"
|
|
99
|
+
fi
|
|
100
|
+
|
|
101
|
+
echo "took $tries trie(s) for the dns record to exist publically"
|
|
102
|
+
|
|
103
|
+
# check if the hostname already exists on the container app
|
|
104
|
+
# if not, add it since it's required to provision a managed cert
|
|
105
|
+
# TODO: DOMAINS! this doesn't work for an array of custom domains
|
|
106
|
+
DOES_CUSTOM_DOMAIN_EXIST=$(
|
|
107
|
+
az containerapp hostname list \
|
|
108
|
+
-n $CONTAINER_APP_NAME \
|
|
109
|
+
-g $RESOURCE_GROUP \
|
|
110
|
+
--query "[?name=='$CUSTOM_DOMAIN'].name" \
|
|
111
|
+
--output tsv
|
|
112
|
+
)
|
|
113
|
+
if [ -z "${DOES_CUSTOM_DOMAIN_EXIST}" ]; then
|
|
114
|
+
echo "adding custom hostname to container app first since it does not exist yet"
|
|
115
|
+
az containerapp hostname add \
|
|
116
|
+
-n $CONTAINER_APP_NAME \
|
|
117
|
+
-g $RESOURCE_GROUP \
|
|
118
|
+
--hostname $CUSTOM_DOMAIN \
|
|
119
|
+
--output none
|
|
120
|
+
fi
|
|
121
|
+
|
|
122
|
+
# check if a managed cert for the domain already exists
|
|
123
|
+
# if it does not exist, provision one
|
|
124
|
+
# if it does, save its name to use for binding it later
|
|
125
|
+
MANAGED_CERTIFICATE_ID=$(
|
|
126
|
+
az containerapp env certificate list \
|
|
127
|
+
-g $ENV_RESOURCE_GROUP \
|
|
128
|
+
-n $CONTAINER_APP_ENV_NAME \
|
|
129
|
+
--managed-certificates-only \
|
|
130
|
+
--query "[?properties.subjectName=='$CUSTOM_DOMAIN'].id" \
|
|
131
|
+
--output tsv
|
|
132
|
+
)
|
|
133
|
+
if [ -z "${MANAGED_CERTIFICATE_ID}" ]; then
|
|
134
|
+
MANAGED_CERTIFICATE_ID=$(
|
|
135
|
+
az containerapp env certificate create \
|
|
136
|
+
-g $ENV_RESOURCE_GROUP \
|
|
137
|
+
-n $CONTAINER_APP_ENV_NAME \
|
|
138
|
+
--hostname $CUSTOM_DOMAIN \
|
|
139
|
+
--validation-method CNAME \
|
|
140
|
+
--query "id" \
|
|
141
|
+
--output tsv
|
|
142
|
+
)
|
|
143
|
+
echo "created cert for '$CUSTOM_DOMAIN'. waiting for it to provision now..."
|
|
144
|
+
|
|
145
|
+
# poll azcli to check for the certificate status
|
|
146
|
+
# this is better than waiting 5 minutes, because it could be
|
|
147
|
+
# faster and we get to exit the script faster
|
|
148
|
+
# ---
|
|
149
|
+
# the default 20 tries means it'll check for 5 mins
|
|
150
|
+
# at 15 second intervals
|
|
151
|
+
tries=0
|
|
152
|
+
until [ "$tries" -ge 20 ]; do
|
|
153
|
+
STATE=$(
|
|
154
|
+
az containerapp env certificate list \
|
|
155
|
+
-g $ENV_RESOURCE_GROUP \
|
|
156
|
+
-n $CONTAINER_APP_ENV_NAME \
|
|
157
|
+
--managed-certificates-only \
|
|
158
|
+
--query "[?properties.subjectName=='$CUSTOM_DOMAIN'].properties.provisioningState" \
|
|
159
|
+
--output tsv
|
|
160
|
+
)
|
|
161
|
+
[[ $STATE == "Succeeded" ]] && break
|
|
162
|
+
tries=$((tries + 1))
|
|
163
|
+
|
|
164
|
+
sleep 15
|
|
165
|
+
done
|
|
166
|
+
if [ "$tries" -ge 20 ]; then
|
|
167
|
+
die "waited for 5 minutes, checked the certificate status 20 times and its not done. check azure portal..."
|
|
168
|
+
fi
|
|
169
|
+
else
|
|
170
|
+
echo "found existing cert in the env. proceeding to use that"
|
|
171
|
+
fi
|
|
172
|
+
|
|
173
|
+
# check if the cert has already been bound
|
|
174
|
+
# if not, bind it then
|
|
175
|
+
IS_CERT_ALREADY_BOUND=$(
|
|
176
|
+
az containerapp hostname list \
|
|
177
|
+
-n $CONTAINER_APP_NAME \
|
|
178
|
+
-g $RESOURCE_GROUP \
|
|
179
|
+
--query "[?name=='$CUSTOM_DOMAIN'].bindingType" \
|
|
180
|
+
--output tsv
|
|
181
|
+
)
|
|
182
|
+
if [ $IS_CERT_ALREADY_BOUND = "SniEnabled" ]; then
|
|
183
|
+
echo "cert is already bound, exiting..."
|
|
184
|
+
else
|
|
185
|
+
# try bind the cert to the container app
|
|
186
|
+
echo "cert successfully provisioned. binding the cert id to the hostname"
|
|
187
|
+
az containerapp hostname bind \
|
|
188
|
+
-g $RESOURCE_GROUP \
|
|
189
|
+
-n $CONTAINER_APP_NAME \
|
|
190
|
+
--hostname $CUSTOM_DOMAIN \
|
|
191
|
+
--environment $CONTAINER_APP_ENV_NAME \
|
|
192
|
+
--certificate $MANAGED_CERTIFICATE_ID \
|
|
193
|
+
--output none
|
|
194
|
+
echo "finished binding. the domain is now secured and ready to use"
|
|
195
|
+
fi
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
# split CUSTOM_DOMAINS by comma into an array
|
|
199
|
+
# loop through the array and bind each domain
|
|
200
|
+
IFS=', ' read -r -a DOMAINS <<<"$CUSTOM_DOMAINS"
|
|
201
|
+
for DOMAIN in "${DOMAINS[@]}"; do
|
|
202
|
+
bind "$DOMAIN"
|
|
203
|
+
done
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# functions below taken from: https://stackoverflow.com/a/25515370
|
|
4
|
+
yell() { echo "$0: $*" >&2; }
|
|
5
|
+
die() {
|
|
6
|
+
yell "$*"
|
|
7
|
+
exit 111
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
az --verison
|
|
11
|
+
|
|
12
|
+
destroy() {
|
|
13
|
+
CUSTOM_DOMAIN=$1
|
|
14
|
+
echo "destroying domain: $CUSTOM_DOMAIN"
|
|
15
|
+
# get the managed cert using the custom domain
|
|
16
|
+
CERTIFICATE_ID=$(
|
|
17
|
+
az containerapp env certificate list \
|
|
18
|
+
-g $ENV_RESOURCE_GROUP \
|
|
19
|
+
-n $CONTAINER_APP_ENV_NAME \
|
|
20
|
+
--managed-certificates-only \
|
|
21
|
+
--query "[?properties.subjectName=='$CUSTOM_DOMAIN'].id" \
|
|
22
|
+
--output tsv
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
# destroy the cert
|
|
26
|
+
az containerapp env certificate delete \
|
|
27
|
+
-g $ENV_RESOURCE_GROUP \
|
|
28
|
+
-n $CONTAINER_APP_ENV_NAME \
|
|
29
|
+
--certificate $CERTIFICATE_ID --yes
|
|
30
|
+
echo "destroyed the managed certificate"
|
|
31
|
+
|
|
32
|
+
# remove the custom domain from the container app
|
|
33
|
+
az containerapp hostname delete --hostname $CUSTOM_DOMAIN \
|
|
34
|
+
-g $RESOURCE_GROUP \
|
|
35
|
+
-n $CONTAINER_APP_NAME
|
|
36
|
+
echo "removed the custom domain from the container app"
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
# split CUSTOM_DOMAINS by comma with whitespaces
|
|
40
|
+
# loop through each domain and destroy it
|
|
41
|
+
IFS=', ' read -r -a DOMAINS <<<"$CUSTOM_DOMAINS"
|
|
42
|
+
for DOMAIN in "${DOMAINS[@]}"; do
|
|
43
|
+
destroy "$DOMAIN"
|
|
44
|
+
done
|