Azure / Azure/azure-devops-cli-extension
[Feature request] az devops command for making rest requests
- Dominant language
- Python
- Stars
- 682
- Forks
- 278
- Avg merge
- 3d 23h
- Merged PRs (30d)
- 3
Description
I can use `az rest` to make request to the Azure DevOps REST API by setting the `--resource` parameter to the application id of Azure DevOps enterprise app. For example, the following command works:
```
$AZURE_DEVOPS_RESOURCE_ID = '499b84ac-1321-427f-aa17-267ca6975798'
# az rest will only pick up the entire body if it is on a single line.
$body = @"
{
"resource": {},
"pipelines": [
{
"authorized": true,
"id": $PipelineId
}
]
}
"@ | ConvertFrom-Json | ConvertTo-Json -Compress
$uri = "https://dev.azure.com/{organization}/{project}/_apis/pipelines/pipelinePermissions/endpoint/{serviceConnectionId}?api-version=5.1-preview.1"
az rest --resource $AZURE_DEVOPS_RESOURCE_ID --method PATCH --uri $uri --headers 'Content-Type=application/json' --body $body -o json
```
As described by `az rest -h`, `https://dev.azure.com` is not listed by `az cloud show --query endpoints -o json`, and hence `az rest` does not figure out the `az rest --resource` parameter out on its own.
There is already the `az devops invoke` command, but I find it hard to grok what to set its `--area`, `--resource` and `--route-parameters` to in order to make a similar request as the one I described above.
**Proposed solution**
Add a new command similar to `az devops rest` which would invoke `az rest --resource '499b84ac-1321-427f-aa17-267ca6975798'`, effectively making in an alias which could be used like this:
```
az devops rest --method PATCH --uri $uri --headers 'Content-Type=application/json' --body $body -o json
```
A command would help for discoverability because users will notice it for example by `az devops -h`.
**Alternative solutions**
The devops az-plugin could register an additional lookup entry for https://dev.azure.com so that `az rest` would work out of the box.
The docs of `az devops invoke` could be clearer so that it is easier to understand what arguments to pass to produce a path similar to `/{organization}/{project}/_apis/pipelines/pipelinePermissions/endpoint/{serviceConnectionId}`. An additional `--body` parameter would also be handy so that I do not have to write temporary files as I make requests with `--in-file`.
Contributor guide
Assessment
This issue has not been assessed yet.