diff --git a/src/azure-cli/azure/cli/command_modules/util/_help.py b/src/azure-cli/azure/cli/command_modules/util/_help.py index fecd0525057..af5e35cb632 100644 --- a/src/azure-cli/azure/cli/command_modules/util/_help.py +++ b/src/azure-cli/azure/cli/command_modules/util/_help.py @@ -11,7 +11,7 @@ type: command short-summary: Invoke a custom request. long-summary: > - This command automatically authenticates using the credential logged in: If Authorization header is not set, it + This command automatically authenticates using the logged-in credential: If Authorization header is not set, it attaches header `Authorization: Bearer `, where `` is retrieved from AAD. The target resource of the token is derived from --url if --url starts with an endpoint from `az cloud show --query endpoints`. You may also use --resource for a custom resource. @@ -21,16 +21,16 @@ examples: - name: Get Audit log through Microsoft Graph text: > - az rest --method get --uri https://graph.microsoft.com/beta/auditLogs/directoryAudits + az rest --method get --url https://graph.microsoft.com/beta/auditLogs/directoryAudits - name: Update a Azure Active Directory Graph User's display name text: > - az rest --method patch --uri "https://graph.microsoft.com/v1.0/users/johndoe@azuresdkteam.onmicrosoft.com" --body "{\\"displayName\\": \\"jondoe2\\"}" + az rest --method patch --url "https://graph.microsoft.com/v1.0/users/johndoe@azuresdkteam.onmicrosoft.com" --body "{\\"displayName\\": \\"jondoe2\\"}" - name: Get a virtual machine text: > az rest --method get --uri /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}?api-version=2019-03-01 - name: Create a public IP address from body.json file text: > - az rest --method put --uri https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/publicIPAddresses/{publicIpAddressName}?api-version=2019-09-01 --body @body.json + az rest --method put --url https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/publicIPAddresses/{publicIpAddressName}?api-version=2019-09-01 --body @body.json """ helps['version'] = """ diff --git a/src/azure-cli/azure/cli/command_modules/util/tests/latest/recordings/test_rest_microsoft_graph.yaml b/src/azure-cli/azure/cli/command_modules/util/tests/latest/recordings/test_rest_microsoft_graph.yaml new file mode 100644 index 00000000000..b54198e6d83 --- /dev/null +++ b/src/azure-cli/azure/cli/command_modules/util/tests/latest/recordings/test_rest_microsoft_graph.yaml @@ -0,0 +1,573 @@ +interactions: +- request: + body: '{"displayName": "az-rest-test-app000001"}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + CommandName: + - rest + Connection: + - keep-alive + Content-Length: + - '44' + Content-Type: + - application/json + ParameterSetName: + - --method --url --body + User-Agent: + - AZURECLI/2.7.0 + method: POST + uri: https://graph.microsoft.com/v1.0/applications + response: + body: + string: '{"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#applications/$entity", + "id": "75ae48c3-0185-4a22-9b0b-a0297e9a7202", "deletedDateTime": null, "appId": + "7d8c8211-69d3-4821-ba83-aa49cdf0bb13", "applicationTemplateId": null, "createdDateTime": + "2020-06-08T02:33:12.9874414Z", "displayName": "az-rest-test-app000001", "groupMembershipClaims": + null, "identifierUris": [], "isDeviceOnlyAuthSupported": null, "isFallbackPublicClient": + null, "optionalClaims": null, "publisherDomain": "AzureSDKTeam.onmicrosoft.com", + "signInAudience": "AzureADandPersonalMicrosoftAccount", "tags": [], "tokenEncryptionKeyId": + null, "spa": {"redirectUris": []}, "addIns": [], "api": {"acceptMappedClaims": + null, "knownClientApplications": [], "requestedAccessTokenVersion": 2, "oauth2PermissionScopes": + [], "preAuthorizedApplications": []}, "appRoles": [], "info": {"logoUrl": + null, "marketingUrl": null, "privacyStatementUrl": null, "supportUrl": null, + "termsOfServiceUrl": null}, "keyCredentials": [], "parentalControlSettings": + {"countriesBlockedForMinors": [], "legalAgeGroupRule": "Allow"}, "passwordCredentials": + [], "publicClient": {"redirectUris": []}, "requiredResourceAccess": [], "web": + {"homePageUrl": null, "logoutUrl": null, "redirectUris": [], "implicitGrantSettings": + {"enableAccessTokenIssuance": false, "enableIdTokenIssuance": false}}}' + headers: + cache-control: + - private + content-length: + - '1260' + content-type: + - application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8 + date: + - Mon, 08 Jun 2020 02:33:14 GMT + location: + - https://graph.microsoft.com/v2/54826b22-38d6-4fb2-bad9-b7b93a3e9c5a/directoryObjects/75ae48c3-0185-4a22-9b0b-a0297e9a7202/Microsoft.DirectoryServices.Application + odata-version: + - '4.0' + request-id: + - 13c30359-f683-4004-9cde-aa3b52145e43 + strict-transport-security: + - max-age=31536000 + x-ms-ags-diagnostic: + - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_10"}}' + status: + code: 201 + message: Created +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + CommandName: + - rest + Connection: + - keep-alive + ParameterSetName: + - --method --uri + User-Agent: + - AZURECLI/2.7.0 + method: GET + uri: https://graph.microsoft.com/v1.0/applications/75ae48c3-0185-4a22-9b0b-a0297e9a7202 + response: + body: + string: '{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#applications/$entity","id":"75ae48c3-0185-4a22-9b0b-a0297e9a7202","deletedDateTime":null,"appId":"7d8c8211-69d3-4821-ba83-aa49cdf0bb13","applicationTemplateId":null,"createdDateTime":"2020-06-08T02:33:12Z","displayName":"az-rest-test-app000001","groupMembershipClaims":null,"identifierUris":[],"isDeviceOnlyAuthSupported":null,"isFallbackPublicClient":null,"optionalClaims":null,"publisherDomain":"AzureSDKTeam.onmicrosoft.com","signInAudience":"AzureADandPersonalMicrosoftAccount","tags":[],"tokenEncryptionKeyId":null,"spa":{"redirectUris":[]},"addIns":[],"api":{"acceptMappedClaims":null,"knownClientApplications":[],"requestedAccessTokenVersion":2,"oauth2PermissionScopes":[],"preAuthorizedApplications":[]},"appRoles":[],"info":{"logoUrl":null,"marketingUrl":null,"privacyStatementUrl":null,"supportUrl":null,"termsOfServiceUrl":null},"keyCredentials":[],"parentalControlSettings":{"countriesBlockedForMinors":[],"legalAgeGroupRule":"Allow"},"passwordCredentials":[],"publicClient":{"redirectUris":[]},"requiredResourceAccess":[],"web":{"homePageUrl":null,"logoutUrl":null,"redirectUris":[],"implicitGrantSettings":{"enableAccessTokenIssuance":false,"enableIdTokenIssuance":false}}}' + headers: + cache-control: + - private + content-length: + - '1252' + content-type: + - application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8 + date: + - Mon, 08 Jun 2020 02:33:15 GMT + odata-version: + - '4.0' + request-id: + - 6a291a2b-2625-41ef-8987-e41f37c5137b + strict-transport-security: + - max-age=31536000 + vary: + - Accept-Encoding + x-ms-ags-diagnostic: + - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_9"}}' + status: + code: 200 + message: OK +- request: + body: '{"web":{"redirectUris":["https://myapp.com"]}}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + CommandName: + - rest + Connection: + - keep-alive + Content-Length: + - '46' + Content-Type: + - application/json + ParameterSetName: + - --method --url --body + User-Agent: + - AZURECLI/2.7.0 + method: PATCH + uri: https://graph.microsoft.com/v1.0/applications/75ae48c3-0185-4a22-9b0b-a0297e9a7202 + response: + body: + string: '' + headers: + cache-control: + - private + content-type: + - text/plain + date: + - Mon, 08 Jun 2020 02:33:17 GMT + request-id: + - b703b62a-0e5b-4386-aa80-67b972b5a117 + strict-transport-security: + - max-age=31536000 + x-ms-ags-diagnostic: + - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_0"}}' + status: + code: 204 + message: No Content +- request: + body: '{"passwordCredential": {"displayName": "Password friendly name"}}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + CommandName: + - rest + Connection: + - keep-alive + Content-Length: + - '65' + Content-Type: + - application/json + ParameterSetName: + - --method --uri --body + User-Agent: + - AZURECLI/2.7.0 + method: POST + uri: https://graph.microsoft.com/v1.0/applications/75ae48c3-0185-4a22-9b0b-a0297e9a7202/addPassword + response: + body: + string: '{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#microsoft.graph.passwordCredential","customKeyIdentifier":null,"displayName":"Password + friendly name","endDateTime":"2022-06-08T02:33:18.2547822Z","hint":"N0S","keyId":"99202341-db26-49b5-945f-1eaf782d9e78","secretText":"N0StLHtoIE_u_Q6go10cQR19~ckgJVoy-c","startDateTime":"2020-06-08T02:33:18.2547822Z"}' + headers: + cache-control: + - private + content-length: + - '366' + content-type: + - application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8 + date: + - Mon, 08 Jun 2020 02:33:19 GMT + location: + - https://graph.microsoft.com + odata-version: + - '4.0' + request-id: + - 05a5eb09-e11e-40c2-a4d7-6edbf68faa57 + strict-transport-security: + - max-age=31536000 + vary: + - Accept-Encoding + x-ms-ags-diagnostic: + - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_16"}}' + status: + code: 200 + message: OK +- request: + body: '{"appId": "7d8c8211-69d3-4821-ba83-aa49cdf0bb13"}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + CommandName: + - rest + Connection: + - keep-alive + Content-Length: + - '49' + Content-Type: + - application/json + ParameterSetName: + - --method --url --body + User-Agent: + - AZURECLI/2.7.0 + method: POST + uri: https://graph.microsoft.com/v1.0/serviceprincipals + response: + body: + string: '{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#servicePrincipals/$entity","id":"6424d6b1-d198-413c-a3f1-fbee548e06c9","deletedDateTime":null,"accountEnabled":true,"alternativeNames":[],"appDisplayName":"az-rest-test-app000001","appId":"7d8c8211-69d3-4821-ba83-aa49cdf0bb13","applicationTemplateId":null,"appOwnerOrganizationId":"54826b22-38d6-4fb2-bad9-b7b93a3e9c5a","appRoleAssignmentRequired":false,"displayName":"az-rest-test-app000001","homepage":null,"loginUrl":null,"logoutUrl":null,"notificationEmailAddresses":[],"preferredSingleSignOnMode":null,"preferredTokenSigningKeyThumbprint":null,"replyUrls":["https://myapp.com"],"samlSingleSignOnSettings":null,"servicePrincipalNames":["7d8c8211-69d3-4821-ba83-aa49cdf0bb13"],"servicePrincipalType":"Application","tags":[],"tokenEncryptionKeyId":null,"addIns":[],"appRoles":[],"info":{"logoUrl":null,"marketingUrl":null,"privacyStatementUrl":null,"supportUrl":null,"termsOfServiceUrl":null},"keyCredentials":[],"oauth2PermissionScopes":[],"passwordCredentials":[]}' + headers: + cache-control: + - private + content-length: + - '1036' + content-type: + - application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8 + date: + - Mon, 08 Jun 2020 02:33:19 GMT + location: + - https://graph.microsoft.com/v2/54826b22-38d6-4fb2-bad9-b7b93a3e9c5a/directoryObjects/6424d6b1-d198-413c-a3f1-fbee548e06c9/Microsoft.DirectoryServices.ServicePrincipal + odata-version: + - '4.0' + request-id: + - 76da8bec-d1ac-4782-aec3-3c95d87301e1 + strict-transport-security: + - max-age=31536000 + x-ms-ags-diagnostic: + - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_15"}}' + status: + code: 201 + message: Created +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + CommandName: + - rest + Connection: + - keep-alive + ParameterSetName: + - --method --uri + User-Agent: + - AZURECLI/2.7.0 + method: GET + uri: https://graph.microsoft.com/v1.0/servicePrincipals/6424d6b1-d198-413c-a3f1-fbee548e06c9 + response: + body: + string: '{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#servicePrincipals/$entity","id":"6424d6b1-d198-413c-a3f1-fbee548e06c9","deletedDateTime":null,"accountEnabled":true,"alternativeNames":[],"appDisplayName":"az-rest-test-app000001","appId":"7d8c8211-69d3-4821-ba83-aa49cdf0bb13","applicationTemplateId":null,"appOwnerOrganizationId":"54826b22-38d6-4fb2-bad9-b7b93a3e9c5a","appRoleAssignmentRequired":false,"displayName":"az-rest-test-app000001","homepage":null,"loginUrl":null,"logoutUrl":null,"notificationEmailAddresses":[],"preferredSingleSignOnMode":null,"preferredTokenSigningKeyThumbprint":null,"replyUrls":["https://myapp.com"],"samlSingleSignOnSettings":null,"servicePrincipalNames":["7d8c8211-69d3-4821-ba83-aa49cdf0bb13"],"servicePrincipalType":"Application","tags":[],"tokenEncryptionKeyId":null,"addIns":[],"appRoles":[],"info":{"logoUrl":null,"marketingUrl":null,"privacyStatementUrl":null,"supportUrl":null,"termsOfServiceUrl":null},"keyCredentials":[],"oauth2PermissionScopes":[],"passwordCredentials":[]}' + headers: + cache-control: + - private + content-length: + - '1036' + content-type: + - application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8 + date: + - Mon, 08 Jun 2020 02:33:20 GMT + odata-version: + - '4.0' + request-id: + - f3a2e5d8-f599-43cf-9859-971ba02990b7 + strict-transport-security: + - max-age=31536000 + vary: + - Accept-Encoding + x-ms-ags-diagnostic: + - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_27"}}' + status: + code: 200 + message: OK +- request: + body: '{"appRoleAssignmentRequired": true}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + CommandName: + - rest + Connection: + - keep-alive + Content-Length: + - '35' + Content-Type: + - application/json + ParameterSetName: + - --method --url --body + User-Agent: + - AZURECLI/2.7.0 + method: PATCH + uri: https://graph.microsoft.com/v1.0/servicePrincipals/6424d6b1-d198-413c-a3f1-fbee548e06c9 + response: + body: + string: '' + headers: + cache-control: + - private + content-type: + - text/plain + date: + - Mon, 08 Jun 2020 02:33:22 GMT + request-id: + - 4923b9af-3cbc-4e8f-948d-b80474ca07d3 + strict-transport-security: + - max-age=31536000 + x-ms-ags-diagnostic: + - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_1"}}' + status: + code: 204 + message: No Content +- request: + body: '{"passwordCredential": {"displayName": "Password friendly name"}}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + CommandName: + - rest + Connection: + - keep-alive + Content-Length: + - '65' + Content-Type: + - application/json + ParameterSetName: + - --method --uri --body + User-Agent: + - AZURECLI/2.7.0 + method: POST + uri: https://graph.microsoft.com/v1.0/servicePrincipals/6424d6b1-d198-413c-a3f1-fbee548e06c9/addPassword + response: + body: + string: '{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#microsoft.graph.passwordCredential","customKeyIdentifier":null,"displayName":"Password + friendly name","endDateTime":"2022-06-08T02:33:23.6822267Z","hint":null,"keyId":"59afc0c8-153b-4d58-8cf9-29f1fe6f83e3","secretText":"1RW43ZQWl2aTFfUGVw1HT3q~_~ZR70W._A","startDateTime":"2020-06-08T02:33:23.6822267Z"}' + headers: + cache-control: + - private + content-length: + - '365' + content-type: + - application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8 + date: + - Mon, 08 Jun 2020 02:33:23 GMT + location: + - https://graph.microsoft.com + odata-version: + - '4.0' + request-id: + - aee5a2a4-8198-43ae-8e80-946126ab5a9d + strict-transport-security: + - max-age=31536000 + vary: + - Accept-Encoding + x-ms-ags-diagnostic: + - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_26"}}' + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + CommandName: + - rest + Connection: + - keep-alive + Content-Length: + - '0' + ParameterSetName: + - --method --url + User-Agent: + - AZURECLI/2.7.0 + method: DELETE + uri: https://graph.microsoft.com/v1.0/serviceprincipals/6424d6b1-d198-413c-a3f1-fbee548e06c9 + response: + body: + string: '' + headers: + cache-control: + - private + content-type: + - text/plain + date: + - Mon, 08 Jun 2020 02:33:24 GMT + request-id: + - cfa21c51-4e50-49a5-aa8b-7bfdf6c04757 + strict-transport-security: + - max-age=31536000 + x-ms-ags-diagnostic: + - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_7"}}' + status: + code: 204 + message: No Content +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + CommandName: + - rest + Connection: + - keep-alive + ParameterSetName: + - --method --url + User-Agent: + - AZURECLI/2.7.0 + method: GET + uri: https://graph.microsoft.com/v1.0/servicePrincipals/6424d6b1-d198-413c-a3f1-fbee548e06c9 + response: + body: + string: "{\r\n \"error\": {\r\n \"code\": \"Request_ResourceNotFound\",\r\n + \ \"message\": \"Resource '6424d6b1-d198-413c-a3f1-fbee548e06c9' does not + exist or one of its queried reference-property objects are not present.\",\r\n + \ \"innerError\": {\r\n \"request-id\": \"9c9cac43-fa0c-479f-99d3-d903c71857bd\",\r\n + \ \"date\": \"2020-06-08T02:33:25\"\r\n }\r\n }\r\n}" + headers: + cache-control: + - private + content-length: + - '338' + content-type: + - application/json + date: + - Mon, 08 Jun 2020 02:33:25 GMT + request-id: + - 9c9cac43-fa0c-479f-99d3-d903c71857bd + strict-transport-security: + - max-age=31536000 + x-ms-ags-diagnostic: + - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_14"}}' + status: + code: 404 + message: Not Found +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + CommandName: + - rest + Connection: + - keep-alive + Content-Length: + - '0' + ParameterSetName: + - --method --url + User-Agent: + - AZURECLI/2.7.0 + method: DELETE + uri: https://graph.microsoft.com/v1.0/applications/75ae48c3-0185-4a22-9b0b-a0297e9a7202 + response: + body: + string: '' + headers: + cache-control: + - private + content-type: + - text/plain + date: + - Mon, 08 Jun 2020 02:33:33 GMT + request-id: + - fbbdb05c-1deb-42c3-b3a9-202827b42cd2 + strict-transport-security: + - max-age=31536000 + x-ms-ags-diagnostic: + - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_15"}}' + status: + code: 204 + message: No Content +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + CommandName: + - rest + Connection: + - keep-alive + ParameterSetName: + - --method --url + User-Agent: + - AZURECLI/2.7.0 + method: GET + uri: https://graph.microsoft.com/v1.0/applications/75ae48c3-0185-4a22-9b0b-a0297e9a7202 + response: + body: + string: "{\r\n \"error\": {\r\n \"code\": \"Request_ResourceNotFound\",\r\n + \ \"message\": \"Resource '75ae48c3-0185-4a22-9b0b-a0297e9a7202' does not + exist or one of its queried reference-property objects are not present.\",\r\n + \ \"innerError\": {\r\n \"request-id\": \"31f94eaa-f1b1-4add-94bb-065810cff2a1\",\r\n + \ \"date\": \"2020-06-08T02:33:35\"\r\n }\r\n }\r\n}" + headers: + cache-control: + - private + content-length: + - '338' + content-type: + - application/json + date: + - Mon, 08 Jun 2020 02:33:35 GMT + request-id: + - 31f94eaa-f1b1-4add-94bb-065810cff2a1 + strict-transport-security: + - max-age=31536000 + x-ms-ags-diagnostic: + - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_0"}}' + status: + code: 404 + message: Not Found +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + CommandName: + - rest + Connection: + - keep-alive + ParameterSetName: + - -m -u + User-Agent: + - AZURECLI/2.7.0 + method: GET + uri: https://graph.microsoft.com/v1.0/applications?$filter=startswith(displayName,%20'az-rest-test-app') + response: + body: + string: '{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#applications","value":[]}' + headers: + cache-control: + - private + content-length: + - '87' + content-type: + - application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8 + date: + - Mon, 08 Jun 2020 02:33:36 GMT + odata-version: + - '4.0' + request-id: + - 12bcce9d-5405-4bc9-b2e3-36379ec2057f + strict-transport-security: + - max-age=31536000 + vary: + - Accept-Encoding + x-ms-ags-diagnostic: + - '{"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"5","ScaleUnit":"000","RoleInstance":"AGSFE_IN_21"}}' + status: + code: 200 + message: OK +version: 1 diff --git a/src/azure-cli/azure/cli/command_modules/util/tests/latest/test_rest.py b/src/azure-cli/azure/cli/command_modules/util/tests/latest/test_rest.py index 4e6abc55b9b..e75770e4b5d 100644 --- a/src/azure-cli/azure/cli/command_modules/util/tests/latest/test_rest.py +++ b/src/azure-cli/azure/cli/command_modules/util/tests/latest/test_rest.py @@ -77,6 +77,83 @@ def test_rest(self, resource_group): # https://docs.microsoft.com/en-us/rest/api/storagerp/storageaccounts/delete self.cmd('az rest -m DELETE -u "/subscriptions/{{subscriptionId}}/resourceGroups/{rg}/providers/Microsoft.Storage/storageAccounts/{sa}?api-version=2019-06-01"') + def test_rest_microsoft_graph(self): + from knack.util import CLIError + + display_name_prefix = "az-rest-test-app" + self.kwargs.update({ + 'display_name_prefix': display_name_prefix, + 'display_name': self.create_random_name(display_name_prefix, length=25) + }) + + # Create application + # https://docs.microsoft.com/en-us/graph/api/application-post-applications?view=graph-rest-1.0&tabs=http + # Escape single quotes for `shlex` and curly braces for `format` + app = self.cmd('az rest --method POST --url https://graph.microsoft.com/v1.0/applications --body \'{{"displayName": "{display_name}"}}\'', + checks=[ + self.check('displayName', '{display_name}') + ]).get_output_in_json() + + self.kwargs["app_object_id"] = app["id"] + self.kwargs["app_id"] = app["appId"] + + # Get application + # https://docs.microsoft.com/en-us/graph/api/application-get?view=graph-rest-1.0&tabs=http + self.cmd('az rest --method GET --url https://graph.microsoft.com/v1.0/applications/{app_object_id}', + checks=[self.check('displayName', '{display_name}')]) + + # Update application + # https://docs.microsoft.com/en-us/graph/api/application-update?view=graph-rest-1.0&tabs=http + self.cmd('az rest --method PATCH --url https://graph.microsoft.com/v1.0/applications/{app_object_id} --body \'{{"web":{{"redirectUris":["https://myapp.com"]}}}}\'') + + # application: addPassword + # https://docs.microsoft.com/en-us/graph/api/application-addpassword?view=graph-rest-1.0&tabs=http + self.cmd('az rest --method POST --url https://graph.microsoft.com/v1.0/applications/{app_object_id}/addPassword ' + '--body \'{{"passwordCredential": {{"displayName": "Password friendly name"}}}}\'', + checks=[self.check('displayName', "Password friendly name")]) + + # Create servicePrincipal + # https://docs.microsoft.com/en-us/graph/api/serviceprincipal-post-serviceprincipals?view=graph-rest-1.0&tabs=http + sp = self.cmd('az rest --method POST --url https://graph.microsoft.com/v1.0/serviceprincipals --body \'{{"appId": "{app_id}"}}\'').get_output_in_json() + self.kwargs["sp_object_id"] = sp["id"] + + # Get servicePrincipal + # https://docs.microsoft.com/en-us/graph/api/serviceprincipal-get?view=graph-rest-1.0&tabs=http + self.cmd('az rest --method GET --url https://graph.microsoft.com/v1.0/servicePrincipals/{sp_object_id}', + checks=[self.check('appId', '{app_id}'), + self.check('id', '{sp_object_id}')]) + + # Update servicePrincipal + # https://docs.microsoft.com/en-us/graph/api/serviceprincipal-update?view=graph-rest-1.0&tabs=http + self.cmd('az rest --method PATCH --url https://graph.microsoft.com/v1.0/servicePrincipals/{sp_object_id} ' + '--body \'{{"appRoleAssignmentRequired": true}}\'') + + # servicePrincipal: addPassword + # https://docs.microsoft.com/en-us/graph/api/serviceprincipal-addpassword?view=graph-rest-1.0&tabs=http + self.cmd('az rest --method POST --url https://graph.microsoft.com/v1.0/servicePrincipals/{sp_object_id}/addPassword ' + '--body \'{{"passwordCredential": {{"displayName": "Password friendly name"}}}}\'', + checks=[self.check('displayName', "Password friendly name")]) + + # Delete servicePrincipal + # https://docs.microsoft.com/en-us/graph/api/serviceprincipal-delete?view=graph-rest-1.0&tabs=http + self.cmd('az rest --method DELETE --url https://graph.microsoft.com/v1.0/serviceprincipals/{sp_object_id}') + + with self.assertRaisesRegex(CLIError, "Request_ResourceNotFound"): + self.cmd('az rest --method GET --url https://graph.microsoft.com/v1.0/servicePrincipals/{sp_object_id}') + + # Delete application + # https://docs.microsoft.com/en-us/graph/api/application-delete?view=graph-rest-1.0&tabs=http + self.cmd('az rest --method DELETE --url https://graph.microsoft.com/v1.0/applications/{app_object_id}') + + with self.assertRaisesRegex(CLIError, "Request_ResourceNotFound"): + self.cmd('az rest --method GET --url https://graph.microsoft.com/v1.0/applications/{app_object_id}') + + # Clear the trash left behind by failed tests + response = self.cmd('az rest -m GET -u "https://graph.microsoft.com/v1.0/applications?$filter=startswith(displayName, \'{display_name_prefix}\')"').get_output_in_json() + apps = response['value'] + for app in apps: + self.cmd('az rest --method DELETE --url https://graph.microsoft.com/v1.0/applications/{}'.format(app['id'])) + if __name__ == '__main__': unittest.main()