You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+79-17Lines changed: 79 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,7 @@
5
5
You want to have an easy way to interact with the Microsoft Azure API endpoints without getting headache of taking care of valid bearer token and error handling?
6
6
7
7
## Table of content
8
+
8
9
-[AzAPICall](#azapicall)
9
10
-[Table of content](#table-of-content)
10
11
-[AzAPICall example](#azapicall-example)
@@ -20,6 +21,8 @@ You want to have an easy way to interact with the Microsoft Azure API endpoints
20
21
-[Good to know](#good-to-know)
21
22
-[Don´t accept the defaults](#dont-accept-the-defaults)
_confused by_ '`$($azAPICallConf['azAPIEndpointUrls'].MicrosoftGraph)`'_? It´s basically a reference to the correct endpoint (think public cloud, sovereign clouds). You can of course also hardcode the endpoint URI:_
| SkipAzContextSubscriptionValidation |`bool`| Only use in case you do not have any valid (quotaId != AAD_* & state != disabled) subscriptions in your tenant OR you do not have any permissions on Azure Resources (Management Groups, Subscriptions, Resource Groups, Resources) and but want to connect non-ARM API endpoints such as Microsoft Graph etc. (Per default a subscription is expected to be present in the Az context, if not then AzAPICall will throw..). ||
123
137
124
-
125
138
## AzAPICall Parameters
126
139
127
140
Parameters that can be used with the AzAPICall cmdlet
| unhandledErrorAction |`string`| When a call to an API returns an Error, that error is processed by AzAPICallErrorHandler. If that error is unhandled, AzAPICallErrorHandler will log the error and Throw a message which terminates the script. This happens when parameter -unhandledErrorAction is set to `Stop` (which is also the default if not configured). When -unhandledErrorAction is set to `Continue`, AzAPICallErrorHandler logs the error including full details to raise an issue at the repo and continues processing. When -unhandledErrorAction is set to `ContinueQuiet`, AzAPICallErrorHandler only logs the error (excluding full details to raise an issue at the repo) and continues processing | default is `Stop`, options: `Continue`, `ContinueQuiet`|
145
158
146
159
## Good to know
160
+
147
161
### Don´t accept the defaults
148
162
149
163
By default, endPoints return results in batches of e.g. `100`. You can increase the return count defining e.g. `$top=999` (`$top` requires use of `consistencyLevel` = `eventual`)
@@ -155,6 +169,7 @@ To get some insights on all API calls you can check the `$azAPICallConf['arrayAP
@@ -199,8 +217,51 @@ As well you can see how fast a AzAPICall was responding:
199
217
}
200
218
```
201
219
220
+
## Runtime environment
221
+
222
+
### Azure DevOps
223
+
224
+
If you are using a PowerShell script within a pipeline and an `OIDC` service connection, you need to set the [`SYSTEM_ACCESSTOKEN` environment variable](https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml#systemaccesstoken) in the task of your pipeline. This allows the AzAPICall module to use it for token renewal:
225
+
226
+
```YML
227
+
- task: AzurePowerShell@5
228
+
displayName: 'OIDC testing with AzurePowerShell@5'
Copy file name to clipboardExpand all lines: pwsh/module/build/AzAPICall/functions/AzAPICallFunctions.ps1
+11-5Lines changed: 11 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -1668,6 +1668,11 @@ function createBearerToken {
1668
1668
if ($_-like'*ClientAssertionCredential authentication failed*') {
1669
1669
Logging -logMessage " Running on '$(($AzApiCallConfiguration['htParameters']).codeRunPlatform)' OIDC: '$(($AzApiCallConfiguration['htParameters']).accountType)' - Getting Bearer Token from Login endpoint '$(($AzApiCallConfiguration['azAPIEndpointUrls']).Login)'"
1670
1670
1671
+
if ([string]::IsNullOrWhiteSpace($env:SYSTEM_ACCESSTOKEN)) {
1672
+
Logging -logMessage "-ERROR: OIDC ADO - Could not find access token, check if the environment variable 'SYSTEM_ACCESSTOKEN' exists and has valid data. https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml#systemaccesstoken"-logMessageWriteMethod 'Error'
1673
+
Throw"Error - OIDC ADO - Could not find access token, check if the environment variable 'SYSTEM_ACCESSTOKEN' exists and has valid data. https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml#systemaccesstoken"
Copy file name to clipboardExpand all lines: pwsh/module/dev/AzAPICall/functions/createBearerToken.ps1
+5Lines changed: 5 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -160,6 +160,11 @@
160
160
if ($_-like'*ClientAssertionCredential authentication failed*') {
161
161
Logging -logMessage " Running on '$(($AzApiCallConfiguration['htParameters']).codeRunPlatform)' OIDC: '$(($AzApiCallConfiguration['htParameters']).accountType)' - Getting Bearer Token from Login endpoint '$(($AzApiCallConfiguration['azAPIEndpointUrls']).Login)'"
162
162
163
+
if ([string]::IsNullOrWhiteSpace($env:SYSTEM_ACCESSTOKEN)) {
164
+
Logging -logMessage "-ERROR: OIDC ADO - Could not find access token, check if the environment variable 'SYSTEM_ACCESSTOKEN' exists and has valid data. https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml#systemaccesstoken"-logMessageWriteMethod 'Error'
165
+
Throw"Error - OIDC ADO - Could not find access token, check if the environment variable 'SYSTEM_ACCESSTOKEN' exists and has valid data. https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml#systemaccesstoken"
0 commit comments