From d82257ee504e3e5b763bf9fc64ffbc38eb820aa8 Mon Sep 17 00:00:00 2001 From: Azure SDK for Python bot Date: Wed, 22 Aug 2018 15:29:55 -0700 Subject: [PATCH] Created to sync Azure/azure-rest-api-specs#3563 (#2512) --- profiles/latest/graphrbac/graphrbac/models.go | 8 + .../preview/graphrbac/graphrbac/models.go | 8 + services/graphrbac/1.6/graphrbac/models.go | 21 +++ services/graphrbac/1.6/graphrbac/oauth2.go | 176 ++++++++++++++++++ .../1.6/graphrbac/serviceprincipals.go | 2 +- 5 files changed, 214 insertions(+), 1 deletion(-) create mode 100644 services/graphrbac/1.6/graphrbac/oauth2.go diff --git a/profiles/latest/graphrbac/graphrbac/models.go b/profiles/latest/graphrbac/graphrbac/models.go index 465433b526d5..387fdbf7d796 100644 --- a/profiles/latest/graphrbac/graphrbac/models.go +++ b/profiles/latest/graphrbac/graphrbac/models.go @@ -84,6 +84,7 @@ type PasswordCredential = original.PasswordCredential type PasswordCredentialListResult = original.PasswordCredentialListResult type PasswordCredentialsUpdateParameters = original.PasswordCredentialsUpdateParameters type PasswordProfile = original.PasswordProfile +type Permissions = original.Permissions type RequiredResourceAccess = original.RequiredResourceAccess type ResourceAccess = original.ResourceAccess type ServicePrincipal = original.ServicePrincipal @@ -101,6 +102,7 @@ type UserListResult = original.UserListResult type UserListResultIterator = original.UserListResultIterator type UserListResultPage = original.UserListResultPage type UserUpdateParameters = original.UserUpdateParameters +type OAuth2Client = original.OAuth2Client type ObjectsClient = original.ObjectsClient type ServicePrincipalsClient = original.ServicePrincipalsClient type UsersClient = original.UsersClient @@ -135,6 +137,12 @@ func PossibleObjectTypeValues() []ObjectType { func PossibleUserTypeValues() []UserType { return original.PossibleUserTypeValues() } +func NewOAuth2Client(tenantID string) OAuth2Client { + return original.NewOAuth2Client(tenantID) +} +func NewOAuth2ClientWithBaseURI(baseURI string, tenantID string) OAuth2Client { + return original.NewOAuth2ClientWithBaseURI(baseURI, tenantID) +} func NewObjectsClient(tenantID string) ObjectsClient { return original.NewObjectsClient(tenantID) } diff --git a/profiles/preview/graphrbac/graphrbac/models.go b/profiles/preview/graphrbac/graphrbac/models.go index 71479bb86fc3..b37affb99dec 100644 --- a/profiles/preview/graphrbac/graphrbac/models.go +++ b/profiles/preview/graphrbac/graphrbac/models.go @@ -84,6 +84,7 @@ type PasswordCredential = original.PasswordCredential type PasswordCredentialListResult = original.PasswordCredentialListResult type PasswordCredentialsUpdateParameters = original.PasswordCredentialsUpdateParameters type PasswordProfile = original.PasswordProfile +type Permissions = original.Permissions type RequiredResourceAccess = original.RequiredResourceAccess type ResourceAccess = original.ResourceAccess type ServicePrincipal = original.ServicePrincipal @@ -101,6 +102,7 @@ type UserListResult = original.UserListResult type UserListResultIterator = original.UserListResultIterator type UserListResultPage = original.UserListResultPage type UserUpdateParameters = original.UserUpdateParameters +type OAuth2Client = original.OAuth2Client type ObjectsClient = original.ObjectsClient type ServicePrincipalsClient = original.ServicePrincipalsClient type UsersClient = original.UsersClient @@ -135,6 +137,12 @@ func PossibleObjectTypeValues() []ObjectType { func PossibleUserTypeValues() []UserType { return original.PossibleUserTypeValues() } +func NewOAuth2Client(tenantID string) OAuth2Client { + return original.NewOAuth2Client(tenantID) +} +func NewOAuth2ClientWithBaseURI(baseURI string, tenantID string) OAuth2Client { + return original.NewOAuth2ClientWithBaseURI(baseURI, tenantID) +} func NewObjectsClient(tenantID string) ObjectsClient { return original.NewObjectsClient(tenantID) } diff --git a/services/graphrbac/1.6/graphrbac/models.go b/services/graphrbac/1.6/graphrbac/models.go index 1db6301a64e6..e7057e1b7b38 100644 --- a/services/graphrbac/1.6/graphrbac/models.go +++ b/services/graphrbac/1.6/graphrbac/models.go @@ -1338,6 +1338,27 @@ func (pp PasswordProfile) MarshalJSON() ([]byte, error) { return json.Marshal(objectMap) } +// Permissions ... +type Permissions struct { + autorest.Response `json:"-"` + // OdataType - Microsoft.DirectoryServices.OAuth2PermissionGrant + OdataType *string `json:"odata.type,omitempty"` + // ClientID - The objectId of the Service Principal associated with the app + ClientID *string `json:"clientId,omitempty"` + // ConsentType - Typically set to AllPrincipals + ConsentType *string `json:"consentType,omitempty"` + // PrincipalID - Set to null if AllPrincipals is set + PrincipalID interface{} `json:"principalId,omitempty"` + // ResourceID - Service Principal Id of the resource you want to grant + ResourceID *string `json:"resourceId,omitempty"` + // Scope - Typically set to user_impersonation + Scope *string `json:"scope,omitempty"` + // StartTime - Start time for TTL + StartTime *string `json:"startTime,omitempty"` + // ExpiryTime - Expiry time for TTL + ExpiryTime *string `json:"expiryTime,omitempty"` +} + // RequiredResourceAccess specifies the set of OAuth 2.0 permission scopes and app roles under the specified // resource that an application requires access to. The specified OAuth 2.0 permission scopes may be requested by // client applications (through the requiredResourceAccess collection) when calling a resource application. The diff --git a/services/graphrbac/1.6/graphrbac/oauth2.go b/services/graphrbac/1.6/graphrbac/oauth2.go new file mode 100644 index 000000000000..97d465bf13b2 --- /dev/null +++ b/services/graphrbac/1.6/graphrbac/oauth2.go @@ -0,0 +1,176 @@ +package graphrbac + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "net/http" +) + +// OAuth2Client is the the Graph RBAC Management Client +type OAuth2Client struct { + BaseClient +} + +// NewOAuth2Client creates an instance of the OAuth2Client client. +func NewOAuth2Client(tenantID string) OAuth2Client { + return NewOAuth2ClientWithBaseURI(DefaultBaseURI, tenantID) +} + +// NewOAuth2ClientWithBaseURI creates an instance of the OAuth2Client client. +func NewOAuth2ClientWithBaseURI(baseURI string, tenantID string) OAuth2Client { + return OAuth2Client{NewWithBaseURI(baseURI, tenantID)} +} + +// Get queries OAuth2 permissions for the relevant SP ObjectId of an app. +// Parameters: +// filter - this is the Service Principal ObjectId associated with the app +func (client OAuth2Client) Get(ctx context.Context, filter string) (result Permissions, err error) { + req, err := client.GetPreparer(ctx, filter) + if err != nil { + err = autorest.NewErrorWithError(err, "graphrbac.OAuth2Client", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "graphrbac.OAuth2Client", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "graphrbac.OAuth2Client", "Get", resp, "Failure responding to request") + } + + return +} + +// GetPreparer prepares the Get request. +func (client OAuth2Client) GetPreparer(ctx context.Context, filter string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "tenantID": autorest.Encode("path", client.TenantID), + } + + const APIVersion = "1.6" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{tenantID}/oauth2PermissionGrants", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client OAuth2Client) GetSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client OAuth2Client) GetResponder(resp *http.Response) (result Permissions, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Post grants OAuth2 permissions for the relevant resource Ids of an app. +// Parameters: +// body - the relevant app Service Principal Object Id and the Service Principal Objecit Id you want to grant. +func (client OAuth2Client) Post(ctx context.Context, body *Permissions) (result Permissions, err error) { + req, err := client.PostPreparer(ctx, body) + if err != nil { + err = autorest.NewErrorWithError(err, "graphrbac.OAuth2Client", "Post", nil, "Failure preparing request") + return + } + + resp, err := client.PostSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "graphrbac.OAuth2Client", "Post", resp, "Failure sending request") + return + } + + result, err = client.PostResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "graphrbac.OAuth2Client", "Post", resp, "Failure responding to request") + } + + return +} + +// PostPreparer prepares the Post request. +func (client OAuth2Client) PostPreparer(ctx context.Context, body *Permissions) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "tenantID": autorest.Encode("path", client.TenantID), + } + + const APIVersion = "1.6" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{tenantID}/oauth2PermissionGrants", pathParameters), + autorest.WithQueryParameters(queryParameters)) + if body != nil { + preparer = autorest.DecoratePreparer(preparer, + autorest.WithJSON(body)) + } + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// PostSender sends the Post request. The method will close the +// http.Response Body if it receives an error. +func (client OAuth2Client) PostSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// PostResponder handles the response to the Post request. The method always +// closes the http.Response Body. +func (client OAuth2Client) PostResponder(resp *http.Response) (result Permissions, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/services/graphrbac/1.6/graphrbac/serviceprincipals.go b/services/graphrbac/1.6/graphrbac/serviceprincipals.go index 4caf3f817e1f..2b09eaf96dc7 100644 --- a/services/graphrbac/1.6/graphrbac/serviceprincipals.go +++ b/services/graphrbac/1.6/graphrbac/serviceprincipals.go @@ -178,7 +178,7 @@ func (client ServicePrincipalsClient) DeleteResponder(resp *http.Response) (resu return } -// Get gets service principal information from the directory. +// Get gets service principal information from the directory. Query by objectId or pass a filter to query by appId // Parameters: // objectID - the object ID of the service principal to get. func (client ServicePrincipalsClient) Get(ctx context.Context, objectID string) (result ServicePrincipal, err error) {