|
10 | 10 | "\n", |
11 | 11 | "⚙️ **Supported infrastructures**: All infrastructures\n", |
12 | 12 | "\n", |
13 | | - "⌚ **Expected *Run All* runtime (excl. infrastructure prerequisite): ~[NOTEBOOK RUNTIME] minute**\n", |
| 13 | + "⌚ **Expected *Run All* runtime (excl. infrastructure prerequisite): ~2-3 minutes**\n", |
14 | 14 | "\n", |
15 | 15 | "## Objectives\n", |
16 | 16 | "\n", |
|
190 | 190 | "from apimjwt import JwtPayload, SymmetricJwtToken\n", |
191 | 191 | "from apimtypes import HR_MEMBER_ROLE_ID, HR_ADMINISTRATOR_ROLE_ID, HR_ASSOCIATE_ROLE_ID\n", |
192 | 192 | "\n", |
| 193 | + "# Preflight: Check if the infrastructure architecture deployment uses Azure Front Door. If so, assume that APIM is not directly accessible and use the Front Door URL instead.\n", |
| 194 | + "endpoint_url = apim_gateway_url\n", |
| 195 | + "utils.print_message('Checking if the infrastructure architecture deployment uses Azure Front Door.', blank_above = True)\n", |
| 196 | + "afd_endpoint_url = utils.get_frontdoor_url(deployment, rg_name)\n", |
| 197 | + "\n", |
| 198 | + "if afd_endpoint_url:\n", |
| 199 | + " endpoint_url = afd_endpoint_url\n", |
| 200 | + " utils.print_message(f'Using Azure Front Door URL: {afd_endpoint_url}', blank_above = True)\n", |
| 201 | + "else:\n", |
| 202 | + " utils.print_message(f'Using APIM Gateway URL: {apim_gateway_url}', blank_above = True)\n", |
| 203 | + "\n", |
193 | 204 | "# 1) HR Administrator\n", |
194 | 205 | "# Create a JSON Web Token with a payload and sign it with the symmetric key from above.\n", |
195 | 206 | "jwt_payload_hr_admin = JwtPayload(subject = 'user123', name = 'Angie Administrator', roles = [HR_MEMBER_ROLE_ID, HR_ADMINISTRATOR_ROLE_ID])\n", |
196 | 207 | "encoded_jwt_token_hr_admin = SymmetricJwtToken(jwt_key_value, jwt_payload_hr_admin).encode()\n", |
197 | | - "print(f'JWT token HR Admin: {encoded_jwt_token_hr_admin}') # this value is used to call the APIs via APIM\n", |
| 208 | + "print(f'\\nJWT token HR Admin: {encoded_jwt_token_hr_admin}') # this value is used to call the APIs via APIM\n", |
198 | 209 | "\n", |
199 | 210 | "# Set up an APIM requests object with the JWT token\n", |
200 | | - "reqsApimAdmin = ApimRequests(apim_gateway_url)\n", |
| 211 | + "reqsApimAdmin = ApimRequests(endpoint_url)\n", |
201 | 212 | "reqsApimAdmin.headers['Authorization'] = f'Bearer {encoded_jwt_token_hr_admin}'\n", |
202 | 213 | "\n", |
203 | 214 | "# Call APIM\n", |
|
208 | 219 | "# Create a JSON Web Token with a payload and sign it with the symmetric key from above.\n", |
209 | 220 | "jwt_payload_hr_associate = JwtPayload(subject = 'user789', name = 'Aaron Associate', roles = [HR_MEMBER_ROLE_ID, HR_ASSOCIATE_ROLE_ID])\n", |
210 | 221 | "encoded_jwt_token_hr_associate = SymmetricJwtToken(jwt_key_value, jwt_payload_hr_associate).encode()\n", |
211 | | - "print(f'\\n\\nJWT token HR Associate: {encoded_jwt_token_hr_associate}') # this value is used to call the APIs via APIM\n", |
| 222 | + "print(f'\\nJWT token HR Associate: {encoded_jwt_token_hr_associate}') # this value is used to call the APIs via APIM\n", |
212 | 223 | "\n", |
213 | 224 | "# Set up an APIM requests object with the JWT token\n", |
214 | | - "reqsApimAssociate = ApimRequests(apim_gateway_url)\n", |
| 225 | + "reqsApimAssociate = ApimRequests(endpoint_url)\n", |
215 | 226 | "reqsApimAssociate.headers['Authorization'] = f'Bearer {encoded_jwt_token_hr_associate}'\n", |
216 | 227 | "\n", |
217 | 228 | "# Call APIM\n", |
|
0 commit comments