diff --git a/services/graphrbac/1.6/graphrbac/applications.go b/services/graphrbac/1.6/graphrbac/applications.go index 8c25193ac34d..bc29bb9bf3ec 100644 --- a/services/graphrbac/1.6/graphrbac/applications.go +++ b/services/graphrbac/1.6/graphrbac/applications.go @@ -18,27 +18,22 @@ package graphrbac // Changes may cause incorrect behavior and will be lost if the code is regenerated. import ( + "bytes" "context" - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/Azure/go-autorest/autorest/to" - "github.com/Azure/go-autorest/autorest/validation" + "encoding/json" + "github.com/Azure/azure-pipeline-go/pipeline" + "io/ioutil" "net/http" ) // ApplicationsClient is the the Graph RBAC Management Client type ApplicationsClient struct { - BaseClient + ManagementClient } // NewApplicationsClient creates an instance of the ApplicationsClient client. -func NewApplicationsClient(tenantID string) ApplicationsClient { - return NewApplicationsClientWithBaseURI(DefaultBaseURI, tenantID) -} - -// NewApplicationsClientWithBaseURI creates an instance of the ApplicationsClient client. -func NewApplicationsClientWithBaseURI(baseURI string, tenantID string) ApplicationsClient { - return ApplicationsClient{NewWithBaseURI(baseURI, tenantID)} +func NewApplicationsClient(p pipeline.Pipeline) ApplicationsClient { + return ApplicationsClient{NewManagementClient(p)} } // AddOwner add an owner to an application. @@ -46,813 +41,622 @@ func NewApplicationsClientWithBaseURI(baseURI string, tenantID string) Applicati // applicationObjectID is the object ID of the application to which to add the owner. parameters is the URL of the // owner object, such as // https://graph.windows.net/0b1f9851-1bf0-433f-aec3-cb9272f093dc/directoryObjects/f260bbc4-c254-447b-94cf-293b5ec434dd. -func (client ApplicationsClient) AddOwner(ctx context.Context, applicationObjectID string, parameters ApplicationAddOwnerParameters) (result autorest.Response, err error) { - if err := validation.Validate([]validation.Validation{ - {TargetValue: parameters, - Constraints: []validation.Constraint{{Target: "parameters.URL", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { - return result, validation.NewErrorWithValidationError(err, "graphrbac.ApplicationsClient", "AddOwner") +func (client ApplicationsClient) AddOwner(ctx context.Context, applicationObjectID string, parameters ApplicationAddOwnerParameters) (*http.Response, error) { + if err := validate([]validation{ + {targetValue: parameters, + constraints: []constraint{{target: "parameters.URL", name: null, rule: true, chain: nil}}}}); err != nil { + return nil, err } - - req, err := client.AddOwnerPreparer(ctx, applicationObjectID, parameters) + req, err := client.addOwnerPreparer(applicationObjectID, parameters) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ApplicationsClient", "AddOwner", nil, "Failure preparing request") - return + return nil, err } - - resp, err := client.AddOwnerSender(req) + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.addOwnerResponder}, req) if err != nil { - result.Response = resp - err = autorest.NewErrorWithError(err, "graphrbac.ApplicationsClient", "AddOwner", resp, "Failure sending request") - return + return nil, err } + return resp.Response(), err +} - result, err = client.AddOwnerResponder(resp) +// addOwnerPreparer prepares the AddOwner request. +func (client ApplicationsClient) addOwnerPreparer(applicationObjectID string, parameters ApplicationAddOwnerParameters) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/applications/{applicationObjectId}/$links/owners" + req, err := pipeline.NewRequest("POST", u, nil) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ApplicationsClient", "AddOwner", resp, "Failure responding to request") + return req, pipeline.NewError(err, "failed to create request") } - - return -} - -// AddOwnerPreparer prepares the AddOwner request. -func (client ApplicationsClient) AddOwnerPreparer(ctx context.Context, applicationObjectID string, parameters ApplicationAddOwnerParameters) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "applicationObjectId": autorest.Encode("path", applicationObjectID), - "tenantID": autorest.Encode("path", client.TenantID), + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + b, err := json.Marshal(parameters) + if err != nil { + return req, pipeline.NewError(err, "failed to marshal request body") } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, + req.Header.Set("Content-Type", "application/json") + err = req.SetBody(bytes.NewReader(b)) + if err != nil { + return req, pipeline.NewError(err, "failed to set request body") } - - preparer := autorest.CreatePreparer( - autorest.AsJSON(), - autorest.AsPost(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/applications/{applicationObjectId}/$links/owners", pathParameters), - autorest.WithJSON(parameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// AddOwnerSender sends the AddOwner request. The method will close the -// http.Response Body if it receives an error. -func (client ApplicationsClient) AddOwnerSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) + return req, nil } -// AddOwnerResponder handles the response to the AddOwner request. The method always -// closes the http.Response Body. -func (client ApplicationsClient) AddOwnerResponder(resp *http.Response) (result autorest.Response, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), - autorest.ByClosing()) - result.Response = resp - return +// addOwnerResponder handles the response to the AddOwner request. +func (client ApplicationsClient) addOwnerResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK, http.StatusNoContent) + if resp == nil { + return nil, err + } + return resp, err } // Create create a new application. // // parameters is the parameters for creating an application. -func (client ApplicationsClient) Create(ctx context.Context, parameters ApplicationCreateParameters) (result Application, err error) { - if err := validation.Validate([]validation.Validation{ - {TargetValue: parameters, - Constraints: []validation.Constraint{{Target: "parameters.AvailableToOtherTenants", Name: validation.Null, Rule: true, Chain: nil}, - {Target: "parameters.DisplayName", Name: validation.Null, Rule: true, Chain: nil}, - {Target: "parameters.IdentifierUris", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { - return result, validation.NewErrorWithValidationError(err, "graphrbac.ApplicationsClient", "Create") +func (client ApplicationsClient) Create(ctx context.Context, parameters ApplicationCreateParameters) (*Application, error) { + if err := validate([]validation{ + {targetValue: parameters, + constraints: []constraint{{target: "parameters.AvailableToOtherTenants", name: null, rule: true, chain: nil}, + {target: "parameters.DisplayName", name: null, rule: true, chain: nil}, + {target: "parameters.IdentifierUris", name: null, rule: true, chain: nil}}}}); err != nil { + return nil, err } - - req, err := client.CreatePreparer(ctx, parameters) + req, err := client.createPreparer(parameters) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ApplicationsClient", "Create", nil, "Failure preparing request") - return + return nil, err } - - resp, err := client.CreateSender(req) + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.createResponder}, req) if err != nil { - result.Response = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "graphrbac.ApplicationsClient", "Create", resp, "Failure sending request") - return + return nil, err } + return resp.(*Application), err +} - result, err = client.CreateResponder(resp) +// createPreparer prepares the Create request. +func (client ApplicationsClient) createPreparer(parameters ApplicationCreateParameters) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/applications" + req, err := pipeline.NewRequest("POST", u, nil) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ApplicationsClient", "Create", resp, "Failure responding to request") + return req, pipeline.NewError(err, "failed to create request") } - - return -} - -// CreatePreparer prepares the Create request. -func (client ApplicationsClient) CreatePreparer(ctx context.Context, parameters ApplicationCreateParameters) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "tenantID": autorest.Encode("path", client.TenantID), + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + b, err := json.Marshal(parameters) + if err != nil { + return req, pipeline.NewError(err, "failed to marshal request body") } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, + req.Header.Set("Content-Type", "application/json") + err = req.SetBody(bytes.NewReader(b)) + if err != nil { + return req, pipeline.NewError(err, "failed to set request body") } - - preparer := autorest.CreatePreparer( - autorest.AsJSON(), - autorest.AsPost(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/applications", pathParameters), - autorest.WithJSON(parameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// CreateSender sends the Create request. The method will close the -// http.Response Body if it receives an error. -func (client ApplicationsClient) CreateSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) + return req, nil } -// CreateResponder handles the response to the Create request. The method always -// closes the http.Response Body. -func (client ApplicationsClient) CreateResponder(resp *http.Response) (result Application, 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 +// createResponder handles the response to the Create request. +func (client ApplicationsClient) createResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK, http.StatusCreated) + if resp == nil { + return nil, err + } + result := &Application{rawResponse: resp.Response()} + if err != nil { + return result, err + } + defer resp.Response().Body.Close() + b, err := ioutil.ReadAll(resp.Response().Body) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to read response body") + } + if len(b) > 0 { + err = json.Unmarshal(b, result) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to unmarshal response body") + } + } + return result, nil } // Delete delete an application. // // applicationObjectID is application object ID. -func (client ApplicationsClient) Delete(ctx context.Context, applicationObjectID string) (result autorest.Response, err error) { - req, err := client.DeletePreparer(ctx, applicationObjectID) +func (client ApplicationsClient) Delete(ctx context.Context, applicationObjectID string) (*http.Response, error) { + req, err := client.deletePreparer(applicationObjectID) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ApplicationsClient", "Delete", nil, "Failure preparing request") - return + return nil, err } - - resp, err := client.DeleteSender(req) + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.deleteResponder}, req) if err != nil { - result.Response = resp - err = autorest.NewErrorWithError(err, "graphrbac.ApplicationsClient", "Delete", resp, "Failure sending request") - return + return nil, err } + return resp.Response(), err +} - result, err = client.DeleteResponder(resp) +// deletePreparer prepares the Delete request. +func (client ApplicationsClient) deletePreparer(applicationObjectID string) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/applications/{applicationObjectId}" + req, err := pipeline.NewRequest("DELETE", u, nil) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ApplicationsClient", "Delete", resp, "Failure responding to request") + return req, pipeline.NewError(err, "failed to create request") } - - return + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + return req, nil } -// DeletePreparer prepares the Delete request. -func (client ApplicationsClient) DeletePreparer(ctx context.Context, applicationObjectID string) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "applicationObjectId": autorest.Encode("path", applicationObjectID), - "tenantID": autorest.Encode("path", client.TenantID), +// deleteResponder handles the response to the Delete request. +func (client ApplicationsClient) deleteResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK, http.StatusNoContent) + if resp == nil { + return nil, err } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsDelete(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/applications/{applicationObjectId}", pathParameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// DeleteSender sends the Delete request. The method will close the -// http.Response Body if it receives an error. -func (client ApplicationsClient) DeleteSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) -} - -// DeleteResponder handles the response to the Delete request. The method always -// closes the http.Response Body. -func (client ApplicationsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), - autorest.ByClosing()) - result.Response = resp - return + return resp, err } // Get get an application by object ID. // // applicationObjectID is application object ID. -func (client ApplicationsClient) Get(ctx context.Context, applicationObjectID string) (result Application, err error) { - req, err := client.GetPreparer(ctx, applicationObjectID) +func (client ApplicationsClient) Get(ctx context.Context, applicationObjectID string) (*Application, error) { + req, err := client.getPreparer(applicationObjectID) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ApplicationsClient", "Get", nil, "Failure preparing request") - return + return nil, err } - - resp, err := client.GetSender(req) + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.getResponder}, req) if err != nil { - result.Response = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "graphrbac.ApplicationsClient", "Get", resp, "Failure sending request") - return + return nil, err } + return resp.(*Application), err +} - result, err = client.GetResponder(resp) +// getPreparer prepares the Get request. +func (client ApplicationsClient) getPreparer(applicationObjectID string) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/applications/{applicationObjectId}" + req, err := pipeline.NewRequest("GET", u, nil) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ApplicationsClient", "Get", resp, "Failure responding to request") + return req, pipeline.NewError(err, "failed to create request") } - - return + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + return req, nil } -// GetPreparer prepares the Get request. -func (client ApplicationsClient) GetPreparer(ctx context.Context, applicationObjectID string) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "applicationObjectId": autorest.Encode("path", applicationObjectID), - "tenantID": autorest.Encode("path", client.TenantID), +// getResponder handles the response to the Get request. +func (client ApplicationsClient) getResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK) + if resp == nil { + return nil, err } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, + result := &Application{rawResponse: resp.Response()} + if err != nil { + return result, err } - - preparer := autorest.CreatePreparer( - autorest.AsGet(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/applications/{applicationObjectId}", 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 ApplicationsClient) 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 ApplicationsClient) GetResponder(resp *http.Response) (result Application, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result), - autorest.ByClosing()) - result.Response = autorest.Response{Response: resp} - return + defer resp.Response().Body.Close() + b, err := ioutil.ReadAll(resp.Response().Body) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to read response body") + } + if len(b) > 0 { + err = json.Unmarshal(b, result) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to unmarshal response body") + } + } + return result, nil } // List lists applications by filter parameters. // // filter is the filters to apply to the operation. -func (client ApplicationsClient) List(ctx context.Context, filter string) (result ApplicationListResultPage, err error) { - result.fn = func(lastResult ApplicationListResult) (ApplicationListResult, error) { - if lastResult.OdataNextLink == nil || len(to.String(lastResult.OdataNextLink)) < 1 { - return ApplicationListResult{}, nil - } - return client.ListNext(ctx, *lastResult.OdataNextLink) - } - req, err := client.ListPreparer(ctx, filter) +func (client ApplicationsClient) List(ctx context.Context, filter *string) (*ApplicationListResult, error) { + req, err := client.listPreparer(filter) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ApplicationsClient", "List", nil, "Failure preparing request") - return + return nil, err } - - resp, err := client.ListSender(req) + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.listResponder}, req) if err != nil { - result.alr.Response = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "graphrbac.ApplicationsClient", "List", resp, "Failure sending request") - return + return nil, err } + return resp.(*ApplicationListResult), err +} - result.alr, err = client.ListResponder(resp) +// listPreparer prepares the List request. +func (client ApplicationsClient) listPreparer(filter *string) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/applications" + req, err := pipeline.NewRequest("GET", u, nil) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ApplicationsClient", "List", resp, "Failure responding to request") + return req, pipeline.NewError(err, "failed to create request") } - - return + params := req.URL.Query() + if filter != nil { + params.Set("$filter", *filter) + } + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + return req, nil } -// ListPreparer prepares the List request. -func (client ApplicationsClient) ListPreparer(ctx context.Context, filter string) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "tenantID": autorest.Encode("path", client.TenantID), +// listResponder handles the response to the List request. +func (client ApplicationsClient) listResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK) + if resp == nil { + return nil, err } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, + result := &ApplicationListResult{rawResponse: resp.Response()} + if err != nil { + return result, err } - if len(filter) > 0 { - queryParameters["$filter"] = autorest.Encode("query", filter) + defer resp.Response().Body.Close() + b, err := ioutil.ReadAll(resp.Response().Body) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to read response body") } - - preparer := autorest.CreatePreparer( - autorest.AsGet(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/applications", pathParameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// ListSender sends the List request. The method will close the -// http.Response Body if it receives an error. -func (client ApplicationsClient) ListSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) -} - -// ListResponder handles the response to the List request. The method always -// closes the http.Response Body. -func (client ApplicationsClient) ListResponder(resp *http.Response) (result ApplicationListResult, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result), - autorest.ByClosing()) - result.Response = autorest.Response{Response: resp} - return -} - -// ListComplete enumerates all values, automatically crossing page boundaries as required. -func (client ApplicationsClient) ListComplete(ctx context.Context, filter string) (result ApplicationListResultIterator, err error) { - result.page, err = client.List(ctx, filter) - return + if len(b) > 0 { + err = json.Unmarshal(b, result) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to unmarshal response body") + } + } + return result, nil } // ListKeyCredentials get the keyCredentials associated with an application. // // applicationObjectID is application object ID. -func (client ApplicationsClient) ListKeyCredentials(ctx context.Context, applicationObjectID string) (result KeyCredentialListResult, err error) { - req, err := client.ListKeyCredentialsPreparer(ctx, applicationObjectID) +func (client ApplicationsClient) ListKeyCredentials(ctx context.Context, applicationObjectID string) (*KeyCredentialListResult, error) { + req, err := client.listKeyCredentialsPreparer(applicationObjectID) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ApplicationsClient", "ListKeyCredentials", nil, "Failure preparing request") - return + return nil, err } - - resp, err := client.ListKeyCredentialsSender(req) + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.listKeyCredentialsResponder}, req) if err != nil { - result.Response = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "graphrbac.ApplicationsClient", "ListKeyCredentials", resp, "Failure sending request") - return + return nil, err } + return resp.(*KeyCredentialListResult), err +} - result, err = client.ListKeyCredentialsResponder(resp) +// listKeyCredentialsPreparer prepares the ListKeyCredentials request. +func (client ApplicationsClient) listKeyCredentialsPreparer(applicationObjectID string) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/applications/{applicationObjectId}/keyCredentials" + req, err := pipeline.NewRequest("GET", u, nil) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ApplicationsClient", "ListKeyCredentials", resp, "Failure responding to request") + return req, pipeline.NewError(err, "failed to create request") } - - return + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + return req, nil } -// ListKeyCredentialsPreparer prepares the ListKeyCredentials request. -func (client ApplicationsClient) ListKeyCredentialsPreparer(ctx context.Context, applicationObjectID string) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "applicationObjectId": autorest.Encode("path", applicationObjectID), - "tenantID": autorest.Encode("path", client.TenantID), +// listKeyCredentialsResponder handles the response to the ListKeyCredentials request. +func (client ApplicationsClient) listKeyCredentialsResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK) + if resp == nil { + return nil, err } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, + result := &KeyCredentialListResult{rawResponse: resp.Response()} + if err != nil { + return result, err } - - preparer := autorest.CreatePreparer( - autorest.AsGet(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/applications/{applicationObjectId}/keyCredentials", pathParameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// ListKeyCredentialsSender sends the ListKeyCredentials request. The method will close the -// http.Response Body if it receives an error. -func (client ApplicationsClient) ListKeyCredentialsSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) -} - -// ListKeyCredentialsResponder handles the response to the ListKeyCredentials request. The method always -// closes the http.Response Body. -func (client ApplicationsClient) ListKeyCredentialsResponder(resp *http.Response) (result KeyCredentialListResult, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result), - autorest.ByClosing()) - result.Response = autorest.Response{Response: resp} - return + defer resp.Response().Body.Close() + b, err := ioutil.ReadAll(resp.Response().Body) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to read response body") + } + if len(b) > 0 { + err = json.Unmarshal(b, result) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to unmarshal response body") + } + } + return result, nil } // ListNext gets a list of applications from the current tenant. // // nextLink is next link for the list operation. -func (client ApplicationsClient) ListNext(ctx context.Context, nextLink string) (result ApplicationListResult, err error) { - req, err := client.ListNextPreparer(ctx, nextLink) +func (client ApplicationsClient) ListNext(ctx context.Context, nextLink string) (*ApplicationListResult, error) { + req, err := client.listNextPreparer(nextLink) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ApplicationsClient", "ListNext", nil, "Failure preparing request") - return + return nil, err } - - resp, err := client.ListNextSender(req) + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.listNextResponder}, req) if err != nil { - result.Response = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "graphrbac.ApplicationsClient", "ListNext", resp, "Failure sending request") - return + return nil, err } + return resp.(*ApplicationListResult), err +} - result, err = client.ListNextResponder(resp) +// listNextPreparer prepares the ListNext request. +func (client ApplicationsClient) listNextPreparer(nextLink string) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/{nextLink}" + req, err := pipeline.NewRequest("GET", u, nil) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ApplicationsClient", "ListNext", resp, "Failure responding to request") + return req, pipeline.NewError(err, "failed to create request") } - - return + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + return req, nil } -// ListNextPreparer prepares the ListNext request. -func (client ApplicationsClient) ListNextPreparer(ctx context.Context, nextLink string) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "nextLink": nextLink, - "tenantID": autorest.Encode("path", client.TenantID), +// listNextResponder handles the response to the ListNext request. +func (client ApplicationsClient) listNextResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK) + if resp == nil { + return nil, err } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, + result := &ApplicationListResult{rawResponse: resp.Response()} + if err != nil { + return result, err } - - preparer := autorest.CreatePreparer( - autorest.AsGet(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/{nextLink}", pathParameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// ListNextSender sends the ListNext request. The method will close the -// http.Response Body if it receives an error. -func (client ApplicationsClient) ListNextSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) -} - -// ListNextResponder handles the response to the ListNext request. The method always -// closes the http.Response Body. -func (client ApplicationsClient) ListNextResponder(resp *http.Response) (result ApplicationListResult, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result), - autorest.ByClosing()) - result.Response = autorest.Response{Response: resp} - return + defer resp.Response().Body.Close() + b, err := ioutil.ReadAll(resp.Response().Body) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to read response body") + } + if len(b) > 0 { + err = json.Unmarshal(b, result) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to unmarshal response body") + } + } + return result, nil } // ListOwners the owners are a set of non-admin users who are allowed to modify this object. // // applicationObjectID is the object ID of the application for which to get owners. -func (client ApplicationsClient) ListOwners(ctx context.Context, applicationObjectID string) (result DirectoryObjectListResult, err error) { - req, err := client.ListOwnersPreparer(ctx, applicationObjectID) +func (client ApplicationsClient) ListOwners(ctx context.Context, applicationObjectID string) (*DirectoryObjectListResult, error) { + req, err := client.listOwnersPreparer(applicationObjectID) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ApplicationsClient", "ListOwners", nil, "Failure preparing request") - return + return nil, err } - - resp, err := client.ListOwnersSender(req) + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.listOwnersResponder}, req) if err != nil { - result.Response = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "graphrbac.ApplicationsClient", "ListOwners", resp, "Failure sending request") - return + return nil, err } + return resp.(*DirectoryObjectListResult), err +} - result, err = client.ListOwnersResponder(resp) +// listOwnersPreparer prepares the ListOwners request. +func (client ApplicationsClient) listOwnersPreparer(applicationObjectID string) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/applications/{applicationObjectId}/owners" + req, err := pipeline.NewRequest("GET", u, nil) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ApplicationsClient", "ListOwners", resp, "Failure responding to request") + return req, pipeline.NewError(err, "failed to create request") } - - return + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + return req, nil } -// ListOwnersPreparer prepares the ListOwners request. -func (client ApplicationsClient) ListOwnersPreparer(ctx context.Context, applicationObjectID string) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "applicationObjectId": autorest.Encode("path", applicationObjectID), - "tenantID": autorest.Encode("path", client.TenantID), +// listOwnersResponder handles the response to the ListOwners request. +func (client ApplicationsClient) listOwnersResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK) + if resp == nil { + return nil, err } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, + result := &DirectoryObjectListResult{rawResponse: resp.Response()} + if err != nil { + return result, err } - - preparer := autorest.CreatePreparer( - autorest.AsGet(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/applications/{applicationObjectId}/owners", pathParameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// ListOwnersSender sends the ListOwners request. The method will close the -// http.Response Body if it receives an error. -func (client ApplicationsClient) ListOwnersSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) -} - -// ListOwnersResponder handles the response to the ListOwners request. The method always -// closes the http.Response Body. -func (client ApplicationsClient) ListOwnersResponder(resp *http.Response) (result DirectoryObjectListResult, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result), - autorest.ByClosing()) - result.Response = autorest.Response{Response: resp} - return + defer resp.Response().Body.Close() + b, err := ioutil.ReadAll(resp.Response().Body) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to read response body") + } + if len(b) > 0 { + err = json.Unmarshal(b, result) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to unmarshal response body") + } + } + return result, nil } // ListPasswordCredentials get the passwordCredentials associated with an application. // // applicationObjectID is application object ID. -func (client ApplicationsClient) ListPasswordCredentials(ctx context.Context, applicationObjectID string) (result PasswordCredentialListResult, err error) { - req, err := client.ListPasswordCredentialsPreparer(ctx, applicationObjectID) +func (client ApplicationsClient) ListPasswordCredentials(ctx context.Context, applicationObjectID string) (*PasswordCredentialListResult, error) { + req, err := client.listPasswordCredentialsPreparer(applicationObjectID) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ApplicationsClient", "ListPasswordCredentials", nil, "Failure preparing request") - return + return nil, err } - - resp, err := client.ListPasswordCredentialsSender(req) + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.listPasswordCredentialsResponder}, req) if err != nil { - result.Response = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "graphrbac.ApplicationsClient", "ListPasswordCredentials", resp, "Failure sending request") - return + return nil, err } + return resp.(*PasswordCredentialListResult), err +} - result, err = client.ListPasswordCredentialsResponder(resp) +// listPasswordCredentialsPreparer prepares the ListPasswordCredentials request. +func (client ApplicationsClient) listPasswordCredentialsPreparer(applicationObjectID string) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/applications/{applicationObjectId}/passwordCredentials" + req, err := pipeline.NewRequest("GET", u, nil) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ApplicationsClient", "ListPasswordCredentials", resp, "Failure responding to request") + return req, pipeline.NewError(err, "failed to create request") } - - return + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + return req, nil } -// ListPasswordCredentialsPreparer prepares the ListPasswordCredentials request. -func (client ApplicationsClient) ListPasswordCredentialsPreparer(ctx context.Context, applicationObjectID string) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "applicationObjectId": autorest.Encode("path", applicationObjectID), - "tenantID": autorest.Encode("path", client.TenantID), +// listPasswordCredentialsResponder handles the response to the ListPasswordCredentials request. +func (client ApplicationsClient) listPasswordCredentialsResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK) + if resp == nil { + return nil, err } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, + result := &PasswordCredentialListResult{rawResponse: resp.Response()} + if err != nil { + return result, err } - - preparer := autorest.CreatePreparer( - autorest.AsGet(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/applications/{applicationObjectId}/passwordCredentials", pathParameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// ListPasswordCredentialsSender sends the ListPasswordCredentials request. The method will close the -// http.Response Body if it receives an error. -func (client ApplicationsClient) ListPasswordCredentialsSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) -} - -// ListPasswordCredentialsResponder handles the response to the ListPasswordCredentials request. The method always -// closes the http.Response Body. -func (client ApplicationsClient) ListPasswordCredentialsResponder(resp *http.Response) (result PasswordCredentialListResult, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result), - autorest.ByClosing()) - result.Response = autorest.Response{Response: resp} - return + defer resp.Response().Body.Close() + b, err := ioutil.ReadAll(resp.Response().Body) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to read response body") + } + if len(b) > 0 { + err = json.Unmarshal(b, result) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to unmarshal response body") + } + } + return result, nil } // Patch update an existing application. // // applicationObjectID is application object ID. parameters is parameters to update an existing application. -func (client ApplicationsClient) Patch(ctx context.Context, applicationObjectID string, parameters ApplicationUpdateParameters) (result autorest.Response, err error) { - req, err := client.PatchPreparer(ctx, applicationObjectID, parameters) +func (client ApplicationsClient) Patch(ctx context.Context, applicationObjectID string, parameters ApplicationUpdateParameters) (*http.Response, error) { + req, err := client.patchPreparer(applicationObjectID, parameters) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ApplicationsClient", "Patch", nil, "Failure preparing request") - return + return nil, err } - - resp, err := client.PatchSender(req) + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.patchResponder}, req) if err != nil { - result.Response = resp - err = autorest.NewErrorWithError(err, "graphrbac.ApplicationsClient", "Patch", resp, "Failure sending request") - return + return nil, err } + return resp.Response(), err +} - result, err = client.PatchResponder(resp) +// patchPreparer prepares the Patch request. +func (client ApplicationsClient) patchPreparer(applicationObjectID string, parameters ApplicationUpdateParameters) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/applications/{applicationObjectId}" + req, err := pipeline.NewRequest("PATCH", u, nil) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ApplicationsClient", "Patch", resp, "Failure responding to request") + return req, pipeline.NewError(err, "failed to create request") } - - return -} - -// PatchPreparer prepares the Patch request. -func (client ApplicationsClient) PatchPreparer(ctx context.Context, applicationObjectID string, parameters ApplicationUpdateParameters) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "applicationObjectId": autorest.Encode("path", applicationObjectID), - "tenantID": autorest.Encode("path", client.TenantID), + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + b, err := json.Marshal(parameters) + if err != nil { + return req, pipeline.NewError(err, "failed to marshal request body") } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, + req.Header.Set("Content-Type", "application/json") + err = req.SetBody(bytes.NewReader(b)) + if err != nil { + return req, pipeline.NewError(err, "failed to set request body") } - - preparer := autorest.CreatePreparer( - autorest.AsJSON(), - autorest.AsPatch(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/applications/{applicationObjectId}", pathParameters), - autorest.WithJSON(parameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// PatchSender sends the Patch request. The method will close the -// http.Response Body if it receives an error. -func (client ApplicationsClient) PatchSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) + return req, nil } -// PatchResponder handles the response to the Patch request. The method always -// closes the http.Response Body. -func (client ApplicationsClient) PatchResponder(resp *http.Response) (result autorest.Response, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), - autorest.ByClosing()) - result.Response = resp - return +// patchResponder handles the response to the Patch request. +func (client ApplicationsClient) patchResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK, http.StatusNoContent) + if resp == nil { + return nil, err + } + return resp, err } // UpdateKeyCredentials update the keyCredentials associated with an application. // // applicationObjectID is application object ID. parameters is parameters to update the keyCredentials of an existing // application. -func (client ApplicationsClient) UpdateKeyCredentials(ctx context.Context, applicationObjectID string, parameters KeyCredentialsUpdateParameters) (result autorest.Response, err error) { - req, err := client.UpdateKeyCredentialsPreparer(ctx, applicationObjectID, parameters) +func (client ApplicationsClient) UpdateKeyCredentials(ctx context.Context, applicationObjectID string, parameters KeyCredentialsUpdateParameters) (*http.Response, error) { + req, err := client.updateKeyCredentialsPreparer(applicationObjectID, parameters) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ApplicationsClient", "UpdateKeyCredentials", nil, "Failure preparing request") - return + return nil, err } - - resp, err := client.UpdateKeyCredentialsSender(req) + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.updateKeyCredentialsResponder}, req) if err != nil { - result.Response = resp - err = autorest.NewErrorWithError(err, "graphrbac.ApplicationsClient", "UpdateKeyCredentials", resp, "Failure sending request") - return + return nil, err } + return resp.Response(), err +} - result, err = client.UpdateKeyCredentialsResponder(resp) +// updateKeyCredentialsPreparer prepares the UpdateKeyCredentials request. +func (client ApplicationsClient) updateKeyCredentialsPreparer(applicationObjectID string, parameters KeyCredentialsUpdateParameters) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/applications/{applicationObjectId}/keyCredentials" + req, err := pipeline.NewRequest("PATCH", u, nil) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ApplicationsClient", "UpdateKeyCredentials", resp, "Failure responding to request") + return req, pipeline.NewError(err, "failed to create request") } - - return -} - -// UpdateKeyCredentialsPreparer prepares the UpdateKeyCredentials request. -func (client ApplicationsClient) UpdateKeyCredentialsPreparer(ctx context.Context, applicationObjectID string, parameters KeyCredentialsUpdateParameters) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "applicationObjectId": autorest.Encode("path", applicationObjectID), - "tenantID": autorest.Encode("path", client.TenantID), + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + b, err := json.Marshal(parameters) + if err != nil { + return req, pipeline.NewError(err, "failed to marshal request body") } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, + req.Header.Set("Content-Type", "application/json") + err = req.SetBody(bytes.NewReader(b)) + if err != nil { + return req, pipeline.NewError(err, "failed to set request body") } - - preparer := autorest.CreatePreparer( - autorest.AsJSON(), - autorest.AsPatch(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/applications/{applicationObjectId}/keyCredentials", pathParameters), - autorest.WithJSON(parameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) + return req, nil } -// UpdateKeyCredentialsSender sends the UpdateKeyCredentials request. The method will close the -// http.Response Body if it receives an error. -func (client ApplicationsClient) UpdateKeyCredentialsSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) -} - -// UpdateKeyCredentialsResponder handles the response to the UpdateKeyCredentials request. The method always -// closes the http.Response Body. -func (client ApplicationsClient) UpdateKeyCredentialsResponder(resp *http.Response) (result autorest.Response, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), - autorest.ByClosing()) - result.Response = resp - return +// updateKeyCredentialsResponder handles the response to the UpdateKeyCredentials request. +func (client ApplicationsClient) updateKeyCredentialsResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK, http.StatusNoContent) + if resp == nil { + return nil, err + } + return resp, err } // UpdatePasswordCredentials update passwordCredentials associated with an application. // // applicationObjectID is application object ID. parameters is parameters to update passwordCredentials of an existing // application. -func (client ApplicationsClient) UpdatePasswordCredentials(ctx context.Context, applicationObjectID string, parameters PasswordCredentialsUpdateParameters) (result autorest.Response, err error) { - req, err := client.UpdatePasswordCredentialsPreparer(ctx, applicationObjectID, parameters) +func (client ApplicationsClient) UpdatePasswordCredentials(ctx context.Context, applicationObjectID string, parameters PasswordCredentialsUpdateParameters) (*http.Response, error) { + req, err := client.updatePasswordCredentialsPreparer(applicationObjectID, parameters) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ApplicationsClient", "UpdatePasswordCredentials", nil, "Failure preparing request") - return + return nil, err } - - resp, err := client.UpdatePasswordCredentialsSender(req) + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.updatePasswordCredentialsResponder}, req) if err != nil { - result.Response = resp - err = autorest.NewErrorWithError(err, "graphrbac.ApplicationsClient", "UpdatePasswordCredentials", resp, "Failure sending request") - return + return nil, err } + return resp.Response(), err +} - result, err = client.UpdatePasswordCredentialsResponder(resp) +// updatePasswordCredentialsPreparer prepares the UpdatePasswordCredentials request. +func (client ApplicationsClient) updatePasswordCredentialsPreparer(applicationObjectID string, parameters PasswordCredentialsUpdateParameters) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/applications/{applicationObjectId}/passwordCredentials" + req, err := pipeline.NewRequest("PATCH", u, nil) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ApplicationsClient", "UpdatePasswordCredentials", resp, "Failure responding to request") + return req, pipeline.NewError(err, "failed to create request") } - - return -} - -// UpdatePasswordCredentialsPreparer prepares the UpdatePasswordCredentials request. -func (client ApplicationsClient) UpdatePasswordCredentialsPreparer(ctx context.Context, applicationObjectID string, parameters PasswordCredentialsUpdateParameters) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "applicationObjectId": autorest.Encode("path", applicationObjectID), - "tenantID": autorest.Encode("path", client.TenantID), + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + b, err := json.Marshal(parameters) + if err != nil { + return req, pipeline.NewError(err, "failed to marshal request body") } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, + req.Header.Set("Content-Type", "application/json") + err = req.SetBody(bytes.NewReader(b)) + if err != nil { + return req, pipeline.NewError(err, "failed to set request body") } - - preparer := autorest.CreatePreparer( - autorest.AsJSON(), - autorest.AsPatch(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/applications/{applicationObjectId}/passwordCredentials", pathParameters), - autorest.WithJSON(parameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) + return req, nil } -// UpdatePasswordCredentialsSender sends the UpdatePasswordCredentials request. The method will close the -// http.Response Body if it receives an error. -func (client ApplicationsClient) UpdatePasswordCredentialsSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) -} - -// UpdatePasswordCredentialsResponder handles the response to the UpdatePasswordCredentials request. The method always -// closes the http.Response Body. -func (client ApplicationsClient) UpdatePasswordCredentialsResponder(resp *http.Response) (result autorest.Response, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), - autorest.ByClosing()) - result.Response = resp - return +// updatePasswordCredentialsResponder handles the response to the UpdatePasswordCredentials request. +func (client ApplicationsClient) updatePasswordCredentialsResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK, http.StatusNoContent) + if resp == nil { + return nil, err + } + return resp, err } diff --git a/services/graphrbac/1.6/graphrbac/client.go b/services/graphrbac/1.6/graphrbac/client.go index 6f46fe18bf90..5340188474cf 100644 --- a/services/graphrbac/1.6/graphrbac/client.go +++ b/services/graphrbac/1.6/graphrbac/client.go @@ -1,6 +1,3 @@ -// Package graphrbac implements the Azure ARM Graphrbac service API version 1.6. -// -// The Graph RBAC Management Client package graphrbac // Copyright (c) Microsoft and contributors. All rights reserved. @@ -21,31 +18,46 @@ package graphrbac // Changes may cause incorrect behavior and will be lost if the code is regenerated. import ( - "github.com/Azure/go-autorest/autorest" + "github.com/Azure/azure-pipeline-go/pipeline" + "net/url" ) const ( - // DefaultBaseURI is the default URI used for the service Graphrbac - DefaultBaseURI = "https://graph.windows.net" + // ServiceVersion specifies the version of the operations used in this package. + ServiceVersion = "1.6" + // DefaultBaseURL is the default URL used for the service Graphrbac + DefaultBaseURL = "https://graph.windows.net" ) -// BaseClient is the base client for Graphrbac. -type BaseClient struct { - autorest.Client - BaseURI string - TenantID string +// ManagementClient is the base client for Graphrbac. +type ManagementClient struct { + url url.URL + p pipeline.Pipeline } -// New creates an instance of the BaseClient client. -func New(tenantID string) BaseClient { - return NewWithBaseURI(DefaultBaseURI, tenantID) +// NewManagementClient creates an instance of the ManagementClient client. +func NewManagementClient(p pipeline.Pipeline) ManagementClient { + u, err := url.Parse(DefaultBaseURL) + if err != nil { + panic(err) + } + return NewManagementClientWithURL(*u, p) } -// NewWithBaseURI creates an instance of the BaseClient client. -func NewWithBaseURI(baseURI string, tenantID string) BaseClient { - return BaseClient{ - Client: autorest.NewClientWithUserAgent(UserAgent()), - BaseURI: baseURI, - TenantID: tenantID, +// NewManagementClientWithURL creates an instance of the ManagementClient client. +func NewManagementClientWithURL(url url.URL, p pipeline.Pipeline) ManagementClient { + return ManagementClient{ + url: url, + p: p, } } + +// URL returns a copy of the URL for this client. +func (mc ManagementClient) URL() url.URL { + return mc.url +} + +// Pipeline returns the pipeline for this client. +func (mc ManagementClient) Pipeline() pipeline.Pipeline { + return mc.p +} diff --git a/services/graphrbac/1.6/graphrbac/domains.go b/services/graphrbac/1.6/graphrbac/domains.go index 30d53aa9e3be..bde165790b1f 100644 --- a/services/graphrbac/1.6/graphrbac/domains.go +++ b/services/graphrbac/1.6/graphrbac/domains.go @@ -19,154 +19,127 @@ package graphrbac import ( "context" - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" + "encoding/json" + "github.com/Azure/azure-pipeline-go/pipeline" + "io/ioutil" "net/http" ) // DomainsClient is the the Graph RBAC Management Client type DomainsClient struct { - BaseClient + ManagementClient } // NewDomainsClient creates an instance of the DomainsClient client. -func NewDomainsClient(tenantID string) DomainsClient { - return NewDomainsClientWithBaseURI(DefaultBaseURI, tenantID) -} - -// NewDomainsClientWithBaseURI creates an instance of the DomainsClient client. -func NewDomainsClientWithBaseURI(baseURI string, tenantID string) DomainsClient { - return DomainsClient{NewWithBaseURI(baseURI, tenantID)} +func NewDomainsClient(p pipeline.Pipeline) DomainsClient { + return DomainsClient{NewManagementClient(p)} } // Get gets a specific domain in the current tenant. // // domainName is name of the domain. -func (client DomainsClient) Get(ctx context.Context, domainName string) (result Domain, err error) { - req, err := client.GetPreparer(ctx, domainName) +func (client DomainsClient) Get(ctx context.Context, domainName string) (*Domain, error) { + req, err := client.getPreparer(domainName) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.DomainsClient", "Get", nil, "Failure preparing request") - return + return nil, err } - - resp, err := client.GetSender(req) + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.getResponder}, req) if err != nil { - result.Response = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "graphrbac.DomainsClient", "Get", resp, "Failure sending request") - return + return nil, err } + return resp.(*Domain), err +} - result, err = client.GetResponder(resp) +// getPreparer prepares the Get request. +func (client DomainsClient) getPreparer(domainName string) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/domains/{domainName}" + req, err := pipeline.NewRequest("GET", u, nil) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.DomainsClient", "Get", resp, "Failure responding to request") + return req, pipeline.NewError(err, "failed to create request") } - - return + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + return req, nil } -// GetPreparer prepares the Get request. -func (client DomainsClient) GetPreparer(ctx context.Context, domainName string) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "domainName": autorest.Encode("path", domainName), - "tenantID": autorest.Encode("path", client.TenantID), +// getResponder handles the response to the Get request. +func (client DomainsClient) getResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK) + if resp == nil { + return nil, err } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, + result := &Domain{rawResponse: resp.Response()} + if err != nil { + return result, err } - - preparer := autorest.CreatePreparer( - autorest.AsGet(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/domains/{domainName}", 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 DomainsClient) 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 DomainsClient) GetResponder(resp *http.Response) (result Domain, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result), - autorest.ByClosing()) - result.Response = autorest.Response{Response: resp} - return + defer resp.Response().Body.Close() + b, err := ioutil.ReadAll(resp.Response().Body) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to read response body") + } + if len(b) > 0 { + err = json.Unmarshal(b, result) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to unmarshal response body") + } + } + return result, nil } // List gets a list of domains for the current tenant. // // filter is the filter to apply to the operation. -func (client DomainsClient) List(ctx context.Context, filter string) (result DomainListResult, err error) { - req, err := client.ListPreparer(ctx, filter) +func (client DomainsClient) List(ctx context.Context, filter *string) (*DomainListResult, error) { + req, err := client.listPreparer(filter) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.DomainsClient", "List", nil, "Failure preparing request") - return + return nil, err } - - resp, err := client.ListSender(req) + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.listResponder}, req) if err != nil { - result.Response = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "graphrbac.DomainsClient", "List", resp, "Failure sending request") - return + return nil, err } + return resp.(*DomainListResult), err +} - result, err = client.ListResponder(resp) +// listPreparer prepares the List request. +func (client DomainsClient) listPreparer(filter *string) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/domains" + req, err := pipeline.NewRequest("GET", u, nil) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.DomainsClient", "List", resp, "Failure responding to request") + return req, pipeline.NewError(err, "failed to create request") } - - return + params := req.URL.Query() + if filter != nil { + params.Set("$filter", *filter) + } + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + return req, nil } -// ListPreparer prepares the List request. -func (client DomainsClient) ListPreparer(ctx context.Context, filter string) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "tenantID": autorest.Encode("path", client.TenantID), +// listResponder handles the response to the List request. +func (client DomainsClient) listResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK) + if resp == nil { + return nil, err } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, + result := &DomainListResult{rawResponse: resp.Response()} + if err != nil { + return result, err } - if len(filter) > 0 { - queryParameters["$filter"] = autorest.Encode("query", filter) + defer resp.Response().Body.Close() + b, err := ioutil.ReadAll(resp.Response().Body) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to read response body") } - - preparer := autorest.CreatePreparer( - autorest.AsGet(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/domains", pathParameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// ListSender sends the List request. The method will close the -// http.Response Body if it receives an error. -func (client DomainsClient) ListSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) -} - -// ListResponder handles the response to the List request. The method always -// closes the http.Response Body. -func (client DomainsClient) ListResponder(resp *http.Response) (result DomainListResult, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result), - autorest.ByClosing()) - result.Response = autorest.Response{Response: resp} - return + if len(b) > 0 { + err = json.Unmarshal(b, result) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to unmarshal response body") + } + } + return result, nil } diff --git a/services/graphrbac/1.6/graphrbac/groups.go b/services/graphrbac/1.6/graphrbac/groups.go index 5202df34dbc5..7417da36b51a 100644 --- a/services/graphrbac/1.6/graphrbac/groups.go +++ b/services/graphrbac/1.6/graphrbac/groups.go @@ -18,27 +18,22 @@ package graphrbac // Changes may cause incorrect behavior and will be lost if the code is regenerated. import ( + "bytes" "context" - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/Azure/go-autorest/autorest/to" - "github.com/Azure/go-autorest/autorest/validation" + "encoding/json" + "github.com/Azure/azure-pipeline-go/pipeline" + "io/ioutil" "net/http" ) // GroupsClient is the the Graph RBAC Management Client type GroupsClient struct { - BaseClient + ManagementClient } // NewGroupsClient creates an instance of the GroupsClient client. -func NewGroupsClient(tenantID string) GroupsClient { - return NewGroupsClientWithBaseURI(DefaultBaseURI, tenantID) -} - -// NewGroupsClientWithBaseURI creates an instance of the GroupsClient client. -func NewGroupsClientWithBaseURI(baseURI string, tenantID string) GroupsClient { - return GroupsClient{NewWithBaseURI(baseURI, tenantID)} +func NewGroupsClient(p pipeline.Pipeline) GroupsClient { + return GroupsClient{NewManagementClient(p)} } // AddMember add a member to a group. @@ -46,773 +41,601 @@ func NewGroupsClientWithBaseURI(baseURI string, tenantID string) GroupsClient { // groupObjectID is the object ID of the group to which to add the member. parameters is the URL of the member object, // such as // https://graph.windows.net/0b1f9851-1bf0-433f-aec3-cb9272f093dc/directoryObjects/f260bbc4-c254-447b-94cf-293b5ec434dd. -func (client GroupsClient) AddMember(ctx context.Context, groupObjectID string, parameters GroupAddMemberParameters) (result autorest.Response, err error) { - if err := validation.Validate([]validation.Validation{ - {TargetValue: parameters, - Constraints: []validation.Constraint{{Target: "parameters.URL", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { - return result, validation.NewErrorWithValidationError(err, "graphrbac.GroupsClient", "AddMember") +func (client GroupsClient) AddMember(ctx context.Context, groupObjectID string, parameters GroupAddMemberParameters) (*http.Response, error) { + if err := validate([]validation{ + {targetValue: parameters, + constraints: []constraint{{target: "parameters.URL", name: null, rule: true, chain: nil}}}}); err != nil { + return nil, err } - - req, err := client.AddMemberPreparer(ctx, groupObjectID, parameters) + req, err := client.addMemberPreparer(groupObjectID, parameters) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.GroupsClient", "AddMember", nil, "Failure preparing request") - return + return nil, err } - - resp, err := client.AddMemberSender(req) + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.addMemberResponder}, req) if err != nil { - result.Response = resp - err = autorest.NewErrorWithError(err, "graphrbac.GroupsClient", "AddMember", resp, "Failure sending request") - return + return nil, err } + return resp.Response(), err +} - result, err = client.AddMemberResponder(resp) +// addMemberPreparer prepares the AddMember request. +func (client GroupsClient) addMemberPreparer(groupObjectID string, parameters GroupAddMemberParameters) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/groups/{groupObjectId}/$links/members" + req, err := pipeline.NewRequest("POST", u, nil) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.GroupsClient", "AddMember", resp, "Failure responding to request") + return req, pipeline.NewError(err, "failed to create request") } - - return -} - -// AddMemberPreparer prepares the AddMember request. -func (client GroupsClient) AddMemberPreparer(ctx context.Context, groupObjectID string, parameters GroupAddMemberParameters) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "groupObjectId": autorest.Encode("path", groupObjectID), - "tenantID": autorest.Encode("path", client.TenantID), + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + b, err := json.Marshal(parameters) + if err != nil { + return req, pipeline.NewError(err, "failed to marshal request body") } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, + req.Header.Set("Content-Type", "application/json") + err = req.SetBody(bytes.NewReader(b)) + if err != nil { + return req, pipeline.NewError(err, "failed to set request body") } - - preparer := autorest.CreatePreparer( - autorest.AsJSON(), - autorest.AsPost(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/groups/{groupObjectId}/$links/members", pathParameters), - autorest.WithJSON(parameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// AddMemberSender sends the AddMember request. The method will close the -// http.Response Body if it receives an error. -func (client GroupsClient) AddMemberSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) + return req, nil } -// AddMemberResponder handles the response to the AddMember request. The method always -// closes the http.Response Body. -func (client GroupsClient) AddMemberResponder(resp *http.Response) (result autorest.Response, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), - autorest.ByClosing()) - result.Response = resp - return +// addMemberResponder handles the response to the AddMember request. +func (client GroupsClient) addMemberResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK, http.StatusNoContent) + if resp == nil { + return nil, err + } + return resp, err } // Create create a group in the directory. // // parameters is the parameters for the group to create. -func (client GroupsClient) Create(ctx context.Context, parameters GroupCreateParameters) (result ADGroup, err error) { - if err := validation.Validate([]validation.Validation{ - {TargetValue: parameters, - Constraints: []validation.Constraint{{Target: "parameters.DisplayName", Name: validation.Null, Rule: true, Chain: nil}, - {Target: "parameters.MailEnabled", Name: validation.Null, Rule: true, Chain: nil}, - {Target: "parameters.MailNickname", Name: validation.Null, Rule: true, Chain: nil}, - {Target: "parameters.SecurityEnabled", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { - return result, validation.NewErrorWithValidationError(err, "graphrbac.GroupsClient", "Create") +func (client GroupsClient) Create(ctx context.Context, parameters GroupCreateParameters) (*ADGroup, error) { + if err := validate([]validation{ + {targetValue: parameters, + constraints: []constraint{{target: "parameters.DisplayName", name: null, rule: true, chain: nil}, + {target: "parameters.MailEnabled", name: null, rule: true, chain: nil}, + {target: "parameters.MailNickname", name: null, rule: true, chain: nil}, + {target: "parameters.SecurityEnabled", name: null, rule: true, chain: nil}}}}); err != nil { + return nil, err } - - req, err := client.CreatePreparer(ctx, parameters) + req, err := client.createPreparer(parameters) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.GroupsClient", "Create", nil, "Failure preparing request") - return + return nil, err } - - resp, err := client.CreateSender(req) + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.createResponder}, req) if err != nil { - result.Response = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "graphrbac.GroupsClient", "Create", resp, "Failure sending request") - return + return nil, err } + return resp.(*ADGroup), err +} - result, err = client.CreateResponder(resp) +// createPreparer prepares the Create request. +func (client GroupsClient) createPreparer(parameters GroupCreateParameters) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/groups" + req, err := pipeline.NewRequest("POST", u, nil) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.GroupsClient", "Create", resp, "Failure responding to request") + return req, pipeline.NewError(err, "failed to create request") } - - return -} - -// CreatePreparer prepares the Create request. -func (client GroupsClient) CreatePreparer(ctx context.Context, parameters GroupCreateParameters) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "tenantID": autorest.Encode("path", client.TenantID), + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + b, err := json.Marshal(parameters) + if err != nil { + return req, pipeline.NewError(err, "failed to marshal request body") } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, + req.Header.Set("Content-Type", "application/json") + err = req.SetBody(bytes.NewReader(b)) + if err != nil { + return req, pipeline.NewError(err, "failed to set request body") } - - preparer := autorest.CreatePreparer( - autorest.AsJSON(), - autorest.AsPost(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/groups", pathParameters), - autorest.WithJSON(parameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) + return req, nil } -// CreateSender sends the Create request. The method will close the -// http.Response Body if it receives an error. -func (client GroupsClient) CreateSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) -} - -// CreateResponder handles the response to the Create request. The method always -// closes the http.Response Body. -func (client GroupsClient) CreateResponder(resp *http.Response) (result ADGroup, 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 +// createResponder handles the response to the Create request. +func (client GroupsClient) createResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK, http.StatusCreated) + if resp == nil { + return nil, err + } + result := &ADGroup{rawResponse: resp.Response()} + if err != nil { + return result, err + } + defer resp.Response().Body.Close() + b, err := ioutil.ReadAll(resp.Response().Body) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to read response body") + } + if len(b) > 0 { + err = json.Unmarshal(b, result) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to unmarshal response body") + } + } + return result, nil } // Delete delete a group from the directory. // // objectID is the object ID of the group to delete. -func (client GroupsClient) Delete(ctx context.Context, objectID string) (result autorest.Response, err error) { - req, err := client.DeletePreparer(ctx, objectID) +func (client GroupsClient) Delete(ctx context.Context, objectID string) (*http.Response, error) { + req, err := client.deletePreparer(objectID) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.GroupsClient", "Delete", nil, "Failure preparing request") - return + return nil, err } - - resp, err := client.DeleteSender(req) + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.deleteResponder}, req) if err != nil { - result.Response = resp - err = autorest.NewErrorWithError(err, "graphrbac.GroupsClient", "Delete", resp, "Failure sending request") - return + return nil, err } + return resp.Response(), err +} - result, err = client.DeleteResponder(resp) +// deletePreparer prepares the Delete request. +func (client GroupsClient) deletePreparer(objectID string) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/groups/{objectId}" + req, err := pipeline.NewRequest("DELETE", u, nil) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.GroupsClient", "Delete", resp, "Failure responding to request") + return req, pipeline.NewError(err, "failed to create request") } - - return + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + return req, nil } -// DeletePreparer prepares the Delete request. -func (client GroupsClient) DeletePreparer(ctx context.Context, objectID string) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "objectId": autorest.Encode("path", objectID), - "tenantID": autorest.Encode("path", client.TenantID), - } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, +// deleteResponder handles the response to the Delete request. +func (client GroupsClient) deleteResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK, http.StatusNoContent) + if resp == nil { + return nil, err } - - preparer := autorest.CreatePreparer( - autorest.AsDelete(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/groups/{objectId}", pathParameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// DeleteSender sends the Delete request. The method will close the -// http.Response Body if it receives an error. -func (client GroupsClient) DeleteSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) -} - -// DeleteResponder handles the response to the Delete request. The method always -// closes the http.Response Body. -func (client GroupsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), - autorest.ByClosing()) - result.Response = resp - return + return resp, err } // Get gets group information from the directory. // // objectID is the object ID of the user for which to get group information. -func (client GroupsClient) Get(ctx context.Context, objectID string) (result ADGroup, err error) { - req, err := client.GetPreparer(ctx, objectID) +func (client GroupsClient) Get(ctx context.Context, objectID string) (*ADGroup, error) { + req, err := client.getPreparer(objectID) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.GroupsClient", "Get", nil, "Failure preparing request") - return + return nil, err } - - resp, err := client.GetSender(req) + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.getResponder}, req) if err != nil { - result.Response = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "graphrbac.GroupsClient", "Get", resp, "Failure sending request") - return + return nil, err } + return resp.(*ADGroup), err +} - result, err = client.GetResponder(resp) +// getPreparer prepares the Get request. +func (client GroupsClient) getPreparer(objectID string) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/groups/{objectId}" + req, err := pipeline.NewRequest("GET", u, nil) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.GroupsClient", "Get", resp, "Failure responding to request") + return req, pipeline.NewError(err, "failed to create request") } - - return + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + return req, nil } -// GetPreparer prepares the Get request. -func (client GroupsClient) GetPreparer(ctx context.Context, objectID string) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "objectId": autorest.Encode("path", objectID), - "tenantID": autorest.Encode("path", client.TenantID), +// getResponder handles the response to the Get request. +func (client GroupsClient) getResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK) + if resp == nil { + return nil, err } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, + result := &ADGroup{rawResponse: resp.Response()} + if err != nil { + return result, err } - - preparer := autorest.CreatePreparer( - autorest.AsGet(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/groups/{objectId}", 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 GroupsClient) 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 GroupsClient) GetResponder(resp *http.Response) (result ADGroup, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result), - autorest.ByClosing()) - result.Response = autorest.Response{Response: resp} - return + defer resp.Response().Body.Close() + b, err := ioutil.ReadAll(resp.Response().Body) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to read response body") + } + if len(b) > 0 { + err = json.Unmarshal(b, result) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to unmarshal response body") + } + } + return result, nil } // GetGroupMembers gets the members of a group. // // objectID is the object ID of the group whose members should be retrieved. -func (client GroupsClient) GetGroupMembers(ctx context.Context, objectID string) (result GetObjectsResultPage, err error) { - result.fn = func(lastResult GetObjectsResult) (GetObjectsResult, error) { - if lastResult.OdataNextLink == nil || len(to.String(lastResult.OdataNextLink)) < 1 { - return GetObjectsResult{}, nil - } - return client.GetGroupMembersNext(ctx, *lastResult.OdataNextLink) - } - req, err := client.GetGroupMembersPreparer(ctx, objectID) +func (client GroupsClient) GetGroupMembers(ctx context.Context, objectID string) (*GetObjectsResult, error) { + req, err := client.getGroupMembersPreparer(objectID) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.GroupsClient", "GetGroupMembers", nil, "Failure preparing request") - return + return nil, err } - - resp, err := client.GetGroupMembersSender(req) + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.getGroupMembersResponder}, req) if err != nil { - result.gor.Response = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "graphrbac.GroupsClient", "GetGroupMembers", resp, "Failure sending request") - return + return nil, err } + return resp.(*GetObjectsResult), err +} - result.gor, err = client.GetGroupMembersResponder(resp) +// getGroupMembersPreparer prepares the GetGroupMembers request. +func (client GroupsClient) getGroupMembersPreparer(objectID string) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/groups/{objectId}/members" + req, err := pipeline.NewRequest("GET", u, nil) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.GroupsClient", "GetGroupMembers", resp, "Failure responding to request") + return req, pipeline.NewError(err, "failed to create request") } - - return + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + return req, nil } -// GetGroupMembersPreparer prepares the GetGroupMembers request. -func (client GroupsClient) GetGroupMembersPreparer(ctx context.Context, objectID string) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "objectId": autorest.Encode("path", objectID), - "tenantID": autorest.Encode("path", client.TenantID), +// getGroupMembersResponder handles the response to the GetGroupMembers request. +func (client GroupsClient) getGroupMembersResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK) + if resp == nil { + return nil, err } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, + result := &GetObjectsResult{rawResponse: resp.Response()} + if err != nil { + return result, err } - - preparer := autorest.CreatePreparer( - autorest.AsGet(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/groups/{objectId}/members", pathParameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// GetGroupMembersSender sends the GetGroupMembers request. The method will close the -// http.Response Body if it receives an error. -func (client GroupsClient) GetGroupMembersSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) -} - -// GetGroupMembersResponder handles the response to the GetGroupMembers request. The method always -// closes the http.Response Body. -func (client GroupsClient) GetGroupMembersResponder(resp *http.Response) (result GetObjectsResult, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result), - autorest.ByClosing()) - result.Response = autorest.Response{Response: resp} - return -} - -// GetGroupMembersComplete enumerates all values, automatically crossing page boundaries as required. -func (client GroupsClient) GetGroupMembersComplete(ctx context.Context, objectID string) (result GetObjectsResultIterator, err error) { - result.page, err = client.GetGroupMembers(ctx, objectID) - return + defer resp.Response().Body.Close() + b, err := ioutil.ReadAll(resp.Response().Body) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to read response body") + } + if len(b) > 0 { + err = json.Unmarshal(b, result) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to unmarshal response body") + } + } + return result, nil } // GetGroupMembersNext gets the members of a group. // // nextLink is next link for the list operation. -func (client GroupsClient) GetGroupMembersNext(ctx context.Context, nextLink string) (result GetObjectsResult, err error) { - req, err := client.GetGroupMembersNextPreparer(ctx, nextLink) +func (client GroupsClient) GetGroupMembersNext(ctx context.Context, nextLink string) (*GetObjectsResult, error) { + req, err := client.getGroupMembersNextPreparer(nextLink) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.GroupsClient", "GetGroupMembersNext", nil, "Failure preparing request") - return + return nil, err } - - resp, err := client.GetGroupMembersNextSender(req) + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.getGroupMembersNextResponder}, req) if err != nil { - result.Response = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "graphrbac.GroupsClient", "GetGroupMembersNext", resp, "Failure sending request") - return + return nil, err } + return resp.(*GetObjectsResult), err +} - result, err = client.GetGroupMembersNextResponder(resp) +// getGroupMembersNextPreparer prepares the GetGroupMembersNext request. +func (client GroupsClient) getGroupMembersNextPreparer(nextLink string) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/{nextLink}" + req, err := pipeline.NewRequest("GET", u, nil) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.GroupsClient", "GetGroupMembersNext", resp, "Failure responding to request") + return req, pipeline.NewError(err, "failed to create request") } - - return + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + return req, nil } -// GetGroupMembersNextPreparer prepares the GetGroupMembersNext request. -func (client GroupsClient) GetGroupMembersNextPreparer(ctx context.Context, nextLink string) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "nextLink": nextLink, - "tenantID": autorest.Encode("path", client.TenantID), +// getGroupMembersNextResponder handles the response to the GetGroupMembersNext request. +func (client GroupsClient) getGroupMembersNextResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK) + if resp == nil { + return nil, err } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, + result := &GetObjectsResult{rawResponse: resp.Response()} + if err != nil { + return result, err } - - preparer := autorest.CreatePreparer( - autorest.AsGet(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/{nextLink}", pathParameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// GetGroupMembersNextSender sends the GetGroupMembersNext request. The method will close the -// http.Response Body if it receives an error. -func (client GroupsClient) GetGroupMembersNextSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) -} - -// GetGroupMembersNextResponder handles the response to the GetGroupMembersNext request. The method always -// closes the http.Response Body. -func (client GroupsClient) GetGroupMembersNextResponder(resp *http.Response) (result GetObjectsResult, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result), - autorest.ByClosing()) - result.Response = autorest.Response{Response: resp} - return + defer resp.Response().Body.Close() + b, err := ioutil.ReadAll(resp.Response().Body) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to read response body") + } + if len(b) > 0 { + err = json.Unmarshal(b, result) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to unmarshal response body") + } + } + return result, nil } // GetMemberGroups gets a collection of object IDs of groups of which the specified group is a member. // // objectID is the object ID of the group for which to get group membership. parameters is group filtering parameters. -func (client GroupsClient) GetMemberGroups(ctx context.Context, objectID string, parameters GroupGetMemberGroupsParameters) (result GroupGetMemberGroupsResult, err error) { - if err := validation.Validate([]validation.Validation{ - {TargetValue: parameters, - Constraints: []validation.Constraint{{Target: "parameters.SecurityEnabledOnly", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { - return result, validation.NewErrorWithValidationError(err, "graphrbac.GroupsClient", "GetMemberGroups") +func (client GroupsClient) GetMemberGroups(ctx context.Context, objectID string, parameters GroupGetMemberGroupsParameters) (*GroupGetMemberGroupsResult, error) { + if err := validate([]validation{ + {targetValue: parameters, + constraints: []constraint{{target: "parameters.SecurityEnabledOnly", name: null, rule: true, chain: nil}}}}); err != nil { + return nil, err } - - req, err := client.GetMemberGroupsPreparer(ctx, objectID, parameters) + req, err := client.getMemberGroupsPreparer(objectID, parameters) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.GroupsClient", "GetMemberGroups", nil, "Failure preparing request") - return + return nil, err } - - resp, err := client.GetMemberGroupsSender(req) + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.getMemberGroupsResponder}, req) if err != nil { - result.Response = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "graphrbac.GroupsClient", "GetMemberGroups", resp, "Failure sending request") - return + return nil, err } + return resp.(*GroupGetMemberGroupsResult), err +} - result, err = client.GetMemberGroupsResponder(resp) +// getMemberGroupsPreparer prepares the GetMemberGroups request. +func (client GroupsClient) getMemberGroupsPreparer(objectID string, parameters GroupGetMemberGroupsParameters) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/groups/{objectId}/getMemberGroups" + req, err := pipeline.NewRequest("POST", u, nil) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.GroupsClient", "GetMemberGroups", resp, "Failure responding to request") + return req, pipeline.NewError(err, "failed to create request") } - - return -} - -// GetMemberGroupsPreparer prepares the GetMemberGroups request. -func (client GroupsClient) GetMemberGroupsPreparer(ctx context.Context, objectID string, parameters GroupGetMemberGroupsParameters) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "objectId": autorest.Encode("path", objectID), - "tenantID": autorest.Encode("path", client.TenantID), + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + b, err := json.Marshal(parameters) + if err != nil { + return req, pipeline.NewError(err, "failed to marshal request body") } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, + req.Header.Set("Content-Type", "application/json") + err = req.SetBody(bytes.NewReader(b)) + if err != nil { + return req, pipeline.NewError(err, "failed to set request body") } - - preparer := autorest.CreatePreparer( - autorest.AsJSON(), - autorest.AsPost(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/groups/{objectId}/getMemberGroups", pathParameters), - autorest.WithJSON(parameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// GetMemberGroupsSender sends the GetMemberGroups request. The method will close the -// http.Response Body if it receives an error. -func (client GroupsClient) GetMemberGroupsSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) + return req, nil } -// GetMemberGroupsResponder handles the response to the GetMemberGroups request. The method always -// closes the http.Response Body. -func (client GroupsClient) GetMemberGroupsResponder(resp *http.Response) (result GroupGetMemberGroupsResult, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result), - autorest.ByClosing()) - result.Response = autorest.Response{Response: resp} - return +// getMemberGroupsResponder handles the response to the GetMemberGroups request. +func (client GroupsClient) getMemberGroupsResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK) + if resp == nil { + return nil, err + } + result := &GroupGetMemberGroupsResult{rawResponse: resp.Response()} + if err != nil { + return result, err + } + defer resp.Response().Body.Close() + b, err := ioutil.ReadAll(resp.Response().Body) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to read response body") + } + if len(b) > 0 { + err = json.Unmarshal(b, result) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to unmarshal response body") + } + } + return result, nil } // IsMemberOf checks whether the specified user, group, contact, or service principal is a direct or transitive member // of the specified group. // // parameters is the check group membership parameters. -func (client GroupsClient) IsMemberOf(ctx context.Context, parameters CheckGroupMembershipParameters) (result CheckGroupMembershipResult, err error) { - if err := validation.Validate([]validation.Validation{ - {TargetValue: parameters, - Constraints: []validation.Constraint{{Target: "parameters.GroupID", Name: validation.Null, Rule: true, Chain: nil}, - {Target: "parameters.MemberID", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { - return result, validation.NewErrorWithValidationError(err, "graphrbac.GroupsClient", "IsMemberOf") +func (client GroupsClient) IsMemberOf(ctx context.Context, parameters CheckGroupMembershipParameters) (*CheckGroupMembershipResult, error) { + if err := validate([]validation{ + {targetValue: parameters, + constraints: []constraint{{target: "parameters.GroupID", name: null, rule: true, chain: nil}, + {target: "parameters.MemberID", name: null, rule: true, chain: nil}}}}); err != nil { + return nil, err } - - req, err := client.IsMemberOfPreparer(ctx, parameters) + req, err := client.isMemberOfPreparer(parameters) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.GroupsClient", "IsMemberOf", nil, "Failure preparing request") - return + return nil, err } - - resp, err := client.IsMemberOfSender(req) + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.isMemberOfResponder}, req) if err != nil { - result.Response = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "graphrbac.GroupsClient", "IsMemberOf", resp, "Failure sending request") - return + return nil, err } + return resp.(*CheckGroupMembershipResult), err +} - result, err = client.IsMemberOfResponder(resp) +// isMemberOfPreparer prepares the IsMemberOf request. +func (client GroupsClient) isMemberOfPreparer(parameters CheckGroupMembershipParameters) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/isMemberOf" + req, err := pipeline.NewRequest("POST", u, nil) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.GroupsClient", "IsMemberOf", resp, "Failure responding to request") + return req, pipeline.NewError(err, "failed to create request") } - - return -} - -// IsMemberOfPreparer prepares the IsMemberOf request. -func (client GroupsClient) IsMemberOfPreparer(ctx context.Context, parameters CheckGroupMembershipParameters) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "tenantID": autorest.Encode("path", client.TenantID), + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + b, err := json.Marshal(parameters) + if err != nil { + return req, pipeline.NewError(err, "failed to marshal request body") } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, + req.Header.Set("Content-Type", "application/json") + err = req.SetBody(bytes.NewReader(b)) + if err != nil { + return req, pipeline.NewError(err, "failed to set request body") } - - preparer := autorest.CreatePreparer( - autorest.AsJSON(), - autorest.AsPost(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/isMemberOf", pathParameters), - autorest.WithJSON(parameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// IsMemberOfSender sends the IsMemberOf request. The method will close the -// http.Response Body if it receives an error. -func (client GroupsClient) IsMemberOfSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) + return req, nil } -// IsMemberOfResponder handles the response to the IsMemberOf request. The method always -// closes the http.Response Body. -func (client GroupsClient) IsMemberOfResponder(resp *http.Response) (result CheckGroupMembershipResult, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result), - autorest.ByClosing()) - result.Response = autorest.Response{Response: resp} - return +// isMemberOfResponder handles the response to the IsMemberOf request. +func (client GroupsClient) isMemberOfResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK) + if resp == nil { + return nil, err + } + result := &CheckGroupMembershipResult{rawResponse: resp.Response()} + if err != nil { + return result, err + } + defer resp.Response().Body.Close() + b, err := ioutil.ReadAll(resp.Response().Body) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to read response body") + } + if len(b) > 0 { + err = json.Unmarshal(b, result) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to unmarshal response body") + } + } + return result, nil } // List gets list of groups for the current tenant. // // filter is the filter to apply to the operation. -func (client GroupsClient) List(ctx context.Context, filter string) (result GroupListResultPage, err error) { - result.fn = func(lastResult GroupListResult) (GroupListResult, error) { - if lastResult.OdataNextLink == nil || len(to.String(lastResult.OdataNextLink)) < 1 { - return GroupListResult{}, nil - } - return client.ListNext(ctx, *lastResult.OdataNextLink) - } - req, err := client.ListPreparer(ctx, filter) +func (client GroupsClient) List(ctx context.Context, filter *string) (*GroupListResult, error) { + req, err := client.listPreparer(filter) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.GroupsClient", "List", nil, "Failure preparing request") - return + return nil, err } - - resp, err := client.ListSender(req) + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.listResponder}, req) if err != nil { - result.glr.Response = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "graphrbac.GroupsClient", "List", resp, "Failure sending request") - return + return nil, err } + return resp.(*GroupListResult), err +} - result.glr, err = client.ListResponder(resp) +// listPreparer prepares the List request. +func (client GroupsClient) listPreparer(filter *string) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/groups" + req, err := pipeline.NewRequest("GET", u, nil) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.GroupsClient", "List", resp, "Failure responding to request") + return req, pipeline.NewError(err, "failed to create request") } - - return + params := req.URL.Query() + if filter != nil { + params.Set("$filter", *filter) + } + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + return req, nil } -// ListPreparer prepares the List request. -func (client GroupsClient) ListPreparer(ctx context.Context, filter string) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "tenantID": autorest.Encode("path", client.TenantID), +// listResponder handles the response to the List request. +func (client GroupsClient) listResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK) + if resp == nil { + return nil, err } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, + result := &GroupListResult{rawResponse: resp.Response()} + if err != nil { + return result, err } - if len(filter) > 0 { - queryParameters["$filter"] = autorest.Encode("query", filter) + defer resp.Response().Body.Close() + b, err := ioutil.ReadAll(resp.Response().Body) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to read response body") } - - preparer := autorest.CreatePreparer( - autorest.AsGet(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/groups", pathParameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// ListSender sends the List request. The method will close the -// http.Response Body if it receives an error. -func (client GroupsClient) ListSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) -} - -// ListResponder handles the response to the List request. The method always -// closes the http.Response Body. -func (client GroupsClient) ListResponder(resp *http.Response) (result GroupListResult, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result), - autorest.ByClosing()) - result.Response = autorest.Response{Response: resp} - return -} - -// ListComplete enumerates all values, automatically crossing page boundaries as required. -func (client GroupsClient) ListComplete(ctx context.Context, filter string) (result GroupListResultIterator, err error) { - result.page, err = client.List(ctx, filter) - return + if len(b) > 0 { + err = json.Unmarshal(b, result) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to unmarshal response body") + } + } + return result, nil } // ListNext gets a list of groups for the current tenant. // // nextLink is next link for the list operation. -func (client GroupsClient) ListNext(ctx context.Context, nextLink string) (result GroupListResult, err error) { - req, err := client.ListNextPreparer(ctx, nextLink) +func (client GroupsClient) ListNext(ctx context.Context, nextLink string) (*GroupListResult, error) { + req, err := client.listNextPreparer(nextLink) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.GroupsClient", "ListNext", nil, "Failure preparing request") - return + return nil, err } - - resp, err := client.ListNextSender(req) + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.listNextResponder}, req) if err != nil { - result.Response = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "graphrbac.GroupsClient", "ListNext", resp, "Failure sending request") - return + return nil, err } + return resp.(*GroupListResult), err +} - result, err = client.ListNextResponder(resp) +// listNextPreparer prepares the ListNext request. +func (client GroupsClient) listNextPreparer(nextLink string) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/{nextLink}" + req, err := pipeline.NewRequest("GET", u, nil) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.GroupsClient", "ListNext", resp, "Failure responding to request") + return req, pipeline.NewError(err, "failed to create request") } - - return + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + return req, nil } -// ListNextPreparer prepares the ListNext request. -func (client GroupsClient) ListNextPreparer(ctx context.Context, nextLink string) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "nextLink": nextLink, - "tenantID": autorest.Encode("path", client.TenantID), +// listNextResponder handles the response to the ListNext request. +func (client GroupsClient) listNextResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK) + if resp == nil { + return nil, err } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, + result := &GroupListResult{rawResponse: resp.Response()} + if err != nil { + return result, err } - - preparer := autorest.CreatePreparer( - autorest.AsGet(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/{nextLink}", pathParameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// ListNextSender sends the ListNext request. The method will close the -// http.Response Body if it receives an error. -func (client GroupsClient) ListNextSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) -} - -// ListNextResponder handles the response to the ListNext request. The method always -// closes the http.Response Body. -func (client GroupsClient) ListNextResponder(resp *http.Response) (result GroupListResult, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result), - autorest.ByClosing()) - result.Response = autorest.Response{Response: resp} - return + defer resp.Response().Body.Close() + b, err := ioutil.ReadAll(resp.Response().Body) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to read response body") + } + if len(b) > 0 { + err = json.Unmarshal(b, result) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to unmarshal response body") + } + } + return result, nil } // RemoveMember remove a member from a group. // // groupObjectID is the object ID of the group from which to remove the member. memberObjectID is member object id -func (client GroupsClient) RemoveMember(ctx context.Context, groupObjectID string, memberObjectID string) (result autorest.Response, err error) { - req, err := client.RemoveMemberPreparer(ctx, groupObjectID, memberObjectID) +func (client GroupsClient) RemoveMember(ctx context.Context, groupObjectID string, memberObjectID string) (*http.Response, error) { + req, err := client.removeMemberPreparer(groupObjectID, memberObjectID) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.GroupsClient", "RemoveMember", nil, "Failure preparing request") - return + return nil, err } - - resp, err := client.RemoveMemberSender(req) + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.removeMemberResponder}, req) if err != nil { - result.Response = resp - err = autorest.NewErrorWithError(err, "graphrbac.GroupsClient", "RemoveMember", resp, "Failure sending request") - return + return nil, err } + return resp.Response(), err +} - result, err = client.RemoveMemberResponder(resp) +// removeMemberPreparer prepares the RemoveMember request. +func (client GroupsClient) removeMemberPreparer(groupObjectID string, memberObjectID string) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/groups/{groupObjectId}/$links/members/{memberObjectId}" + req, err := pipeline.NewRequest("DELETE", u, nil) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.GroupsClient", "RemoveMember", resp, "Failure responding to request") + return req, pipeline.NewError(err, "failed to create request") } - - return + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + return req, nil } -// RemoveMemberPreparer prepares the RemoveMember request. -func (client GroupsClient) RemoveMemberPreparer(ctx context.Context, groupObjectID string, memberObjectID string) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "groupObjectId": autorest.Encode("path", groupObjectID), - "memberObjectId": autorest.Encode("path", memberObjectID), - "tenantID": autorest.Encode("path", client.TenantID), - } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, +// removeMemberResponder handles the response to the RemoveMember request. +func (client GroupsClient) removeMemberResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK, http.StatusNoContent) + if resp == nil { + return nil, err } - - preparer := autorest.CreatePreparer( - autorest.AsDelete(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/groups/{groupObjectId}/$links/members/{memberObjectId}", pathParameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// RemoveMemberSender sends the RemoveMember request. The method will close the -// http.Response Body if it receives an error. -func (client GroupsClient) RemoveMemberSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) -} - -// RemoveMemberResponder handles the response to the RemoveMember request. The method always -// closes the http.Response Body. -func (client GroupsClient) RemoveMemberResponder(resp *http.Response) (result autorest.Response, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), - autorest.ByClosing()) - result.Response = resp - return + return resp, err } diff --git a/services/graphrbac/1.6/graphrbac/marshalling.go b/services/graphrbac/1.6/graphrbac/marshalling.go new file mode 100644 index 000000000000..75811efb5d7b --- /dev/null +++ b/services/graphrbac/1.6/graphrbac/marshalling.go @@ -0,0 +1,147 @@ +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 ( + "encoding/xml" + "reflect" + "time" + "unsafe" +) + +const ( + rfc3339Format = "2006-01-02T15:04:05.0000000Z07:00" +) + +// used to convert times from UTC to GMT before sending across the wire +var gmt = time.FixedZone("GMT", 0) + +// internal type used for marshalling time in RFC1123 format +type timeRFC1123 struct { + time.Time +} + +// MarshalText implements the encoding.TextMarshaler interface for timeRFC1123. +func (t timeRFC1123) MarshalText() ([]byte, error) { + return []byte(t.Format(time.RFC1123)), nil +} + +// UnmarshalText implements the encoding.TextUnmarshaler interface for timeRFC1123. +func (t *timeRFC1123) UnmarshalText(data []byte) (err error) { + t.Time, err = time.Parse(time.RFC1123, string(data)) + return +} + +// internal type used for marshalling time in RFC3339 format +type timeRFC3339 struct { + time.Time +} + +// MarshalText implements the encoding.TextMarshaler interface for timeRFC3339. +func (t timeRFC3339) MarshalText() ([]byte, error) { + return []byte(t.Format(rfc3339Format)), nil +} + +// UnmarshalText implements the encoding.TextUnmarshaler interface for timeRFC3339. +func (t *timeRFC3339) UnmarshalText(data []byte) (err error) { + t.Time, err = time.Parse(rfc3339Format, string(data)) + return +} + +// internal type used for marshalling +type directoryObject struct { + AdditionalProperties map[string]map[string]interface{} `json:",omitempty"` + ObjectID *string `json:"objectId,omitempty"` + DeletionTimestamp *timeRFC3339 `json:"deletionTimestamp,omitempty"` + ObjectType ObjectType `json:"objectType,omitempty"` +} + +// MarshalXML implements the xml.Marshaler interface for DirectoryObject. +func (do DirectoryObject) MarshalXML(e *xml.Encoder, start xml.StartElement) error { + if reflect.TypeOf((*DirectoryObject)(nil)).Elem().Size() != reflect.TypeOf((*directoryObject)(nil)).Elem().Size() { + panic("size mismatch between DirectoryObject and directoryObject") + } + do2 := (*directoryObject)(unsafe.Pointer(&do)) + return e.EncodeElement(*do2, start) +} + +// UnmarshalXML implements the xml.Unmarshaler interface for DirectoryObject. +func (do *DirectoryObject) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { + if reflect.TypeOf((*DirectoryObject)(nil)).Elem().Size() != reflect.TypeOf((*directoryObject)(nil)).Elem().Size() { + panic("size mismatch between DirectoryObject and directoryObject") + } + do2 := (*directoryObject)(unsafe.Pointer(do)) + return d.DecodeElement(do2, &start) +} + +// internal type used for marshalling +type keyCredential struct { + AdditionalProperties map[string]map[string]interface{} `json:",omitempty"` + StartDate *timeRFC3339 `json:"startDate,omitempty"` + EndDate *timeRFC3339 `json:"endDate,omitempty"` + Value *string `json:"value,omitempty"` + KeyID *string `json:"keyId,omitempty"` + Usage *string `json:"usage,omitempty"` + Type *string `json:"type,omitempty"` + CustomKeyIdentifier []byte `json:"customKeyIdentifier,omitempty"` +} + +// MarshalXML implements the xml.Marshaler interface for KeyCredential. +func (kc KeyCredential) MarshalXML(e *xml.Encoder, start xml.StartElement) error { + if reflect.TypeOf((*KeyCredential)(nil)).Elem().Size() != reflect.TypeOf((*keyCredential)(nil)).Elem().Size() { + panic("size mismatch between KeyCredential and keyCredential") + } + kc2 := (*keyCredential)(unsafe.Pointer(&kc)) + return e.EncodeElement(*kc2, start) +} + +// UnmarshalXML implements the xml.Unmarshaler interface for KeyCredential. +func (kc *KeyCredential) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { + if reflect.TypeOf((*KeyCredential)(nil)).Elem().Size() != reflect.TypeOf((*keyCredential)(nil)).Elem().Size() { + panic("size mismatch between KeyCredential and keyCredential") + } + kc2 := (*keyCredential)(unsafe.Pointer(kc)) + return d.DecodeElement(kc2, &start) +} + +// internal type used for marshalling +type passwordCredential struct { + AdditionalProperties map[string]map[string]interface{} `json:",omitempty"` + StartDate *timeRFC3339 `json:"startDate,omitempty"` + EndDate *timeRFC3339 `json:"endDate,omitempty"` + KeyID *string `json:"keyId,omitempty"` + Value *string `json:"value,omitempty"` +} + +// MarshalXML implements the xml.Marshaler interface for PasswordCredential. +func (pc PasswordCredential) MarshalXML(e *xml.Encoder, start xml.StartElement) error { + if reflect.TypeOf((*PasswordCredential)(nil)).Elem().Size() != reflect.TypeOf((*passwordCredential)(nil)).Elem().Size() { + panic("size mismatch between PasswordCredential and passwordCredential") + } + pc2 := (*passwordCredential)(unsafe.Pointer(&pc)) + return e.EncodeElement(*pc2, start) +} + +// UnmarshalXML implements the xml.Unmarshaler interface for PasswordCredential. +func (pc *PasswordCredential) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { + if reflect.TypeOf((*PasswordCredential)(nil)).Elem().Size() != reflect.TypeOf((*passwordCredential)(nil)).Elem().Size() { + panic("size mismatch between PasswordCredential and passwordCredential") + } + pc2 := (*passwordCredential)(unsafe.Pointer(pc)) + return d.DecodeElement(pc2, &start) +} diff --git a/services/graphrbac/1.6/graphrbac/models.go b/services/graphrbac/1.6/graphrbac/models.go index 1efb689e1842..452421b0d8be 100644 --- a/services/graphrbac/1.6/graphrbac/models.go +++ b/services/graphrbac/1.6/graphrbac/models.go @@ -19,41 +19,63 @@ package graphrbac import ( "encoding/json" - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/date" + "errors" + "net/http" + "time" ) +// Marker represents an opaque value used in paged responses. +type Marker struct { + val *string +} + +// NotDone returns true if the list enumeration should be started or is not yet complete. Specifically, NotDone returns true +// for a just-initialized (zero value) Marker indicating that you should make an initial request to get a result portion from +// the service. NotDone also returns true whenever the service returns an interim result portion. NotDone returns false only +// after the service has returned the final result portion. +func (m Marker) NotDone() bool { + return m.val == nil || *m.val != "" +} + +// UnmarshalXML implements the xml.Unmarshaler interface for Marker. +func (m *Marker) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { + var out string + err := d.DecodeElement(&out, &start) + m.val = &out + return err +} + // ObjectType enumerates the values for object type. type ObjectType string const ( - // ObjectTypeApplication ... - ObjectTypeApplication ObjectType = "Application" - // ObjectTypeDirectoryObject ... - ObjectTypeDirectoryObject ObjectType = "DirectoryObject" - // ObjectTypeGroup ... - ObjectTypeGroup ObjectType = "Group" - // ObjectTypeServicePrincipal ... - ObjectTypeServicePrincipal ObjectType = "ServicePrincipal" - // ObjectTypeUser ... - ObjectTypeUser ObjectType = "User" + // ObjectObjectTypeApplication ... + ObjectObjectTypeApplication ObjectType = "Application" + // ObjectObjectTypeGroup ... + ObjectObjectTypeGroup ObjectType = "Group" + // ObjectObjectTypeServicePrincipal ... + ObjectObjectTypeServicePrincipal ObjectType = "ServicePrincipal" + // ObjectObjectTypeUser ... + ObjectObjectTypeUser ObjectType = "User" ) // UserType enumerates the values for user type. type UserType string const ( - // Guest ... - Guest UserType = "Guest" - // Member ... - Member UserType = "Member" + // UserGuest ... + UserGuest UserType = "Guest" + // UserMember ... + UserMember UserType = "Member" + // UserNone represents an empty UserType. + UserNone UserType = "" ) -// AADObject the properties of an Active Directory object. +// AADObject - The properties of an Active Directory object. type AADObject struct { - autorest.Response `json:"-"` + rawResponse *http.Response // AdditionalProperties - Unmatched properties from the message are deserialized this collection - AdditionalProperties *map[string]*map[string]interface{} `json:",omitempty"` + AdditionalProperties map[string]map[string]interface{} `json:",omitempty"` // ObjectID - The ID of the object. ObjectID *string `json:"objectId,omitempty"` // ObjectType - The type of AAD object. @@ -73,7 +95,7 @@ type AADObject struct { // SignInName - The sign-in name of the object. SignInName *string `json:"signInName,omitempty"` // ServicePrincipalNames - A collection of service principal names associated with the object. - ServicePrincipalNames *[]string `json:"servicePrincipalNames,omitempty"` + ServicePrincipalNames []string `json:"servicePrincipalNames,omitempty"` // UserType - The user type of the object. UserType *string `json:"userType,omitempty"` // UsageLocation - A two letter country code (ISO standard 3166). Required for users that will be assigned licenses due to legal requirement to check for availability of services in countries. Examples include: "US", "JP", and "GB". @@ -81,27 +103,42 @@ type AADObject struct { // AppID - The application ID. AppID *string `json:"appId,omitempty"` // AppPermissions - The application permissions. - AppPermissions *[]string `json:"appPermissions,omitempty"` + AppPermissions []string `json:"appPermissions,omitempty"` // AvailableToOtherTenants - Whether the application is be available to other tenants. AvailableToOtherTenants *bool `json:"availableToOtherTenants,omitempty"` // IdentifierUris - A collection of URIs for the application. - IdentifierUris *[]string `json:"identifierUris,omitempty"` + IdentifierUris []string `json:"identifierUris,omitempty"` // ReplyUrls - A collection of reply URLs for the application. - ReplyUrls *[]string `json:"replyUrls,omitempty"` + ReplyUrls []string `json:"replyUrls,omitempty"` // Homepage - The home page of the application. Homepage *string `json:"homepage,omitempty"` } -// ADGroup active Directory group information. +// Response returns the raw HTTP response object. +func (ao AADObject) Response() *http.Response { + return ao.rawResponse +} + +// StatusCode returns the HTTP status code of the response, e.g. 200. +func (ao AADObject) StatusCode() int { + return ao.rawResponse.StatusCode +} + +// Status returns the HTTP status message of the response, e.g. "200 OK". +func (ao AADObject) Status() string { + return ao.rawResponse.Status +} + +// ADGroup - Active Directory group information. type ADGroup struct { - autorest.Response `json:"-"` + rawResponse *http.Response // AdditionalProperties - Unmatched properties from the message are deserialized this collection - AdditionalProperties *map[string]*map[string]interface{} `json:",omitempty"` + AdditionalProperties map[string]map[string]interface{} `json:",omitempty"` // ObjectID - The object ID. ObjectID *string `json:"objectId,omitempty"` // DeletionTimestamp - The time at which the directory object was deleted. - DeletionTimestamp *date.Time `json:"deletionTimestamp,omitempty"` - // ObjectType - Possible values include: 'ObjectTypeDirectoryObject', 'ObjectTypeApplication', 'ObjectTypeGroup', 'ObjectTypeServicePrincipal', 'ObjectTypeUser' + DeletionTimestamp *time.Time `json:"deletionTimestamp,omitempty"` + // ObjectType - Possible values include: 'ObjectTypeApplication', 'ObjectTypeGroup', 'ObjectTypeServicePrincipal', 'ObjectTypeUser' ObjectType ObjectType `json:"objectType,omitempty"` // DisplayName - The display name of the group. DisplayName *string `json:"displayName,omitempty"` @@ -122,59 +159,64 @@ func (ag ADGroup) MarshalJSON() ([]byte, error) { }) } -// AsApplication is the BasicDirectoryObject implementation for ADGroup. +// AsApplication is the DirectoryObject implementation for ADGroup. func (ag ADGroup) AsApplication() (*Application, bool) { return nil, false } -// AsADGroup is the BasicDirectoryObject implementation for ADGroup. +// AsADGroup is the DirectoryObject implementation for ADGroup. func (ag ADGroup) AsADGroup() (*ADGroup, bool) { return &ag, true } -// AsServicePrincipal is the BasicDirectoryObject implementation for ADGroup. +// AsServicePrincipal is the DirectoryObject implementation for ADGroup. func (ag ADGroup) AsServicePrincipal() (*ServicePrincipal, bool) { return nil, false } -// AsUser is the BasicDirectoryObject implementation for ADGroup. +// AsUser is the DirectoryObject implementation for ADGroup. func (ag ADGroup) AsUser() (*User, bool) { return nil, false } -// AsDirectoryObject is the BasicDirectoryObject implementation for ADGroup. -func (ag ADGroup) AsDirectoryObject() (*DirectoryObject, bool) { - return nil, false +// Response returns the raw HTTP response object. +func (ag ADGroup) Response() *http.Response { + return ag.rawResponse } -// AsBasicDirectoryObject is the BasicDirectoryObject implementation for ADGroup. -func (ag ADGroup) AsBasicDirectoryObject() (BasicDirectoryObject, bool) { - return &ag, true +// StatusCode returns the HTTP status code of the response, e.g. 200. +func (ag ADGroup) StatusCode() int { + return ag.rawResponse.StatusCode } -// Application active Directory application information. +// Status returns the HTTP status message of the response, e.g. "200 OK". +func (ag ADGroup) Status() string { + return ag.rawResponse.Status +} + +// Application - Active Directory application information. type Application struct { - autorest.Response `json:"-"` + rawResponse *http.Response // AdditionalProperties - Unmatched properties from the message are deserialized this collection - AdditionalProperties *map[string]*map[string]interface{} `json:",omitempty"` + AdditionalProperties map[string]map[string]interface{} `json:",omitempty"` // ObjectID - The object ID. ObjectID *string `json:"objectId,omitempty"` // DeletionTimestamp - The time at which the directory object was deleted. - DeletionTimestamp *date.Time `json:"deletionTimestamp,omitempty"` - // ObjectType - Possible values include: 'ObjectTypeDirectoryObject', 'ObjectTypeApplication', 'ObjectTypeGroup', 'ObjectTypeServicePrincipal', 'ObjectTypeUser' + DeletionTimestamp *time.Time `json:"deletionTimestamp,omitempty"` + // ObjectType - Possible values include: 'ObjectTypeApplication', 'ObjectTypeGroup', 'ObjectTypeServicePrincipal', 'ObjectTypeUser' ObjectType ObjectType `json:"objectType,omitempty"` // AppID - The application ID. AppID *string `json:"appId,omitempty"` // AppPermissions - The application permissions. - AppPermissions *[]string `json:"appPermissions,omitempty"` + AppPermissions []string `json:"appPermissions,omitempty"` // AvailableToOtherTenants - Whether the application is be available to other tenants. AvailableToOtherTenants *bool `json:"availableToOtherTenants,omitempty"` // DisplayName - The display name of the application. DisplayName *string `json:"displayName,omitempty"` // IdentifierUris - A collection of URIs for the application. - IdentifierUris *[]string `json:"identifierUris,omitempty"` + IdentifierUris []string `json:"identifierUris,omitempty"` // ReplyUrls - A collection of reply URLs for the application. - ReplyUrls *[]string `json:"replyUrls,omitempty"` + ReplyUrls []string `json:"replyUrls,omitempty"` // Homepage - The home page of the application. Homepage *string `json:"homepage,omitempty"` // Oauth2AllowImplicitFlow - Whether to allow implicit grant flow for OAuth2 @@ -192,162 +234,101 @@ func (a Application) MarshalJSON() ([]byte, error) { }) } -// AsApplication is the BasicDirectoryObject implementation for Application. +// AsApplication is the DirectoryObject implementation for Application. func (a Application) AsApplication() (*Application, bool) { return &a, true } -// AsADGroup is the BasicDirectoryObject implementation for Application. +// AsADGroup is the DirectoryObject implementation for Application. func (a Application) AsADGroup() (*ADGroup, bool) { return nil, false } -// AsServicePrincipal is the BasicDirectoryObject implementation for Application. +// AsServicePrincipal is the DirectoryObject implementation for Application. func (a Application) AsServicePrincipal() (*ServicePrincipal, bool) { return nil, false } -// AsUser is the BasicDirectoryObject implementation for Application. +// AsUser is the DirectoryObject implementation for Application. func (a Application) AsUser() (*User, bool) { return nil, false } -// AsDirectoryObject is the BasicDirectoryObject implementation for Application. -func (a Application) AsDirectoryObject() (*DirectoryObject, bool) { - return nil, false +// Response returns the raw HTTP response object. +func (a Application) Response() *http.Response { + return a.rawResponse } -// AsBasicDirectoryObject is the BasicDirectoryObject implementation for Application. -func (a Application) AsBasicDirectoryObject() (BasicDirectoryObject, bool) { - return &a, true +// StatusCode returns the HTTP status code of the response, e.g. 200. +func (a Application) StatusCode() int { + return a.rawResponse.StatusCode } -// ApplicationAddOwnerParameters request parameters for adding a owner to an application. +// Status returns the HTTP status message of the response, e.g. "200 OK". +func (a Application) Status() string { + return a.rawResponse.Status +} + +// ApplicationAddOwnerParameters - Request parameters for adding a owner to an application. type ApplicationAddOwnerParameters struct { // AdditionalProperties - Unmatched properties from the message are deserialized this collection - AdditionalProperties *map[string]*map[string]interface{} `json:",omitempty"` + AdditionalProperties map[string]map[string]interface{} `json:",omitempty"` // URL - A owner object URL, such as "https://graph.windows.net/0b1f9851-1bf0-433f-aec3-cb9272f093dc/directoryObjects/f260bbc4-c254-447b-94cf-293b5ec434dd", where "0b1f9851-1bf0-433f-aec3-cb9272f093dc" is the tenantId and "f260bbc4-c254-447b-94cf-293b5ec434dd" is the objectId of the owner (user, application, servicePrincipal, group) to be added. - URL *string `json:"url,omitempty"` + URL string `json:"url,omitempty"` } -// ApplicationCreateParameters request parameters for creating a new application. +// ApplicationCreateParameters - Request parameters for creating a new application. type ApplicationCreateParameters struct { // AdditionalProperties - Unmatched properties from the message are deserialized this collection - AdditionalProperties *map[string]*map[string]interface{} `json:",omitempty"` + AdditionalProperties map[string]map[string]interface{} `json:",omitempty"` // AvailableToOtherTenants - Whether the application is available to other tenants. - AvailableToOtherTenants *bool `json:"availableToOtherTenants,omitempty"` + AvailableToOtherTenants bool `json:"availableToOtherTenants,omitempty"` // DisplayName - The display name of the application. - DisplayName *string `json:"displayName,omitempty"` + DisplayName string `json:"displayName,omitempty"` // Homepage - The home page of the application. Homepage *string `json:"homepage,omitempty"` // IdentifierUris - A collection of URIs for the application. - IdentifierUris *[]string `json:"identifierUris,omitempty"` + IdentifierUris []string `json:"identifierUris,omitempty"` // ReplyUrls - A collection of reply URLs for the application. - ReplyUrls *[]string `json:"replyUrls,omitempty"` + ReplyUrls []string `json:"replyUrls,omitempty"` // KeyCredentials - The list of KeyCredential objects. - KeyCredentials *[]KeyCredential `json:"keyCredentials,omitempty"` + KeyCredentials []KeyCredential `json:"keyCredentials,omitempty"` // PasswordCredentials - The list of PasswordCredential objects. - PasswordCredentials *[]PasswordCredential `json:"passwordCredentials,omitempty"` + PasswordCredentials []PasswordCredential `json:"passwordCredentials,omitempty"` // Oauth2AllowImplicitFlow - Whether to allow implicit grant flow for OAuth2 Oauth2AllowImplicitFlow *bool `json:"oauth2AllowImplicitFlow,omitempty"` // RequiredResourceAccess - Specifies resources that this application requires access to and the set of OAuth permission scopes and application roles that it needs under each of those resources. This pre-configuration of required resource access drives the consent experience. - RequiredResourceAccess *[]RequiredResourceAccess `json:"requiredResourceAccess,omitempty"` + RequiredResourceAccess []RequiredResourceAccess `json:"requiredResourceAccess,omitempty"` } -// ApplicationListResult application list operation result. +// ApplicationListResult - Application list operation result. type ApplicationListResult struct { - autorest.Response `json:"-"` + rawResponse *http.Response // Value - A collection of applications. - Value *[]Application `json:"value,omitempty"` + Value []Application `json:"value,omitempty"` // OdataNextLink - The URL to get the next set of results. - OdataNextLink *string `json:"odata.nextLink,omitempty"` -} - -// ApplicationListResultIterator provides access to a complete listing of Application values. -type ApplicationListResultIterator struct { - i int - page ApplicationListResultPage -} - -// Next advances to the next value. If there was an error making -// the request the iterator does not advance and the error is returned. -func (iter *ApplicationListResultIterator) Next() error { - iter.i++ - if iter.i < len(iter.page.Values()) { - return nil - } - err := iter.page.Next() - if err != nil { - iter.i-- - return err - } - iter.i = 0 - return nil -} - -// NotDone returns true if the enumeration should be started or is not yet complete. -func (iter ApplicationListResultIterator) NotDone() bool { - return iter.page.NotDone() && iter.i < len(iter.page.Values()) -} - -// Response returns the raw server response from the last page request. -func (iter ApplicationListResultIterator) Response() ApplicationListResult { - return iter.page.Response() + OdataNextLink Marker `json:"OdataNextLink"` } -// Value returns the current value or a zero-initialized value if the -// iterator has advanced beyond the end of the collection. -func (iter ApplicationListResultIterator) Value() Application { - if !iter.page.NotDone() { - return Application{} - } - return iter.page.Values()[iter.i] -} - -// IsEmpty returns true if the ListResult contains no values. -func (alr ApplicationListResult) IsEmpty() bool { - return alr.Value == nil || len(*alr.Value) == 0 -} - -// ApplicationListResultPage contains a page of Application values. -type ApplicationListResultPage struct { - fn func(ApplicationListResult) (ApplicationListResult, error) - alr ApplicationListResult -} - -// Next advances to the next page of values. If there was an error making -// the request the page does not advance and the error is returned. -func (page *ApplicationListResultPage) Next() error { - next, err := page.fn(page.alr) - if err != nil { - return err - } - page.alr = next - return nil +// Response returns the raw HTTP response object. +func (alr ApplicationListResult) Response() *http.Response { + return alr.rawResponse } -// NotDone returns true if the page enumeration should be started or is not yet complete. -func (page ApplicationListResultPage) NotDone() bool { - return !page.alr.IsEmpty() +// StatusCode returns the HTTP status code of the response, e.g. 200. +func (alr ApplicationListResult) StatusCode() int { + return alr.rawResponse.StatusCode } -// Response returns the raw server response from the last page request. -func (page ApplicationListResultPage) Response() ApplicationListResult { - return page.alr -} - -// Values returns the slice of values for the current page or nil if there are no values. -func (page ApplicationListResultPage) Values() []Application { - if page.alr.IsEmpty() { - return nil - } - return *page.alr.Value +// Status returns the HTTP status message of the response, e.g. "200 OK". +func (alr ApplicationListResult) Status() string { + return alr.rawResponse.Status } -// ApplicationUpdateParameters request parameters for updating an existing application. +// ApplicationUpdateParameters - Request parameters for updating an existing application. type ApplicationUpdateParameters struct { // AdditionalProperties - Unmatched properties from the message are deserialized this collection - AdditionalProperties *map[string]*map[string]interface{} `json:",omitempty"` + AdditionalProperties map[string]map[string]interface{} `json:",omitempty"` // AvailableToOtherTenants - Whether the application is available to other tenants AvailableToOtherTenants *bool `json:"availableToOtherTenants,omitempty"` // DisplayName - The display name of the application. @@ -355,60 +336,61 @@ type ApplicationUpdateParameters struct { // Homepage - The home page of the application. Homepage *string `json:"homepage,omitempty"` // IdentifierUris - A collection of URIs for the application. - IdentifierUris *[]string `json:"identifierUris,omitempty"` + IdentifierUris []string `json:"identifierUris,omitempty"` // ReplyUrls - A collection of reply URLs for the application. - ReplyUrls *[]string `json:"replyUrls,omitempty"` + ReplyUrls []string `json:"replyUrls,omitempty"` // KeyCredentials - The list of KeyCredential objects. - KeyCredentials *[]KeyCredential `json:"keyCredentials,omitempty"` + KeyCredentials []KeyCredential `json:"keyCredentials,omitempty"` // PasswordCredentials - The list of PasswordCredential objects. - PasswordCredentials *[]PasswordCredential `json:"passwordCredentials,omitempty"` + PasswordCredentials []PasswordCredential `json:"passwordCredentials,omitempty"` // Oauth2AllowImplicitFlow - Whether to allow implicit grant flow for OAuth2 Oauth2AllowImplicitFlow *bool `json:"oauth2AllowImplicitFlow,omitempty"` // RequiredResourceAccess - Specifies resources that this application requires access to and the set of OAuth permission scopes and application roles that it needs under each of those resources. This pre-configuration of required resource access drives the consent experience. - RequiredResourceAccess *[]RequiredResourceAccess `json:"requiredResourceAccess,omitempty"` + RequiredResourceAccess []RequiredResourceAccess `json:"requiredResourceAccess,omitempty"` } -// CheckGroupMembershipParameters request parameters for IsMemberOf API call. +// CheckGroupMembershipParameters - Request parameters for IsMemberOf API call. type CheckGroupMembershipParameters struct { // AdditionalProperties - Unmatched properties from the message are deserialized this collection - AdditionalProperties *map[string]*map[string]interface{} `json:",omitempty"` + AdditionalProperties map[string]map[string]interface{} `json:",omitempty"` // GroupID - The object ID of the group to check. - GroupID *string `json:"groupId,omitempty"` + GroupID string `json:"groupId,omitempty"` // MemberID - The object ID of the contact, group, user, or service principal to check for membership in the specified group. - MemberID *string `json:"memberId,omitempty"` + MemberID string `json:"memberId,omitempty"` } -// CheckGroupMembershipResult server response for IsMemberOf API call +// CheckGroupMembershipResult - Server response for IsMemberOf API call type CheckGroupMembershipResult struct { - autorest.Response `json:"-"` + rawResponse *http.Response // AdditionalProperties - Unmatched properties from the message are deserialized this collection - AdditionalProperties *map[string]*map[string]interface{} `json:",omitempty"` + AdditionalProperties map[string]map[string]interface{} `json:",omitempty"` // Value - True if the specified user, group, contact, or service principal has either direct or transitive membership in the specified group; otherwise, false. Value *bool `json:"value,omitempty"` } -// BasicDirectoryObject represents an Azure Active Directory object. -type BasicDirectoryObject interface { +// Response returns the raw HTTP response object. +func (cgmr CheckGroupMembershipResult) Response() *http.Response { + return cgmr.rawResponse +} + +// StatusCode returns the HTTP status code of the response, e.g. 200. +func (cgmr CheckGroupMembershipResult) StatusCode() int { + return cgmr.rawResponse.StatusCode +} + +// Status returns the HTTP status message of the response, e.g. "200 OK". +func (cgmr CheckGroupMembershipResult) Status() string { + return cgmr.rawResponse.Status +} + +type DirectoryObject interface { AsApplication() (*Application, bool) AsADGroup() (*ADGroup, bool) AsServicePrincipal() (*ServicePrincipal, bool) AsUser() (*User, bool) - AsDirectoryObject() (*DirectoryObject, bool) -} - -// DirectoryObject represents an Azure Active Directory object. -type DirectoryObject struct { - // AdditionalProperties - Unmatched properties from the message are deserialized this collection - AdditionalProperties *map[string]*map[string]interface{} `json:",omitempty"` - // ObjectID - The object ID. - ObjectID *string `json:"objectId,omitempty"` - // DeletionTimestamp - The time at which the directory object was deleted. - DeletionTimestamp *date.Time `json:"deletionTimestamp,omitempty"` - // ObjectType - Possible values include: 'ObjectTypeDirectoryObject', 'ObjectTypeApplication', 'ObjectTypeGroup', 'ObjectTypeServicePrincipal', 'ObjectTypeUser' - ObjectType ObjectType `json:"objectType,omitempty"` } -func unmarshalBasicDirectoryObject(body []byte) (BasicDirectoryObject, error) { +func unmarshalDirectoryObject(body []byte) (DirectoryObject, error) { var m map[string]interface{} err := json.Unmarshal(body, &m) if err != nil { @@ -433,22 +415,20 @@ func unmarshalBasicDirectoryObject(body []byte) (BasicDirectoryObject, error) { err := json.Unmarshal(body, &u) return u, err default: - var do DirectoryObject - err := json.Unmarshal(body, &do) - return do, err + return nil, errors.New("Unsupported type") } } -func unmarshalBasicDirectoryObjectArray(body []byte) ([]BasicDirectoryObject, error) { +func unmarshalDirectoryObjectArray(body []byte) ([]DirectoryObject, error) { var rawMessages []*json.RawMessage err := json.Unmarshal(body, &rawMessages) if err != nil { return nil, err } - doArray := make([]BasicDirectoryObject, len(rawMessages)) + doArray := make([]DirectoryObject, len(rawMessages)) for index, rawMessage := range rawMessages { - do, err := unmarshalBasicDirectoryObject(*rawMessage) + do, err := unmarshalDirectoryObject(*rawMessage) if err != nil { return nil, err } @@ -457,52 +437,11 @@ func unmarshalBasicDirectoryObjectArray(body []byte) ([]BasicDirectoryObject, er return doArray, nil } -// MarshalJSON is the custom marshaler for DirectoryObject. -func (do DirectoryObject) MarshalJSON() ([]byte, error) { - do.ObjectType = ObjectTypeDirectoryObject - type Alias DirectoryObject - return json.Marshal(&struct { - Alias - }{ - Alias: (Alias)(do), - }) -} - -// AsApplication is the BasicDirectoryObject implementation for DirectoryObject. -func (do DirectoryObject) AsApplication() (*Application, bool) { - return nil, false -} - -// AsADGroup is the BasicDirectoryObject implementation for DirectoryObject. -func (do DirectoryObject) AsADGroup() (*ADGroup, bool) { - return nil, false -} - -// AsServicePrincipal is the BasicDirectoryObject implementation for DirectoryObject. -func (do DirectoryObject) AsServicePrincipal() (*ServicePrincipal, bool) { - return nil, false -} - -// AsUser is the BasicDirectoryObject implementation for DirectoryObject. -func (do DirectoryObject) AsUser() (*User, bool) { - return nil, false -} - -// AsDirectoryObject is the BasicDirectoryObject implementation for DirectoryObject. -func (do DirectoryObject) AsDirectoryObject() (*DirectoryObject, bool) { - return &do, true -} - -// AsBasicDirectoryObject is the BasicDirectoryObject implementation for DirectoryObject. -func (do DirectoryObject) AsBasicDirectoryObject() (BasicDirectoryObject, bool) { - return &do, true -} - -// DirectoryObjectListResult directoryObject list operation result. +// DirectoryObjectListResult - DirectoryObject list operation result. type DirectoryObjectListResult struct { - autorest.Response `json:"-"` + rawResponse *http.Response // Value - A collection of DirectoryObject. - Value *[]BasicDirectoryObject `json:"value,omitempty"` + Value []DirectoryObject `json:"value,omitempty"` } // UnmarshalJSON is the custom unmarshaler for DirectoryObjectListResult struct. @@ -516,7 +455,7 @@ func (dolr *DirectoryObjectListResult) UnmarshalJSON(body []byte) error { v = m["value"] if v != nil { - value, err := unmarshalBasicDirectoryObjectArray(*m["value"]) + value, err := unmarshalDirectoryObjectArray(*m["value"]) if err != nil { return err } @@ -526,11 +465,26 @@ func (dolr *DirectoryObjectListResult) UnmarshalJSON(body []byte) error { return nil } -// Domain active Directory Domain information. +// Response returns the raw HTTP response object. +func (dolr DirectoryObjectListResult) Response() *http.Response { + return dolr.rawResponse +} + +// StatusCode returns the HTTP status code of the response, e.g. 200. +func (dolr DirectoryObjectListResult) StatusCode() int { + return dolr.rawResponse.StatusCode +} + +// Status returns the HTTP status message of the response, e.g. "200 OK". +func (dolr DirectoryObjectListResult) Status() string { + return dolr.rawResponse.Status +} + +// Domain - Active Directory Domain information. type Domain struct { - autorest.Response `json:"-"` + rawResponse *http.Response // AdditionalProperties - Unmatched properties from the message are deserialized this collection - AdditionalProperties *map[string]*map[string]interface{} `json:",omitempty"` + AdditionalProperties map[string]map[string]interface{} `json:",omitempty"` // AuthenticationType - the type of the authentication into the domain. AuthenticationType *string `json:"authenticationType,omitempty"` // IsDefault - if this is the default domain in the tenant. @@ -538,287 +492,178 @@ type Domain struct { // IsVerified - if this domain's ownership is verified. IsVerified *bool `json:"isVerified,omitempty"` // Name - the domain name. - Name *string `json:"name,omitempty"` + Name string `json:"name,omitempty"` } -// DomainListResult server response for Get tenant domains API call. +// Response returns the raw HTTP response object. +func (d Domain) Response() *http.Response { + return d.rawResponse +} + +// StatusCode returns the HTTP status code of the response, e.g. 200. +func (d Domain) StatusCode() int { + return d.rawResponse.StatusCode +} + +// Status returns the HTTP status message of the response, e.g. "200 OK". +func (d Domain) Status() string { + return d.rawResponse.Status +} + +// DomainListResult - Server response for Get tenant domains API call. type DomainListResult struct { - autorest.Response `json:"-"` + rawResponse *http.Response // Value - the list of domains. - Value *[]Domain `json:"value,omitempty"` + Value []Domain `json:"value,omitempty"` } -// ErrorMessage active Directory error message. +// Response returns the raw HTTP response object. +func (dlr DomainListResult) Response() *http.Response { + return dlr.rawResponse +} + +// StatusCode returns the HTTP status code of the response, e.g. 200. +func (dlr DomainListResult) StatusCode() int { + return dlr.rawResponse.StatusCode +} + +// Status returns the HTTP status message of the response, e.g. "200 OK". +func (dlr DomainListResult) Status() string { + return dlr.rawResponse.Status +} + +// ErrorMessage - Active Directory error message. type ErrorMessage struct { // Message - Error message value. Message *string `json:"value,omitempty"` } -// GetObjectsParameters request parameters for the GetObjectsByObjectIds API. +// GetObjectsParameters - Request parameters for the GetObjectsByObjectIds API. type GetObjectsParameters struct { // AdditionalProperties - Unmatched properties from the message are deserialized this collection - AdditionalProperties *map[string]*map[string]interface{} `json:",omitempty"` + AdditionalProperties map[string]map[string]interface{} `json:",omitempty"` // ObjectIds - The requested object IDs. - ObjectIds *[]string `json:"objectIds,omitempty"` + ObjectIds []string `json:"objectIds,omitempty"` // Types - The requested object types. - Types *[]string `json:"types,omitempty"` + Types []string `json:"types,omitempty"` // IncludeDirectoryObjectReferences - If true, also searches for object IDs in the partner tenant. - IncludeDirectoryObjectReferences *bool `json:"includeDirectoryObjectReferences,omitempty"` + IncludeDirectoryObjectReferences bool `json:"includeDirectoryObjectReferences,omitempty"` } -// GetObjectsResult the response to an Active Directory object inquiry API request. +// GetObjectsResult - The response to an Active Directory object inquiry API request. type GetObjectsResult struct { - autorest.Response `json:"-"` + rawResponse *http.Response // Value - A collection of Active Directory objects. - Value *[]AADObject `json:"value,omitempty"` + Value []AADObject `json:"value,omitempty"` // OdataNextLink - The URL to get the next set of results. - OdataNextLink *string `json:"odata.nextLink,omitempty"` -} - -// GetObjectsResultIterator provides access to a complete listing of AADObject values. -type GetObjectsResultIterator struct { - i int - page GetObjectsResultPage -} - -// Next advances to the next value. If there was an error making -// the request the iterator does not advance and the error is returned. -func (iter *GetObjectsResultIterator) Next() error { - iter.i++ - if iter.i < len(iter.page.Values()) { - return nil - } - err := iter.page.Next() - if err != nil { - iter.i-- - return err - } - iter.i = 0 - return nil -} - -// NotDone returns true if the enumeration should be started or is not yet complete. -func (iter GetObjectsResultIterator) NotDone() bool { - return iter.page.NotDone() && iter.i < len(iter.page.Values()) -} - -// Response returns the raw server response from the last page request. -func (iter GetObjectsResultIterator) Response() GetObjectsResult { - return iter.page.Response() + OdataNextLink Marker `json:"OdataNextLink"` } -// Value returns the current value or a zero-initialized value if the -// iterator has advanced beyond the end of the collection. -func (iter GetObjectsResultIterator) Value() AADObject { - if !iter.page.NotDone() { - return AADObject{} - } - return iter.page.Values()[iter.i] +// Response returns the raw HTTP response object. +func (gor GetObjectsResult) Response() *http.Response { + return gor.rawResponse } -// IsEmpty returns true if the ListResult contains no values. -func (gor GetObjectsResult) IsEmpty() bool { - return gor.Value == nil || len(*gor.Value) == 0 +// StatusCode returns the HTTP status code of the response, e.g. 200. +func (gor GetObjectsResult) StatusCode() int { + return gor.rawResponse.StatusCode } -// GetObjectsResultPage contains a page of AADObject values. -type GetObjectsResultPage struct { - fn func(GetObjectsResult) (GetObjectsResult, error) - gor GetObjectsResult +// Status returns the HTTP status message of the response, e.g. "200 OK". +func (gor GetObjectsResult) Status() string { + return gor.rawResponse.Status } -// Next advances to the next page of values. If there was an error making -// the request the page does not advance and the error is returned. -func (page *GetObjectsResultPage) Next() error { - next, err := page.fn(page.gor) - if err != nil { - return err - } - page.gor = next - return nil -} - -// NotDone returns true if the page enumeration should be started or is not yet complete. -func (page GetObjectsResultPage) NotDone() bool { - return !page.gor.IsEmpty() -} - -// Response returns the raw server response from the last page request. -func (page GetObjectsResultPage) Response() GetObjectsResult { - return page.gor -} - -// Values returns the slice of values for the current page or nil if there are no values. -func (page GetObjectsResultPage) Values() []AADObject { - if page.gor.IsEmpty() { - return nil - } - return *page.gor.Value -} - -// GraphError active Directory error information. +// GraphError - Active Directory error information. type GraphError struct { // OdataError - A Graph API error. *OdataError `json:"odata.error,omitempty"` } -// UnmarshalJSON is the custom unmarshaler for GraphError struct. -func (ge *GraphError) UnmarshalJSON(body []byte) error { - var m map[string]*json.RawMessage - err := json.Unmarshal(body, &m) - if err != nil { - return err - } - var v *json.RawMessage - - v = m["odata.error"] - if v != nil { - var odataerror OdataError - err = json.Unmarshal(*m["odata.error"], &odataerror) - if err != nil { - return err - } - ge.OdataError = &odataerror - } - - return nil -} - -// GroupAddMemberParameters request parameters for adding a member to a group. +// GroupAddMemberParameters - Request parameters for adding a member to a group. type GroupAddMemberParameters struct { // AdditionalProperties - Unmatched properties from the message are deserialized this collection - AdditionalProperties *map[string]*map[string]interface{} `json:",omitempty"` + AdditionalProperties map[string]map[string]interface{} `json:",omitempty"` // URL - A member object URL, such as "https://graph.windows.net/0b1f9851-1bf0-433f-aec3-cb9272f093dc/directoryObjects/f260bbc4-c254-447b-94cf-293b5ec434dd", where "0b1f9851-1bf0-433f-aec3-cb9272f093dc" is the tenantId and "f260bbc4-c254-447b-94cf-293b5ec434dd" is the objectId of the member (user, application, servicePrincipal, group) to be added. - URL *string `json:"url,omitempty"` + URL string `json:"url,omitempty"` } -// GroupCreateParameters request parameters for creating a new group. +// GroupCreateParameters - Request parameters for creating a new group. type GroupCreateParameters struct { // AdditionalProperties - Unmatched properties from the message are deserialized this collection - AdditionalProperties *map[string]*map[string]interface{} `json:",omitempty"` + AdditionalProperties map[string]map[string]interface{} `json:",omitempty"` // DisplayName - Group display name - DisplayName *string `json:"displayName,omitempty"` + DisplayName string `json:"displayName,omitempty"` // MailEnabled - Whether the group is mail-enabled. Must be false. This is because only pure security groups can be created using the Graph API. - MailEnabled *bool `json:"mailEnabled,omitempty"` + MailEnabled bool `json:"mailEnabled,omitempty"` // MailNickname - Mail nickname - MailNickname *string `json:"mailNickname,omitempty"` + MailNickname string `json:"mailNickname,omitempty"` // SecurityEnabled - Whether the group is a security group. Must be true. This is because only pure security groups can be created using the Graph API. - SecurityEnabled *bool `json:"securityEnabled,omitempty"` + SecurityEnabled bool `json:"securityEnabled,omitempty"` } -// GroupGetMemberGroupsParameters request parameters for GetMemberGroups API call. +// GroupGetMemberGroupsParameters - Request parameters for GetMemberGroups API call. type GroupGetMemberGroupsParameters struct { // AdditionalProperties - Unmatched properties from the message are deserialized this collection - AdditionalProperties *map[string]*map[string]interface{} `json:",omitempty"` + AdditionalProperties map[string]map[string]interface{} `json:",omitempty"` // SecurityEnabledOnly - If true, only membership in security-enabled groups should be checked. Otherwise, membership in all groups should be checked. - SecurityEnabledOnly *bool `json:"securityEnabledOnly,omitempty"` + SecurityEnabledOnly bool `json:"securityEnabledOnly,omitempty"` } -// GroupGetMemberGroupsResult server response for GetMemberGroups API call. +// GroupGetMemberGroupsResult - Server response for GetMemberGroups API call. type GroupGetMemberGroupsResult struct { - autorest.Response `json:"-"` + rawResponse *http.Response // Value - A collection of group IDs of which the group is a member. - Value *[]string `json:"value,omitempty"` + Value []string `json:"value,omitempty"` } -// GroupListResult server response for Get tenant groups API call -type GroupListResult struct { - autorest.Response `json:"-"` - // Value - A collection of Active Directory groups. - Value *[]ADGroup `json:"value,omitempty"` - // OdataNextLink - The URL to get the next set of results. - OdataNextLink *string `json:"odata.nextLink,omitempty"` +// Response returns the raw HTTP response object. +func (ggmgr GroupGetMemberGroupsResult) Response() *http.Response { + return ggmgr.rawResponse } -// GroupListResultIterator provides access to a complete listing of ADGroup values. -type GroupListResultIterator struct { - i int - page GroupListResultPage +// StatusCode returns the HTTP status code of the response, e.g. 200. +func (ggmgr GroupGetMemberGroupsResult) StatusCode() int { + return ggmgr.rawResponse.StatusCode } -// Next advances to the next value. If there was an error making -// the request the iterator does not advance and the error is returned. -func (iter *GroupListResultIterator) Next() error { - iter.i++ - if iter.i < len(iter.page.Values()) { - return nil - } - err := iter.page.Next() - if err != nil { - iter.i-- - return err - } - iter.i = 0 - return nil +// Status returns the HTTP status message of the response, e.g. "200 OK". +func (ggmgr GroupGetMemberGroupsResult) Status() string { + return ggmgr.rawResponse.Status } -// NotDone returns true if the enumeration should be started or is not yet complete. -func (iter GroupListResultIterator) NotDone() bool { - return iter.page.NotDone() && iter.i < len(iter.page.Values()) -} - -// Response returns the raw server response from the last page request. -func (iter GroupListResultIterator) Response() GroupListResult { - return iter.page.Response() -} - -// Value returns the current value or a zero-initialized value if the -// iterator has advanced beyond the end of the collection. -func (iter GroupListResultIterator) Value() ADGroup { - if !iter.page.NotDone() { - return ADGroup{} - } - return iter.page.Values()[iter.i] -} - -// IsEmpty returns true if the ListResult contains no values. -func (glr GroupListResult) IsEmpty() bool { - return glr.Value == nil || len(*glr.Value) == 0 -} - -// GroupListResultPage contains a page of ADGroup values. -type GroupListResultPage struct { - fn func(GroupListResult) (GroupListResult, error) - glr GroupListResult -} - -// Next advances to the next page of values. If there was an error making -// the request the page does not advance and the error is returned. -func (page *GroupListResultPage) Next() error { - next, err := page.fn(page.glr) - if err != nil { - return err - } - page.glr = next - return nil +// GroupListResult - Server response for Get tenant groups API call +type GroupListResult struct { + rawResponse *http.Response + // Value - A collection of Active Directory groups. + Value []ADGroup `json:"value,omitempty"` + // OdataNextLink - The URL to get the next set of results. + OdataNextLink Marker `json:"OdataNextLink"` } -// NotDone returns true if the page enumeration should be started or is not yet complete. -func (page GroupListResultPage) NotDone() bool { - return !page.glr.IsEmpty() +// Response returns the raw HTTP response object. +func (glr GroupListResult) Response() *http.Response { + return glr.rawResponse } -// Response returns the raw server response from the last page request. -func (page GroupListResultPage) Response() GroupListResult { - return page.glr +// StatusCode returns the HTTP status code of the response, e.g. 200. +func (glr GroupListResult) StatusCode() int { + return glr.rawResponse.StatusCode } -// Values returns the slice of values for the current page or nil if there are no values. -func (page GroupListResultPage) Values() []ADGroup { - if page.glr.IsEmpty() { - return nil - } - return *page.glr.Value +// Status returns the HTTP status message of the response, e.g. "200 OK". +func (glr GroupListResult) Status() string { + return glr.rawResponse.Status } -// KeyCredential active Directory Key Credential information. +// KeyCredential - Active Directory Key Credential information. type KeyCredential struct { // AdditionalProperties - Unmatched properties from the message are deserialized this collection - AdditionalProperties *map[string]*map[string]interface{} `json:",omitempty"` + AdditionalProperties map[string]map[string]interface{} `json:",omitempty"` // StartDate - Start date. - StartDate *date.Time `json:"startDate,omitempty"` + StartDate *time.Time `json:"startDate,omitempty"` // EndDate - End date. - EndDate *date.Time `json:"endDate,omitempty"` + EndDate *time.Time `json:"endDate,omitempty"` // Value - Key value. Value *string `json:"value,omitempty"` // KeyID - Key ID. @@ -827,139 +672,139 @@ type KeyCredential struct { Usage *string `json:"usage,omitempty"` // Type - Type. Acceptable values are 'AsymmetricX509Cert' and 'Symmetric'. Type *string `json:"type,omitempty"` + // CustomKeyIdentifier - Custom Key Identifier + CustomKeyIdentifier []byte `json:"customKeyIdentifier,omitempty"` } -// KeyCredentialListResult keyCredential list operation result. +// KeyCredentialListResult - KeyCredential list operation result. type KeyCredentialListResult struct { - autorest.Response `json:"-"` + rawResponse *http.Response // Value - A collection of KeyCredentials. - Value *[]KeyCredential `json:"value,omitempty"` + Value []KeyCredential `json:"value,omitempty"` +} + +// Response returns the raw HTTP response object. +func (kclr KeyCredentialListResult) Response() *http.Response { + return kclr.rawResponse +} + +// StatusCode returns the HTTP status code of the response, e.g. 200. +func (kclr KeyCredentialListResult) StatusCode() int { + return kclr.rawResponse.StatusCode } -// KeyCredentialsUpdateParameters request parameters for a KeyCredentials update operation +// Status returns the HTTP status message of the response, e.g. "200 OK". +func (kclr KeyCredentialListResult) Status() string { + return kclr.rawResponse.Status +} + +// KeyCredentialsUpdateParameters - Request parameters for a KeyCredentials update operation type KeyCredentialsUpdateParameters struct { // Value - A collection of KeyCredentials. - Value *[]KeyCredential `json:"value,omitempty"` + Value []KeyCredential `json:"value,omitempty"` } -// OdataError active Directory OData error information. +// OdataError - Active Directory OData error information. type OdataError struct { // Code - Error code. Code *string `json:"code,omitempty"` - // ErrorMessage - Error Message. + // Message - Error Message. *ErrorMessage `json:"message,omitempty"` } -// UnmarshalJSON is the custom unmarshaler for OdataError struct. -func (oe *OdataError) UnmarshalJSON(body []byte) error { - var m map[string]*json.RawMessage - err := json.Unmarshal(body, &m) - if err != nil { - return err - } - var v *json.RawMessage - - v = m["code"] - if v != nil { - var code string - err = json.Unmarshal(*m["code"], &code) - if err != nil { - return err - } - oe.Code = &code - } - - v = m["message"] - if v != nil { - var message ErrorMessage - err = json.Unmarshal(*m["message"], &message) - if err != nil { - return err - } - oe.ErrorMessage = &message - } - - return nil -} - -// PasswordCredential active Directory Password Credential information. +// PasswordCredential - Active Directory Password Credential information. type PasswordCredential struct { // AdditionalProperties - Unmatched properties from the message are deserialized this collection - AdditionalProperties *map[string]*map[string]interface{} `json:",omitempty"` + AdditionalProperties map[string]map[string]interface{} `json:",omitempty"` // StartDate - Start date. - StartDate *date.Time `json:"startDate,omitempty"` + StartDate *time.Time `json:"startDate,omitempty"` // EndDate - End date. - EndDate *date.Time `json:"endDate,omitempty"` + EndDate *time.Time `json:"endDate,omitempty"` // KeyID - Key ID. KeyID *string `json:"keyId,omitempty"` // Value - Key value. Value *string `json:"value,omitempty"` } -// PasswordCredentialListResult passwordCredential list operation result. +// PasswordCredentialListResult - PasswordCredential list operation result. type PasswordCredentialListResult struct { - autorest.Response `json:"-"` + rawResponse *http.Response // Value - A collection of PasswordCredentials. - Value *[]PasswordCredential `json:"value,omitempty"` + Value []PasswordCredential `json:"value,omitempty"` +} + +// Response returns the raw HTTP response object. +func (pclr PasswordCredentialListResult) Response() *http.Response { + return pclr.rawResponse +} + +// StatusCode returns the HTTP status code of the response, e.g. 200. +func (pclr PasswordCredentialListResult) StatusCode() int { + return pclr.rawResponse.StatusCode +} + +// Status returns the HTTP status message of the response, e.g. "200 OK". +func (pclr PasswordCredentialListResult) Status() string { + return pclr.rawResponse.Status } -// PasswordCredentialsUpdateParameters request parameters for a PasswordCredentials update operation. +// PasswordCredentialsUpdateParameters - Request parameters for a PasswordCredentials update operation. type PasswordCredentialsUpdateParameters struct { // Value - A collection of PasswordCredentials. - Value *[]PasswordCredential `json:"value,omitempty"` + Value []PasswordCredential `json:"value,omitempty"` } -// PasswordProfile the password profile associated with a user. +// PasswordProfile - The password profile associated with a user. type PasswordProfile struct { // AdditionalProperties - Unmatched properties from the message are deserialized this collection - AdditionalProperties *map[string]*map[string]interface{} `json:",omitempty"` + AdditionalProperties map[string]map[string]interface{} `json:",omitempty"` // Password - Password - Password *string `json:"password,omitempty"` + Password string `json:"password,omitempty"` // ForceChangePasswordNextLogin - Whether to force a password change on next login. ForceChangePasswordNextLogin *bool `json:"forceChangePasswordNextLogin,omitempty"` } -// RequiredResourceAccess specifies the set of OAuth 2.0 permission scopes and app roles under the specified resource +// 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 // requiredResourceAccess property of the Application entity is a collection of ReqiredResourceAccess. type RequiredResourceAccess struct { // AdditionalProperties - Unmatched properties from the message are deserialized this collection - AdditionalProperties *map[string]*map[string]interface{} `json:",omitempty"` + AdditionalProperties map[string]map[string]interface{} `json:",omitempty"` // ResourceAccess - The list of OAuth2.0 permission scopes and app roles that the application requires from the specified resource. - ResourceAccess *[]ResourceAccess `json:"resourceAccess,omitempty"` + ResourceAccess []ResourceAccess `json:"resourceAccess,omitempty"` // ResourceAppID - The unique identifier for the resource that the application requires access to. This should be equal to the appId declared on the target resource application. ResourceAppID *string `json:"resourceAppId,omitempty"` } -// ResourceAccess specifies an OAuth 2.0 permission scope or an app role that an application requires. The +// ResourceAccess - Specifies an OAuth 2.0 permission scope or an app role that an application requires. The // resourceAccess property of the RequiredResourceAccess type is a collection of ResourceAccess. type ResourceAccess struct { // AdditionalProperties - Unmatched properties from the message are deserialized this collection - AdditionalProperties *map[string]*map[string]interface{} `json:",omitempty"` + AdditionalProperties map[string]map[string]interface{} `json:",omitempty"` // ID - The unique identifier for one of the OAuth2Permission or AppRole instances that the resource application exposes. - ID *string `json:"id,omitempty"` + ID string `json:"id,omitempty"` // Type - Specifies whether the id property references an OAuth2Permission or an AppRole. Possible values are "scope" or "role". Type *string `json:"type,omitempty"` } -// ServicePrincipal active Directory service principal information. +// ServicePrincipal - Active Directory service principal information. type ServicePrincipal struct { - autorest.Response `json:"-"` + rawResponse *http.Response // AdditionalProperties - Unmatched properties from the message are deserialized this collection - AdditionalProperties *map[string]*map[string]interface{} `json:",omitempty"` + AdditionalProperties map[string]map[string]interface{} `json:",omitempty"` // ObjectID - The object ID. ObjectID *string `json:"objectId,omitempty"` // DeletionTimestamp - The time at which the directory object was deleted. - DeletionTimestamp *date.Time `json:"deletionTimestamp,omitempty"` - // ObjectType - Possible values include: 'ObjectTypeDirectoryObject', 'ObjectTypeApplication', 'ObjectTypeGroup', 'ObjectTypeServicePrincipal', 'ObjectTypeUser' + DeletionTimestamp *time.Time `json:"deletionTimestamp,omitempty"` + // ObjectType - Possible values include: 'ObjectTypeApplication', 'ObjectTypeGroup', 'ObjectTypeServicePrincipal', 'ObjectTypeUser' ObjectType ObjectType `json:"objectType,omitempty"` // DisplayName - The display name of the service principal. DisplayName *string `json:"displayName,omitempty"` // AppID - The application ID. AppID *string `json:"appId,omitempty"` // ServicePrincipalNames - A collection of service principal names. - ServicePrincipalNames *[]string `json:"servicePrincipalNames,omitempty"` + ServicePrincipalNames []string `json:"servicePrincipalNames,omitempty"` } // MarshalJSON is the custom marshaler for ServicePrincipal. @@ -973,161 +818,100 @@ func (sp ServicePrincipal) MarshalJSON() ([]byte, error) { }) } -// AsApplication is the BasicDirectoryObject implementation for ServicePrincipal. +// AsApplication is the DirectoryObject implementation for ServicePrincipal. func (sp ServicePrincipal) AsApplication() (*Application, bool) { return nil, false } -// AsADGroup is the BasicDirectoryObject implementation for ServicePrincipal. +// AsADGroup is the DirectoryObject implementation for ServicePrincipal. func (sp ServicePrincipal) AsADGroup() (*ADGroup, bool) { return nil, false } -// AsServicePrincipal is the BasicDirectoryObject implementation for ServicePrincipal. +// AsServicePrincipal is the DirectoryObject implementation for ServicePrincipal. func (sp ServicePrincipal) AsServicePrincipal() (*ServicePrincipal, bool) { return &sp, true } -// AsUser is the BasicDirectoryObject implementation for ServicePrincipal. +// AsUser is the DirectoryObject implementation for ServicePrincipal. func (sp ServicePrincipal) AsUser() (*User, bool) { return nil, false } -// AsDirectoryObject is the BasicDirectoryObject implementation for ServicePrincipal. -func (sp ServicePrincipal) AsDirectoryObject() (*DirectoryObject, bool) { - return nil, false +// Response returns the raw HTTP response object. +func (sp ServicePrincipal) Response() *http.Response { + return sp.rawResponse } -// AsBasicDirectoryObject is the BasicDirectoryObject implementation for ServicePrincipal. -func (sp ServicePrincipal) AsBasicDirectoryObject() (BasicDirectoryObject, bool) { - return &sp, true +// StatusCode returns the HTTP status code of the response, e.g. 200. +func (sp ServicePrincipal) StatusCode() int { + return sp.rawResponse.StatusCode } -// ServicePrincipalCreateParameters request parameters for creating a new service principal. +// Status returns the HTTP status message of the response, e.g. "200 OK". +func (sp ServicePrincipal) Status() string { + return sp.rawResponse.Status +} + +// ServicePrincipalCreateParameters - Request parameters for creating a new service principal. type ServicePrincipalCreateParameters struct { // AdditionalProperties - Unmatched properties from the message are deserialized this collection - AdditionalProperties *map[string]*map[string]interface{} `json:",omitempty"` + AdditionalProperties map[string]map[string]interface{} `json:",omitempty"` // AppID - application Id - AppID *string `json:"appId,omitempty"` + AppID string `json:"appId,omitempty"` // AccountEnabled - Whether the account is enabled - AccountEnabled *bool `json:"accountEnabled,omitempty"` + AccountEnabled bool `json:"accountEnabled,omitempty"` // KeyCredentials - A collection of KeyCredential objects. - KeyCredentials *[]KeyCredential `json:"keyCredentials,omitempty"` + KeyCredentials []KeyCredential `json:"keyCredentials,omitempty"` // PasswordCredentials - A collection of PasswordCredential objects - PasswordCredentials *[]PasswordCredential `json:"passwordCredentials,omitempty"` + PasswordCredentials []PasswordCredential `json:"passwordCredentials,omitempty"` } -// ServicePrincipalListResult server response for get tenant service principals API call. +// ServicePrincipalListResult - Server response for get tenant service principals API call. type ServicePrincipalListResult struct { - autorest.Response `json:"-"` + rawResponse *http.Response // Value - the list of service principals. - Value *[]ServicePrincipal `json:"value,omitempty"` + Value []ServicePrincipal `json:"value,omitempty"` // OdataNextLink - the URL to get the next set of results. - OdataNextLink *string `json:"odata.nextLink,omitempty"` -} - -// ServicePrincipalListResultIterator provides access to a complete listing of ServicePrincipal values. -type ServicePrincipalListResultIterator struct { - i int - page ServicePrincipalListResultPage -} - -// Next advances to the next value. If there was an error making -// the request the iterator does not advance and the error is returned. -func (iter *ServicePrincipalListResultIterator) Next() error { - iter.i++ - if iter.i < len(iter.page.Values()) { - return nil - } - err := iter.page.Next() - if err != nil { - iter.i-- - return err - } - iter.i = 0 - return nil -} - -// NotDone returns true if the enumeration should be started or is not yet complete. -func (iter ServicePrincipalListResultIterator) NotDone() bool { - return iter.page.NotDone() && iter.i < len(iter.page.Values()) + OdataNextLink Marker `json:"OdataNextLink"` } -// Response returns the raw server response from the last page request. -func (iter ServicePrincipalListResultIterator) Response() ServicePrincipalListResult { - return iter.page.Response() +// Response returns the raw HTTP response object. +func (splr ServicePrincipalListResult) Response() *http.Response { + return splr.rawResponse } -// Value returns the current value or a zero-initialized value if the -// iterator has advanced beyond the end of the collection. -func (iter ServicePrincipalListResultIterator) Value() ServicePrincipal { - if !iter.page.NotDone() { - return ServicePrincipal{} - } - return iter.page.Values()[iter.i] +// StatusCode returns the HTTP status code of the response, e.g. 200. +func (splr ServicePrincipalListResult) StatusCode() int { + return splr.rawResponse.StatusCode } -// IsEmpty returns true if the ListResult contains no values. -func (splr ServicePrincipalListResult) IsEmpty() bool { - return splr.Value == nil || len(*splr.Value) == 0 +// Status returns the HTTP status message of the response, e.g. "200 OK". +func (splr ServicePrincipalListResult) Status() string { + return splr.rawResponse.Status } -// ServicePrincipalListResultPage contains a page of ServicePrincipal values. -type ServicePrincipalListResultPage struct { - fn func(ServicePrincipalListResult) (ServicePrincipalListResult, error) - splr ServicePrincipalListResult -} - -// Next advances to the next page of values. If there was an error making -// the request the page does not advance and the error is returned. -func (page *ServicePrincipalListResultPage) Next() error { - next, err := page.fn(page.splr) - if err != nil { - return err - } - page.splr = next - return nil -} - -// NotDone returns true if the page enumeration should be started or is not yet complete. -func (page ServicePrincipalListResultPage) NotDone() bool { - return !page.splr.IsEmpty() -} - -// Response returns the raw server response from the last page request. -func (page ServicePrincipalListResultPage) Response() ServicePrincipalListResult { - return page.splr -} - -// Values returns the slice of values for the current page or nil if there are no values. -func (page ServicePrincipalListResultPage) Values() []ServicePrincipal { - if page.splr.IsEmpty() { - return nil - } - return *page.splr.Value -} - -// SignInName contains information about a sign-in name of a local account user in an Azure Active Directory B2C +// SignInName - Contains information about a sign-in name of a local account user in an Azure Active Directory B2C // tenant. type SignInName struct { // AdditionalProperties - Unmatched properties from the message are deserialized this collection - AdditionalProperties *map[string]*map[string]interface{} `json:",omitempty"` + AdditionalProperties map[string]map[string]interface{} `json:",omitempty"` // Type - A string value that can be used to classify user sign-in types in your directory, such as 'emailAddress' or 'userName'. Type *string `json:"type,omitempty"` // Value - The sign-in used by the local account. Must be unique across the company/tenant. For example, 'johnc@example.com'. Value *string `json:"value,omitempty"` } -// User active Directory user information. +// User - Active Directory user information. type User struct { - autorest.Response `json:"-"` + rawResponse *http.Response // AdditionalProperties - Unmatched properties from the message are deserialized this collection - AdditionalProperties *map[string]*map[string]interface{} `json:",omitempty"` + AdditionalProperties map[string]map[string]interface{} `json:",omitempty"` // ObjectID - The object ID. ObjectID *string `json:"objectId,omitempty"` // DeletionTimestamp - The time at which the directory object was deleted. - DeletionTimestamp *date.Time `json:"deletionTimestamp,omitempty"` - // ObjectType - Possible values include: 'ObjectTypeDirectoryObject', 'ObjectTypeApplication', 'ObjectTypeGroup', 'ObjectTypeServicePrincipal', 'ObjectTypeUser' + DeletionTimestamp *time.Time `json:"deletionTimestamp,omitempty"` + // ObjectType - Possible values include: 'ObjectTypeApplication', 'ObjectTypeGroup', 'ObjectTypeServicePrincipal', 'ObjectTypeUser' ObjectType ObjectType `json:"objectType,omitempty"` // ImmutableID - This must be specified if you are using a federated domain for the user's userPrincipalName (UPN) property when creating a new user account. It is used to associate an on-premises Active Directory user account with their Azure AD user object. ImmutableID *string `json:"immutableId,omitempty"` @@ -1137,7 +921,7 @@ type User struct { GivenName *string `json:"givenName,omitempty"` // Surname - The user's surname (family name or last name). Surname *string `json:"surname,omitempty"` - // UserType - A string value that can be used to classify user types in your directory, such as 'Member' and 'Guest'. Possible values include: 'Member', 'Guest' + // UserType - A string value that can be used to classify user types in your directory, such as 'Member' and 'Guest'. Possible values include: 'Member', 'Guest', 'None' UserType UserType `json:"userType,omitempty"` // AccountEnabled - Whether the account is enabled. AccountEnabled *bool `json:"accountEnabled,omitempty"` @@ -1150,7 +934,7 @@ type User struct { // Mail - The primary email address of the user. Mail *string `json:"mail,omitempty"` // SignInNames - The sign-in names of the user. - SignInNames *[]SignInName `json:"signInNames,omitempty"` + SignInNames []SignInName `json:"signInNames,omitempty"` } // MarshalJSON is the custom marshaler for User. @@ -1164,40 +948,45 @@ func (u User) MarshalJSON() ([]byte, error) { }) } -// AsApplication is the BasicDirectoryObject implementation for User. +// AsApplication is the DirectoryObject implementation for User. func (u User) AsApplication() (*Application, bool) { return nil, false } -// AsADGroup is the BasicDirectoryObject implementation for User. +// AsADGroup is the DirectoryObject implementation for User. func (u User) AsADGroup() (*ADGroup, bool) { return nil, false } -// AsServicePrincipal is the BasicDirectoryObject implementation for User. +// AsServicePrincipal is the DirectoryObject implementation for User. func (u User) AsServicePrincipal() (*ServicePrincipal, bool) { return nil, false } -// AsUser is the BasicDirectoryObject implementation for User. +// AsUser is the DirectoryObject implementation for User. func (u User) AsUser() (*User, bool) { return &u, true } -// AsDirectoryObject is the BasicDirectoryObject implementation for User. -func (u User) AsDirectoryObject() (*DirectoryObject, bool) { - return nil, false +// Response returns the raw HTTP response object. +func (u User) Response() *http.Response { + return u.rawResponse } -// AsBasicDirectoryObject is the BasicDirectoryObject implementation for User. -func (u User) AsBasicDirectoryObject() (BasicDirectoryObject, bool) { - return &u, true +// StatusCode returns the HTTP status code of the response, e.g. 200. +func (u User) StatusCode() int { + return u.rawResponse.StatusCode +} + +// Status returns the HTTP status message of the response, e.g. "200 OK". +func (u User) Status() string { + return u.rawResponse.Status } // UserBase ... type UserBase struct { // AdditionalProperties - Unmatched properties from the message are deserialized this collection - AdditionalProperties *map[string]*map[string]interface{} `json:",omitempty"` + AdditionalProperties map[string]map[string]interface{} `json:",omitempty"` // ImmutableID - This must be specified if you are using a federated domain for the user's userPrincipalName (UPN) property when creating a new user account. It is used to associate an on-premises Active Directory user account with their Azure AD user object. ImmutableID *string `json:"immutableId,omitempty"` // UsageLocation - A two letter country code (ISO standard 3166). Required for users that will be assigned licenses due to legal requirement to check for availability of services in countries. Examples include: "US", "JP", and "GB". @@ -1206,14 +995,14 @@ type UserBase struct { GivenName *string `json:"givenName,omitempty"` // Surname - The user's surname (family name or last name). Surname *string `json:"surname,omitempty"` - // UserType - A string value that can be used to classify user types in your directory, such as 'Member' and 'Guest'. Possible values include: 'Member', 'Guest' + // UserType - A string value that can be used to classify user types in your directory, such as 'Member' and 'Guest'. Possible values include: 'Member', 'Guest', 'None' UserType UserType `json:"userType,omitempty"` } -// UserCreateParameters request parameters for creating a new work or school account user. +// UserCreateParameters - Request parameters for creating a new work or school account user. type UserCreateParameters struct { // AdditionalProperties - Unmatched properties from the message are deserialized this collection - AdditionalProperties *map[string]*map[string]interface{} `json:",omitempty"` + AdditionalProperties map[string]map[string]interface{} `json:",omitempty"` // ImmutableID - This must be specified if you are using a federated domain for the user's userPrincipalName (UPN) property when creating a new user account. It is used to associate an on-premises Active Directory user account with their Azure AD user object. ImmutableID *string `json:"immutableId,omitempty"` // UsageLocation - A two letter country code (ISO standard 3166). Required for users that will be assigned licenses due to legal requirement to check for availability of services in countries. Examples include: "US", "JP", and "GB". @@ -1222,131 +1011,80 @@ type UserCreateParameters struct { GivenName *string `json:"givenName,omitempty"` // Surname - The user's surname (family name or last name). Surname *string `json:"surname,omitempty"` - // UserType - A string value that can be used to classify user types in your directory, such as 'Member' and 'Guest'. Possible values include: 'Member', 'Guest' + // UserType - A string value that can be used to classify user types in your directory, such as 'Member' and 'Guest'. Possible values include: 'Member', 'Guest', 'None' UserType UserType `json:"userType,omitempty"` // AccountEnabled - Whether the account is enabled. - AccountEnabled *bool `json:"accountEnabled,omitempty"` + AccountEnabled bool `json:"accountEnabled,omitempty"` // DisplayName - The display name of the user. - DisplayName *string `json:"displayName,omitempty"` + DisplayName string `json:"displayName,omitempty"` // PasswordProfile - Password Profile - PasswordProfile *PasswordProfile `json:"passwordProfile,omitempty"` + PasswordProfile PasswordProfile `json:"passwordProfile,omitempty"` // UserPrincipalName - The user principal name (someuser@contoso.com). It must contain one of the verified domains for the tenant. - UserPrincipalName *string `json:"userPrincipalName,omitempty"` + UserPrincipalName string `json:"userPrincipalName,omitempty"` // MailNickname - The mail alias for the user. - MailNickname *string `json:"mailNickname,omitempty"` + MailNickname string `json:"mailNickname,omitempty"` // Mail - The primary email address of the user. Mail *string `json:"mail,omitempty"` } -// UserGetMemberGroupsParameters request parameters for GetMemberGroups API call. +// UserGetMemberGroupsParameters - Request parameters for GetMemberGroups API call. type UserGetMemberGroupsParameters struct { // AdditionalProperties - Unmatched properties from the message are deserialized this collection - AdditionalProperties *map[string]*map[string]interface{} `json:",omitempty"` + AdditionalProperties map[string]map[string]interface{} `json:",omitempty"` // SecurityEnabledOnly - If true, only membership in security-enabled groups should be checked. Otherwise, membership in all groups should be checked. - SecurityEnabledOnly *bool `json:"securityEnabledOnly,omitempty"` + SecurityEnabledOnly bool `json:"securityEnabledOnly,omitempty"` } -// UserGetMemberGroupsResult server response for GetMemberGroups API call. +// UserGetMemberGroupsResult - Server response for GetMemberGroups API call. type UserGetMemberGroupsResult struct { - autorest.Response `json:"-"` + rawResponse *http.Response // Value - A collection of group IDs of which the user is a member. - Value *[]string `json:"value,omitempty"` -} - -// UserListResult server response for Get tenant users API call. -type UserListResult struct { - autorest.Response `json:"-"` - // Value - the list of users. - Value *[]User `json:"value,omitempty"` - // OdataNextLink - The URL to get the next set of results. - OdataNextLink *string `json:"odata.nextLink,omitempty"` -} - -// UserListResultIterator provides access to a complete listing of User values. -type UserListResultIterator struct { - i int - page UserListResultPage -} - -// Next advances to the next value. If there was an error making -// the request the iterator does not advance and the error is returned. -func (iter *UserListResultIterator) Next() error { - iter.i++ - if iter.i < len(iter.page.Values()) { - return nil - } - err := iter.page.Next() - if err != nil { - iter.i-- - return err - } - iter.i = 0 - return nil + Value []string `json:"value,omitempty"` } -// NotDone returns true if the enumeration should be started or is not yet complete. -func (iter UserListResultIterator) NotDone() bool { - return iter.page.NotDone() && iter.i < len(iter.page.Values()) -} - -// Response returns the raw server response from the last page request. -func (iter UserListResultIterator) Response() UserListResult { - return iter.page.Response() -} - -// Value returns the current value or a zero-initialized value if the -// iterator has advanced beyond the end of the collection. -func (iter UserListResultIterator) Value() User { - if !iter.page.NotDone() { - return User{} - } - return iter.page.Values()[iter.i] +// Response returns the raw HTTP response object. +func (ugmgr UserGetMemberGroupsResult) Response() *http.Response { + return ugmgr.rawResponse } -// IsEmpty returns true if the ListResult contains no values. -func (ulr UserListResult) IsEmpty() bool { - return ulr.Value == nil || len(*ulr.Value) == 0 +// StatusCode returns the HTTP status code of the response, e.g. 200. +func (ugmgr UserGetMemberGroupsResult) StatusCode() int { + return ugmgr.rawResponse.StatusCode } -// UserListResultPage contains a page of User values. -type UserListResultPage struct { - fn func(UserListResult) (UserListResult, error) - ulr UserListResult +// Status returns the HTTP status message of the response, e.g. "200 OK". +func (ugmgr UserGetMemberGroupsResult) Status() string { + return ugmgr.rawResponse.Status } -// Next advances to the next page of values. If there was an error making -// the request the page does not advance and the error is returned. -func (page *UserListResultPage) Next() error { - next, err := page.fn(page.ulr) - if err != nil { - return err - } - page.ulr = next - return nil +// UserListResult - Server response for Get tenant users API call. +type UserListResult struct { + rawResponse *http.Response + // Value - the list of users. + Value []User `json:"value,omitempty"` + // OdataNextLink - The URL to get the next set of results. + OdataNextLink Marker `json:"OdataNextLink"` } -// NotDone returns true if the page enumeration should be started or is not yet complete. -func (page UserListResultPage) NotDone() bool { - return !page.ulr.IsEmpty() +// Response returns the raw HTTP response object. +func (ulr UserListResult) Response() *http.Response { + return ulr.rawResponse } -// Response returns the raw server response from the last page request. -func (page UserListResultPage) Response() UserListResult { - return page.ulr +// StatusCode returns the HTTP status code of the response, e.g. 200. +func (ulr UserListResult) StatusCode() int { + return ulr.rawResponse.StatusCode } -// Values returns the slice of values for the current page or nil if there are no values. -func (page UserListResultPage) Values() []User { - if page.ulr.IsEmpty() { - return nil - } - return *page.ulr.Value +// Status returns the HTTP status message of the response, e.g. "200 OK". +func (ulr UserListResult) Status() string { + return ulr.rawResponse.Status } -// UserUpdateParameters request parameters for updating an existing work or school account user. +// UserUpdateParameters - Request parameters for updating an existing work or school account user. type UserUpdateParameters struct { // AdditionalProperties - Unmatched properties from the message are deserialized this collection - AdditionalProperties *map[string]*map[string]interface{} `json:",omitempty"` + AdditionalProperties map[string]map[string]interface{} `json:",omitempty"` // ImmutableID - This must be specified if you are using a federated domain for the user's userPrincipalName (UPN) property when creating a new user account. It is used to associate an on-premises Active Directory user account with their Azure AD user object. ImmutableID *string `json:"immutableId,omitempty"` // UsageLocation - A two letter country code (ISO standard 3166). Required for users that will be assigned licenses due to legal requirement to check for availability of services in countries. Examples include: "US", "JP", and "GB". @@ -1355,7 +1093,7 @@ type UserUpdateParameters struct { GivenName *string `json:"givenName,omitempty"` // Surname - The user's surname (family name or last name). Surname *string `json:"surname,omitempty"` - // UserType - A string value that can be used to classify user types in your directory, such as 'Member' and 'Guest'. Possible values include: 'Member', 'Guest' + // UserType - A string value that can be used to classify user types in your directory, such as 'Member' and 'Guest'. Possible values include: 'Member', 'Guest', 'None' UserType UserType `json:"userType,omitempty"` // AccountEnabled - Whether the account is enabled. AccountEnabled *bool `json:"accountEnabled,omitempty"` diff --git a/services/graphrbac/1.6/graphrbac/objects.go b/services/graphrbac/1.6/graphrbac/objects.go index f0c34caf78cc..9f8066a3ddcb 100644 --- a/services/graphrbac/1.6/graphrbac/objects.go +++ b/services/graphrbac/1.6/graphrbac/objects.go @@ -18,236 +18,191 @@ package graphrbac // Changes may cause incorrect behavior and will be lost if the code is regenerated. import ( + "bytes" "context" - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/Azure/go-autorest/autorest/to" - "github.com/Azure/go-autorest/autorest/validation" + "encoding/json" + "github.com/Azure/azure-pipeline-go/pipeline" + "io/ioutil" "net/http" ) // ObjectsClient is the the Graph RBAC Management Client type ObjectsClient struct { - BaseClient + ManagementClient } // NewObjectsClient creates an instance of the ObjectsClient client. -func NewObjectsClient(tenantID string) ObjectsClient { - return NewObjectsClientWithBaseURI(DefaultBaseURI, tenantID) -} - -// NewObjectsClientWithBaseURI creates an instance of the ObjectsClient client. -func NewObjectsClientWithBaseURI(baseURI string, tenantID string) ObjectsClient { - return ObjectsClient{NewWithBaseURI(baseURI, tenantID)} +func NewObjectsClient(p pipeline.Pipeline) ObjectsClient { + return ObjectsClient{NewManagementClient(p)} } // GetCurrentUser gets the details for the currently logged-in user. -func (client ObjectsClient) GetCurrentUser(ctx context.Context) (result AADObject, err error) { - req, err := client.GetCurrentUserPreparer(ctx) +func (client ObjectsClient) GetCurrentUser(ctx context.Context) (*AADObject, error) { + req, err := client.getCurrentUserPreparer() if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ObjectsClient", "GetCurrentUser", nil, "Failure preparing request") - return + return nil, err } - - resp, err := client.GetCurrentUserSender(req) + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.getCurrentUserResponder}, req) if err != nil { - result.Response = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "graphrbac.ObjectsClient", "GetCurrentUser", resp, "Failure sending request") - return + return nil, err } + return resp.(*AADObject), err +} - result, err = client.GetCurrentUserResponder(resp) +// getCurrentUserPreparer prepares the GetCurrentUser request. +func (client ObjectsClient) getCurrentUserPreparer() (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/me" + req, err := pipeline.NewRequest("GET", u, nil) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ObjectsClient", "GetCurrentUser", resp, "Failure responding to request") + return req, pipeline.NewError(err, "failed to create request") } - - return + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + return req, nil } -// GetCurrentUserPreparer prepares the GetCurrentUser request. -func (client ObjectsClient) GetCurrentUserPreparer(ctx context.Context) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "tenantID": autorest.Encode("path", client.TenantID), +// getCurrentUserResponder handles the response to the GetCurrentUser request. +func (client ObjectsClient) getCurrentUserResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK) + if resp == nil { + return nil, err } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, + result := &AADObject{rawResponse: resp.Response()} + if err != nil { + return result, err } - - preparer := autorest.CreatePreparer( - autorest.AsGet(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/me", pathParameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// GetCurrentUserSender sends the GetCurrentUser request. The method will close the -// http.Response Body if it receives an error. -func (client ObjectsClient) GetCurrentUserSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) -} - -// GetCurrentUserResponder handles the response to the GetCurrentUser request. The method always -// closes the http.Response Body. -func (client ObjectsClient) GetCurrentUserResponder(resp *http.Response) (result AADObject, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result), - autorest.ByClosing()) - result.Response = autorest.Response{Response: resp} - return + defer resp.Response().Body.Close() + b, err := ioutil.ReadAll(resp.Response().Body) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to read response body") + } + if len(b) > 0 { + err = json.Unmarshal(b, result) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to unmarshal response body") + } + } + return result, nil } // GetObjectsByObjectIds gets AD group membership for the specified AD object IDs. // // parameters is objects filtering parameters. -func (client ObjectsClient) GetObjectsByObjectIds(ctx context.Context, parameters GetObjectsParameters) (result GetObjectsResultPage, err error) { - if err := validation.Validate([]validation.Validation{ - {TargetValue: parameters, - Constraints: []validation.Constraint{{Target: "parameters.IncludeDirectoryObjectReferences", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { - return result, validation.NewErrorWithValidationError(err, "graphrbac.ObjectsClient", "GetObjectsByObjectIds") +func (client ObjectsClient) GetObjectsByObjectIds(ctx context.Context, parameters GetObjectsParameters) (*GetObjectsResult, error) { + if err := validate([]validation{ + {targetValue: parameters, + constraints: []constraint{{target: "parameters.IncludeDirectoryObjectReferences", name: null, rule: true, chain: nil}}}}); err != nil { + return nil, err } - - result.fn = func(lastResult GetObjectsResult) (GetObjectsResult, error) { - if lastResult.OdataNextLink == nil || len(to.String(lastResult.OdataNextLink)) < 1 { - return GetObjectsResult{}, nil - } - return client.GetObjectsByObjectIdsNext(ctx, *lastResult.OdataNextLink) + req, err := client.getObjectsByObjectIdsPreparer(parameters) + if err != nil { + return nil, err } - req, err := client.GetObjectsByObjectIdsPreparer(ctx, parameters) + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.getObjectsByObjectIdsResponder}, req) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ObjectsClient", "GetObjectsByObjectIds", nil, "Failure preparing request") - return + return nil, err } + return resp.(*GetObjectsResult), err +} - resp, err := client.GetObjectsByObjectIdsSender(req) +// getObjectsByObjectIdsPreparer prepares the GetObjectsByObjectIds request. +func (client ObjectsClient) getObjectsByObjectIdsPreparer(parameters GetObjectsParameters) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/getObjectsByObjectIds" + req, err := pipeline.NewRequest("POST", u, nil) if err != nil { - result.gor.Response = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "graphrbac.ObjectsClient", "GetObjectsByObjectIds", resp, "Failure sending request") - return + return req, pipeline.NewError(err, "failed to create request") } - - result.gor, err = client.GetObjectsByObjectIdsResponder(resp) + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + b, err := json.Marshal(parameters) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ObjectsClient", "GetObjectsByObjectIds", resp, "Failure responding to request") + return req, pipeline.NewError(err, "failed to marshal request body") } - - return + req.Header.Set("Content-Type", "application/json") + err = req.SetBody(bytes.NewReader(b)) + if err != nil { + return req, pipeline.NewError(err, "failed to set request body") + } + return req, nil } -// GetObjectsByObjectIdsPreparer prepares the GetObjectsByObjectIds request. -func (client ObjectsClient) GetObjectsByObjectIdsPreparer(ctx context.Context, parameters GetObjectsParameters) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "tenantID": autorest.Encode("path", client.TenantID), +// getObjectsByObjectIdsResponder handles the response to the GetObjectsByObjectIds request. +func (client ObjectsClient) getObjectsByObjectIdsResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK) + if resp == nil { + return nil, err } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, + result := &GetObjectsResult{rawResponse: resp.Response()} + if err != nil { + return result, err } - - preparer := autorest.CreatePreparer( - autorest.AsJSON(), - autorest.AsPost(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/getObjectsByObjectIds", pathParameters), - autorest.WithJSON(parameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// GetObjectsByObjectIdsSender sends the GetObjectsByObjectIds request. The method will close the -// http.Response Body if it receives an error. -func (client ObjectsClient) GetObjectsByObjectIdsSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) -} - -// GetObjectsByObjectIdsResponder handles the response to the GetObjectsByObjectIds request. The method always -// closes the http.Response Body. -func (client ObjectsClient) GetObjectsByObjectIdsResponder(resp *http.Response) (result GetObjectsResult, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result), - autorest.ByClosing()) - result.Response = autorest.Response{Response: resp} - return -} - -// GetObjectsByObjectIdsComplete enumerates all values, automatically crossing page boundaries as required. -func (client ObjectsClient) GetObjectsByObjectIdsComplete(ctx context.Context, parameters GetObjectsParameters) (result GetObjectsResultIterator, err error) { - result.page, err = client.GetObjectsByObjectIds(ctx, parameters) - return + defer resp.Response().Body.Close() + b, err := ioutil.ReadAll(resp.Response().Body) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to read response body") + } + if len(b) > 0 { + err = json.Unmarshal(b, result) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to unmarshal response body") + } + } + return result, nil } // GetObjectsByObjectIdsNext gets AD group membership for the specified AD object IDs. // // nextLink is next link for the list operation. -func (client ObjectsClient) GetObjectsByObjectIdsNext(ctx context.Context, nextLink string) (result GetObjectsResult, err error) { - req, err := client.GetObjectsByObjectIdsNextPreparer(ctx, nextLink) +func (client ObjectsClient) GetObjectsByObjectIdsNext(ctx context.Context, nextLink string) (*GetObjectsResult, error) { + req, err := client.getObjectsByObjectIdsNextPreparer(nextLink) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ObjectsClient", "GetObjectsByObjectIdsNext", nil, "Failure preparing request") - return + return nil, err } - - resp, err := client.GetObjectsByObjectIdsNextSender(req) + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.getObjectsByObjectIdsNextResponder}, req) if err != nil { - result.Response = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "graphrbac.ObjectsClient", "GetObjectsByObjectIdsNext", resp, "Failure sending request") - return + return nil, err } + return resp.(*GetObjectsResult), err +} - result, err = client.GetObjectsByObjectIdsNextResponder(resp) +// getObjectsByObjectIdsNextPreparer prepares the GetObjectsByObjectIdsNext request. +func (client ObjectsClient) getObjectsByObjectIdsNextPreparer(nextLink string) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/{nextLink}" + req, err := pipeline.NewRequest("POST", u, nil) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ObjectsClient", "GetObjectsByObjectIdsNext", resp, "Failure responding to request") + return req, pipeline.NewError(err, "failed to create request") } - - return + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + return req, nil } -// GetObjectsByObjectIdsNextPreparer prepares the GetObjectsByObjectIdsNext request. -func (client ObjectsClient) GetObjectsByObjectIdsNextPreparer(ctx context.Context, nextLink string) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "nextLink": nextLink, - "tenantID": autorest.Encode("path", client.TenantID), +// getObjectsByObjectIdsNextResponder handles the response to the GetObjectsByObjectIdsNext request. +func (client ObjectsClient) getObjectsByObjectIdsNextResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK) + if resp == nil { + return nil, err } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, + result := &GetObjectsResult{rawResponse: resp.Response()} + if err != nil { + return result, err } - - preparer := autorest.CreatePreparer( - autorest.AsPost(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/{nextLink}", pathParameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// GetObjectsByObjectIdsNextSender sends the GetObjectsByObjectIdsNext request. The method will close the -// http.Response Body if it receives an error. -func (client ObjectsClient) GetObjectsByObjectIdsNextSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) -} - -// GetObjectsByObjectIdsNextResponder handles the response to the GetObjectsByObjectIdsNext request. The method always -// closes the http.Response Body. -func (client ObjectsClient) GetObjectsByObjectIdsNextResponder(resp *http.Response) (result GetObjectsResult, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result), - autorest.ByClosing()) - result.Response = autorest.Response{Response: resp} - return + defer resp.Response().Body.Close() + b, err := ioutil.ReadAll(resp.Response().Body) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to read response body") + } + if len(b) > 0 { + err = json.Unmarshal(b, result) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to unmarshal response body") + } + } + return result, nil } diff --git a/services/graphrbac/1.6/graphrbac/responder_policy.go b/services/graphrbac/1.6/graphrbac/responder_policy.go new file mode 100644 index 000000000000..9ee5c82f3751 --- /dev/null +++ b/services/graphrbac/1.6/graphrbac/responder_policy.go @@ -0,0 +1,81 @@ +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" + "encoding/xml" + "github.com/Azure/azure-pipeline-go/pipeline" + "io/ioutil" +) + +type responder func(resp pipeline.Response) (result pipeline.Response, err error) + +// ResponderPolicyFactory is a Factory capable of creating a responder pipeline. +type responderPolicyFactory struct { + responder responder +} + +// New creates a responder policy factory. +func (arpf responderPolicyFactory) New(next pipeline.Policy, po *pipeline.PolicyOptions) pipeline.Policy { + return responderPolicy{next: next, responder: arpf.responder} +} + +type responderPolicy struct { + next pipeline.Policy + responder responder +} + +// Do sends the request to the service and validates/deserializes the HTTP response. +func (arp responderPolicy) Do(ctx context.Context, request pipeline.Request) (pipeline.Response, error) { + resp, err := arp.next.Do(ctx, request) + if err != nil { + return resp, err + } + return arp.responder(resp) +} + +// validateResponse checks an HTTP response's status code against a legal set of codes. +// If the response code is not legal, then validateResponse reads all of the response's body +// (containing error information) and returns a response error. +func validateResponse(resp pipeline.Response, successStatusCodes ...int) error { + if resp == nil { + return NewResponseError(nil, nil, "nil response") + } + responseCode := resp.Response().StatusCode + for _, i := range successStatusCodes { + if i == responseCode { + return nil + } + } + // only close the body in the failure case. in the + // success case responders will close the body as required. + defer resp.Response().Body.Close() + b, err := ioutil.ReadAll(resp.Response().Body) + if err != nil { + return NewResponseError(err, resp.Response(), "failed to read response body") + } + // the service code, description and details will be populated during unmarshalling + responseError := NewResponseError(nil, resp.Response(), resp.Response().Status) + if len(b) > 0 { + if err = xml.Unmarshal(b, &responseError); err != nil { + return NewResponseError(err, resp.Response(), "failed to unmarshal response body") + } + } + return responseError +} diff --git a/services/graphrbac/1.6/graphrbac/response_error.go b/services/graphrbac/1.6/graphrbac/response_error.go new file mode 100644 index 000000000000..4542dbd92a29 --- /dev/null +++ b/services/graphrbac/1.6/graphrbac/response_error.go @@ -0,0 +1,110 @@ +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 ( + "bytes" + "fmt" + "github.com/Azure/azure-pipeline-go/pipeline" + "net" + "net/http" +) + +// if you want to provide custom error handling set this variable to your constructor function +var responseErrorFactory func(cause error, response *http.Response, description string) error + +// ResponseError identifies a responder-generated network or response parsing error. +type ResponseError interface { + // Error exposes the Error(), Temporary() and Timeout() methods. + net.Error // Includes the Go error interface + + // Response returns the HTTP response. You may examine this but you should not modify it. + Response() *http.Response +} + +// NewResponseError creates an error object that implements the error interface. +func NewResponseError(cause error, response *http.Response, description string) error { + if responseErrorFactory != nil { + return responseErrorFactory(cause, response, description) + } + return &responseError{ + ErrorNode: pipeline.ErrorNode{}.Initialize(cause, 3), + response: response, + description: description, + } +} + +// responseError is the internal struct that implements the public ResponseError interface. +type responseError struct { + pipeline.ErrorNode // This is embedded so that responseError "inherits" Error, Temporary, Timeout, and Cause + response *http.Response + description string +} + +// Error implements the error interface's Error method to return a string representation of the error. +func (e *responseError) Error() string { + b := &bytes.Buffer{} + fmt.Fprintf(b, "===== RESPONSE ERROR (Code=%v) =====\n", e.response.StatusCode) + fmt.Fprintf(b, "Status=%s, Description: %s\n", e.response.Status, e.description) + s := b.String() + return e.ErrorNode.Error(s) +} + +// Response implements the ResponseError interface's method to return the HTTP response. +func (e *responseError) Response() *http.Response { + return e.response +} + +// RFC7807 PROBLEM ------------------------------------------------------------------------------------ +// RFC7807Problem ... This type can be publicly embedded in another type that wants to add additional members. +/*type RFC7807Problem struct { + // Mandatory: A (relative) URI reference identifying the problem type (it MAY refer to human-readable documentation). + typeURI string // Should default to "about:blank" + // Optional: Short, human-readable summary (maybe localized). + title string + // Optional: HTTP status code generated by the origin server + status int + // Optional: Human-readable explanation for this problem occurance. + // Should help client correct the problem. Clients should NOT parse this string. + detail string + // Optional: A (relative) URI identifying this specific problem occurence (it may or may not be dereferenced). + instance string +} +// NewRFC7807Problem ... +func NewRFC7807Problem(typeURI string, status int, titleFormat string, a ...interface{}) error { + return &RFC7807Problem{ + typeURI: typeURI, + status: status, + title: fmt.Sprintf(titleFormat, a...), + } +} +// Error returns the error information as a string. +func (e *RFC7807Problem) Error() string { + return e.title +} +// TypeURI ... +func (e *RFC7807Problem) TypeURI() string { + if e.typeURI == "" { + e.typeURI = "about:blank" + } + return e.typeURI +} +// Members ... +func (e *RFC7807Problem) Members() (status int, title, detail, instance string) { + return e.status, e.title, e.detail, e.instance +}*/ diff --git a/services/graphrbac/1.6/graphrbac/service_principals.go b/services/graphrbac/1.6/graphrbac/service_principals.go new file mode 100644 index 000000000000..35b451f8f059 --- /dev/null +++ b/services/graphrbac/1.6/graphrbac/service_principals.go @@ -0,0 +1,560 @@ +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 ( + "bytes" + "context" + "encoding/json" + "github.com/Azure/azure-pipeline-go/pipeline" + "io/ioutil" + "net/http" +) + +// ServicePrincipalsClient is the the Graph RBAC Management Client +type ServicePrincipalsClient struct { + ManagementClient +} + +// NewServicePrincipalsClient creates an instance of the ServicePrincipalsClient client. +func NewServicePrincipalsClient(p pipeline.Pipeline) ServicePrincipalsClient { + return ServicePrincipalsClient{NewManagementClient(p)} +} + +// Create creates a service principal in the directory. +// +// parameters is parameters to create a service principal. +func (client ServicePrincipalsClient) Create(ctx context.Context, parameters ServicePrincipalCreateParameters) (*ServicePrincipal, error) { + if err := validate([]validation{ + {targetValue: parameters, + constraints: []constraint{{target: "parameters.AppID", name: null, rule: true, chain: nil}, + {target: "parameters.AccountEnabled", name: null, rule: true, chain: nil}}}}); err != nil { + return nil, err + } + req, err := client.createPreparer(parameters) + if err != nil { + return nil, err + } + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.createResponder}, req) + if err != nil { + return nil, err + } + return resp.(*ServicePrincipal), err +} + +// createPreparer prepares the Create request. +func (client ServicePrincipalsClient) createPreparer(parameters ServicePrincipalCreateParameters) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/servicePrincipals" + req, err := pipeline.NewRequest("POST", u, nil) + if err != nil { + return req, pipeline.NewError(err, "failed to create request") + } + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + b, err := json.Marshal(parameters) + if err != nil { + return req, pipeline.NewError(err, "failed to marshal request body") + } + req.Header.Set("Content-Type", "application/json") + err = req.SetBody(bytes.NewReader(b)) + if err != nil { + return req, pipeline.NewError(err, "failed to set request body") + } + return req, nil +} + +// createResponder handles the response to the Create request. +func (client ServicePrincipalsClient) createResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK, http.StatusCreated) + if resp == nil { + return nil, err + } + result := &ServicePrincipal{rawResponse: resp.Response()} + if err != nil { + return result, err + } + defer resp.Response().Body.Close() + b, err := ioutil.ReadAll(resp.Response().Body) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to read response body") + } + if len(b) > 0 { + err = json.Unmarshal(b, result) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to unmarshal response body") + } + } + return result, nil +} + +// Delete deletes a service principal from the directory. +// +// objectID is the object ID of the service principal to delete. +func (client ServicePrincipalsClient) Delete(ctx context.Context, objectID string) (*http.Response, error) { + req, err := client.deletePreparer(objectID) + if err != nil { + return nil, err + } + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.deleteResponder}, req) + if err != nil { + return nil, err + } + return resp.Response(), err +} + +// deletePreparer prepares the Delete request. +func (client ServicePrincipalsClient) deletePreparer(objectID string) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/servicePrincipals/{objectId}" + req, err := pipeline.NewRequest("DELETE", u, nil) + if err != nil { + return req, pipeline.NewError(err, "failed to create request") + } + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + return req, nil +} + +// deleteResponder handles the response to the Delete request. +func (client ServicePrincipalsClient) deleteResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK, http.StatusNoContent) + if resp == nil { + return nil, err + } + return resp, err +} + +// Get gets service principal information from the directory. +// +// objectID is the object ID of the service principal to get. +func (client ServicePrincipalsClient) Get(ctx context.Context, objectID string) (*ServicePrincipal, error) { + req, err := client.getPreparer(objectID) + if err != nil { + return nil, err + } + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.getResponder}, req) + if err != nil { + return nil, err + } + return resp.(*ServicePrincipal), err +} + +// getPreparer prepares the Get request. +func (client ServicePrincipalsClient) getPreparer(objectID string) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/servicePrincipals/{objectId}" + req, err := pipeline.NewRequest("GET", u, nil) + if err != nil { + return req, pipeline.NewError(err, "failed to create request") + } + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + return req, nil +} + +// getResponder handles the response to the Get request. +func (client ServicePrincipalsClient) getResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK) + if resp == nil { + return nil, err + } + result := &ServicePrincipal{rawResponse: resp.Response()} + if err != nil { + return result, err + } + defer resp.Response().Body.Close() + b, err := ioutil.ReadAll(resp.Response().Body) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to read response body") + } + if len(b) > 0 { + err = json.Unmarshal(b, result) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to unmarshal response body") + } + } + return result, nil +} + +// List gets a list of service principals from the current tenant. +// +// filter is the filter to apply to the operation. +func (client ServicePrincipalsClient) List(ctx context.Context, filter *string) (*ServicePrincipalListResult, error) { + req, err := client.listPreparer(filter) + if err != nil { + return nil, err + } + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.listResponder}, req) + if err != nil { + return nil, err + } + return resp.(*ServicePrincipalListResult), err +} + +// listPreparer prepares the List request. +func (client ServicePrincipalsClient) listPreparer(filter *string) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/servicePrincipals" + req, err := pipeline.NewRequest("GET", u, nil) + if err != nil { + return req, pipeline.NewError(err, "failed to create request") + } + params := req.URL.Query() + if filter != nil { + params.Set("$filter", *filter) + } + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + return req, nil +} + +// listResponder handles the response to the List request. +func (client ServicePrincipalsClient) listResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK) + if resp == nil { + return nil, err + } + result := &ServicePrincipalListResult{rawResponse: resp.Response()} + if err != nil { + return result, err + } + defer resp.Response().Body.Close() + b, err := ioutil.ReadAll(resp.Response().Body) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to read response body") + } + if len(b) > 0 { + err = json.Unmarshal(b, result) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to unmarshal response body") + } + } + return result, nil +} + +// ListKeyCredentials get the keyCredentials associated with the specified service principal. +// +// objectID is the object ID of the service principal for which to get keyCredentials. +func (client ServicePrincipalsClient) ListKeyCredentials(ctx context.Context, objectID string) (*KeyCredentialListResult, error) { + req, err := client.listKeyCredentialsPreparer(objectID) + if err != nil { + return nil, err + } + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.listKeyCredentialsResponder}, req) + if err != nil { + return nil, err + } + return resp.(*KeyCredentialListResult), err +} + +// listKeyCredentialsPreparer prepares the ListKeyCredentials request. +func (client ServicePrincipalsClient) listKeyCredentialsPreparer(objectID string) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/servicePrincipals/{objectId}/keyCredentials" + req, err := pipeline.NewRequest("GET", u, nil) + if err != nil { + return req, pipeline.NewError(err, "failed to create request") + } + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + return req, nil +} + +// listKeyCredentialsResponder handles the response to the ListKeyCredentials request. +func (client ServicePrincipalsClient) listKeyCredentialsResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK) + if resp == nil { + return nil, err + } + result := &KeyCredentialListResult{rawResponse: resp.Response()} + if err != nil { + return result, err + } + defer resp.Response().Body.Close() + b, err := ioutil.ReadAll(resp.Response().Body) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to read response body") + } + if len(b) > 0 { + err = json.Unmarshal(b, result) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to unmarshal response body") + } + } + return result, nil +} + +// ListNext gets a list of service principals from the current tenant. +// +// nextLink is next link for the list operation. +func (client ServicePrincipalsClient) ListNext(ctx context.Context, nextLink string) (*ServicePrincipalListResult, error) { + req, err := client.listNextPreparer(nextLink) + if err != nil { + return nil, err + } + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.listNextResponder}, req) + if err != nil { + return nil, err + } + return resp.(*ServicePrincipalListResult), err +} + +// listNextPreparer prepares the ListNext request. +func (client ServicePrincipalsClient) listNextPreparer(nextLink string) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/{nextLink}" + req, err := pipeline.NewRequest("GET", u, nil) + if err != nil { + return req, pipeline.NewError(err, "failed to create request") + } + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + return req, nil +} + +// listNextResponder handles the response to the ListNext request. +func (client ServicePrincipalsClient) listNextResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK) + if resp == nil { + return nil, err + } + result := &ServicePrincipalListResult{rawResponse: resp.Response()} + if err != nil { + return result, err + } + defer resp.Response().Body.Close() + b, err := ioutil.ReadAll(resp.Response().Body) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to read response body") + } + if len(b) > 0 { + err = json.Unmarshal(b, result) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to unmarshal response body") + } + } + return result, nil +} + +// ListOwners the owners are a set of non-admin users who are allowed to modify this object. +// +// objectID is the object ID of the service principal for which to get owners. +func (client ServicePrincipalsClient) ListOwners(ctx context.Context, objectID string) (*DirectoryObjectListResult, error) { + req, err := client.listOwnersPreparer(objectID) + if err != nil { + return nil, err + } + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.listOwnersResponder}, req) + if err != nil { + return nil, err + } + return resp.(*DirectoryObjectListResult), err +} + +// listOwnersPreparer prepares the ListOwners request. +func (client ServicePrincipalsClient) listOwnersPreparer(objectID string) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/servicePrincipals/{objectId}/owners" + req, err := pipeline.NewRequest("GET", u, nil) + if err != nil { + return req, pipeline.NewError(err, "failed to create request") + } + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + return req, nil +} + +// listOwnersResponder handles the response to the ListOwners request. +func (client ServicePrincipalsClient) listOwnersResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK) + if resp == nil { + return nil, err + } + result := &DirectoryObjectListResult{rawResponse: resp.Response()} + if err != nil { + return result, err + } + defer resp.Response().Body.Close() + b, err := ioutil.ReadAll(resp.Response().Body) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to read response body") + } + if len(b) > 0 { + err = json.Unmarshal(b, result) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to unmarshal response body") + } + } + return result, nil +} + +// ListPasswordCredentials gets the passwordCredentials associated with a service principal. +// +// objectID is the object ID of the service principal. +func (client ServicePrincipalsClient) ListPasswordCredentials(ctx context.Context, objectID string) (*PasswordCredentialListResult, error) { + req, err := client.listPasswordCredentialsPreparer(objectID) + if err != nil { + return nil, err + } + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.listPasswordCredentialsResponder}, req) + if err != nil { + return nil, err + } + return resp.(*PasswordCredentialListResult), err +} + +// listPasswordCredentialsPreparer prepares the ListPasswordCredentials request. +func (client ServicePrincipalsClient) listPasswordCredentialsPreparer(objectID string) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/servicePrincipals/{objectId}/passwordCredentials" + req, err := pipeline.NewRequest("GET", u, nil) + if err != nil { + return req, pipeline.NewError(err, "failed to create request") + } + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + return req, nil +} + +// listPasswordCredentialsResponder handles the response to the ListPasswordCredentials request. +func (client ServicePrincipalsClient) listPasswordCredentialsResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK) + if resp == nil { + return nil, err + } + result := &PasswordCredentialListResult{rawResponse: resp.Response()} + if err != nil { + return result, err + } + defer resp.Response().Body.Close() + b, err := ioutil.ReadAll(resp.Response().Body) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to read response body") + } + if len(b) > 0 { + err = json.Unmarshal(b, result) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to unmarshal response body") + } + } + return result, nil +} + +// UpdateKeyCredentials update the keyCredentials associated with a service principal. +// +// objectID is the object ID for which to get service principal information. parameters is parameters to update the +// keyCredentials of an existing service principal. +func (client ServicePrincipalsClient) UpdateKeyCredentials(ctx context.Context, objectID string, parameters KeyCredentialsUpdateParameters) (*http.Response, error) { + req, err := client.updateKeyCredentialsPreparer(objectID, parameters) + if err != nil { + return nil, err + } + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.updateKeyCredentialsResponder}, req) + if err != nil { + return nil, err + } + return resp.Response(), err +} + +// updateKeyCredentialsPreparer prepares the UpdateKeyCredentials request. +func (client ServicePrincipalsClient) updateKeyCredentialsPreparer(objectID string, parameters KeyCredentialsUpdateParameters) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/servicePrincipals/{objectId}/keyCredentials" + req, err := pipeline.NewRequest("PATCH", u, nil) + if err != nil { + return req, pipeline.NewError(err, "failed to create request") + } + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + b, err := json.Marshal(parameters) + if err != nil { + return req, pipeline.NewError(err, "failed to marshal request body") + } + req.Header.Set("Content-Type", "application/json") + err = req.SetBody(bytes.NewReader(b)) + if err != nil { + return req, pipeline.NewError(err, "failed to set request body") + } + return req, nil +} + +// updateKeyCredentialsResponder handles the response to the UpdateKeyCredentials request. +func (client ServicePrincipalsClient) updateKeyCredentialsResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK, http.StatusNoContent) + if resp == nil { + return nil, err + } + return resp, err +} + +// UpdatePasswordCredentials updates the passwordCredentials associated with a service principal. +// +// objectID is the object ID of the service principal. parameters is parameters to update the passwordCredentials of an +// existing service principal. +func (client ServicePrincipalsClient) UpdatePasswordCredentials(ctx context.Context, objectID string, parameters PasswordCredentialsUpdateParameters) (*http.Response, error) { + req, err := client.updatePasswordCredentialsPreparer(objectID, parameters) + if err != nil { + return nil, err + } + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.updatePasswordCredentialsResponder}, req) + if err != nil { + return nil, err + } + return resp.Response(), err +} + +// updatePasswordCredentialsPreparer prepares the UpdatePasswordCredentials request. +func (client ServicePrincipalsClient) updatePasswordCredentialsPreparer(objectID string, parameters PasswordCredentialsUpdateParameters) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/servicePrincipals/{objectId}/passwordCredentials" + req, err := pipeline.NewRequest("PATCH", u, nil) + if err != nil { + return req, pipeline.NewError(err, "failed to create request") + } + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + b, err := json.Marshal(parameters) + if err != nil { + return req, pipeline.NewError(err, "failed to marshal request body") + } + req.Header.Set("Content-Type", "application/json") + err = req.SetBody(bytes.NewReader(b)) + if err != nil { + return req, pipeline.NewError(err, "failed to set request body") + } + return req, nil +} + +// updatePasswordCredentialsResponder handles the response to the UpdatePasswordCredentials request. +func (client ServicePrincipalsClient) updatePasswordCredentialsResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK, http.StatusNoContent) + if resp == nil { + return nil, err + } + return resp, err +} diff --git a/services/graphrbac/1.6/graphrbac/serviceprincipals.go b/services/graphrbac/1.6/graphrbac/serviceprincipals.go deleted file mode 100644 index 8a9e7c66faee..000000000000 --- a/services/graphrbac/1.6/graphrbac/serviceprincipals.go +++ /dev/null @@ -1,717 +0,0 @@ -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" - "github.com/Azure/go-autorest/autorest/to" - "github.com/Azure/go-autorest/autorest/validation" - "net/http" -) - -// ServicePrincipalsClient is the the Graph RBAC Management Client -type ServicePrincipalsClient struct { - BaseClient -} - -// NewServicePrincipalsClient creates an instance of the ServicePrincipalsClient client. -func NewServicePrincipalsClient(tenantID string) ServicePrincipalsClient { - return NewServicePrincipalsClientWithBaseURI(DefaultBaseURI, tenantID) -} - -// NewServicePrincipalsClientWithBaseURI creates an instance of the ServicePrincipalsClient client. -func NewServicePrincipalsClientWithBaseURI(baseURI string, tenantID string) ServicePrincipalsClient { - return ServicePrincipalsClient{NewWithBaseURI(baseURI, tenantID)} -} - -// Create creates a service principal in the directory. -// -// parameters is parameters to create a service principal. -func (client ServicePrincipalsClient) Create(ctx context.Context, parameters ServicePrincipalCreateParameters) (result ServicePrincipal, err error) { - if err := validation.Validate([]validation.Validation{ - {TargetValue: parameters, - Constraints: []validation.Constraint{{Target: "parameters.AppID", Name: validation.Null, Rule: true, Chain: nil}, - {Target: "parameters.AccountEnabled", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { - return result, validation.NewErrorWithValidationError(err, "graphrbac.ServicePrincipalsClient", "Create") - } - - req, err := client.CreatePreparer(ctx, parameters) - if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "Create", nil, "Failure preparing request") - return - } - - resp, err := client.CreateSender(req) - if err != nil { - result.Response = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "Create", resp, "Failure sending request") - return - } - - result, err = client.CreateResponder(resp) - if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "Create", resp, "Failure responding to request") - } - - return -} - -// CreatePreparer prepares the Create request. -func (client ServicePrincipalsClient) CreatePreparer(ctx context.Context, parameters ServicePrincipalCreateParameters) (*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.AsJSON(), - autorest.AsPost(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/servicePrincipals", pathParameters), - autorest.WithJSON(parameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// CreateSender sends the Create request. The method will close the -// http.Response Body if it receives an error. -func (client ServicePrincipalsClient) CreateSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) -} - -// CreateResponder handles the response to the Create request. The method always -// closes the http.Response Body. -func (client ServicePrincipalsClient) CreateResponder(resp *http.Response) (result ServicePrincipal, 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 -} - -// Delete deletes a service principal from the directory. -// -// objectID is the object ID of the service principal to delete. -func (client ServicePrincipalsClient) Delete(ctx context.Context, objectID string) (result autorest.Response, err error) { - req, err := client.DeletePreparer(ctx, objectID) - if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "Delete", nil, "Failure preparing request") - return - } - - resp, err := client.DeleteSender(req) - if err != nil { - result.Response = resp - err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "Delete", resp, "Failure sending request") - return - } - - result, err = client.DeleteResponder(resp) - if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "Delete", resp, "Failure responding to request") - } - - return -} - -// DeletePreparer prepares the Delete request. -func (client ServicePrincipalsClient) DeletePreparer(ctx context.Context, objectID string) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "objectId": autorest.Encode("path", objectID), - "tenantID": autorest.Encode("path", client.TenantID), - } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsDelete(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/servicePrincipals/{objectId}", pathParameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// DeleteSender sends the Delete request. The method will close the -// http.Response Body if it receives an error. -func (client ServicePrincipalsClient) DeleteSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) -} - -// DeleteResponder handles the response to the Delete request. The method always -// closes the http.Response Body. -func (client ServicePrincipalsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), - autorest.ByClosing()) - result.Response = resp - return -} - -// Get gets service principal information from the directory. -// -// objectID is the object ID of the service principal to get. -func (client ServicePrincipalsClient) Get(ctx context.Context, objectID string) (result ServicePrincipal, err error) { - req, err := client.GetPreparer(ctx, objectID) - if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "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.ServicePrincipalsClient", "Get", resp, "Failure sending request") - return - } - - result, err = client.GetResponder(resp) - if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "Get", resp, "Failure responding to request") - } - - return -} - -// GetPreparer prepares the Get request. -func (client ServicePrincipalsClient) GetPreparer(ctx context.Context, objectID string) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "objectId": autorest.Encode("path", objectID), - "tenantID": autorest.Encode("path", client.TenantID), - } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsGet(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/servicePrincipals/{objectId}", 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 ServicePrincipalsClient) 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 ServicePrincipalsClient) GetResponder(resp *http.Response) (result ServicePrincipal, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result), - autorest.ByClosing()) - result.Response = autorest.Response{Response: resp} - return -} - -// List gets a list of service principals from the current tenant. -// -// filter is the filter to apply to the operation. -func (client ServicePrincipalsClient) List(ctx context.Context, filter string) (result ServicePrincipalListResultPage, err error) { - result.fn = func(lastResult ServicePrincipalListResult) (ServicePrincipalListResult, error) { - if lastResult.OdataNextLink == nil || len(to.String(lastResult.OdataNextLink)) < 1 { - return ServicePrincipalListResult{}, nil - } - return client.ListNext(ctx, *lastResult.OdataNextLink) - } - req, err := client.ListPreparer(ctx, filter) - if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "List", nil, "Failure preparing request") - return - } - - resp, err := client.ListSender(req) - if err != nil { - result.splr.Response = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "List", resp, "Failure sending request") - return - } - - result.splr, err = client.ListResponder(resp) - if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "List", resp, "Failure responding to request") - } - - return -} - -// ListPreparer prepares the List request. -func (client ServicePrincipalsClient) ListPreparer(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}/servicePrincipals", pathParameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// ListSender sends the List request. The method will close the -// http.Response Body if it receives an error. -func (client ServicePrincipalsClient) ListSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) -} - -// ListResponder handles the response to the List request. The method always -// closes the http.Response Body. -func (client ServicePrincipalsClient) ListResponder(resp *http.Response) (result ServicePrincipalListResult, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result), - autorest.ByClosing()) - result.Response = autorest.Response{Response: resp} - return -} - -// ListComplete enumerates all values, automatically crossing page boundaries as required. -func (client ServicePrincipalsClient) ListComplete(ctx context.Context, filter string) (result ServicePrincipalListResultIterator, err error) { - result.page, err = client.List(ctx, filter) - return -} - -// ListKeyCredentials get the keyCredentials associated with the specified service principal. -// -// objectID is the object ID of the service principal for which to get keyCredentials. -func (client ServicePrincipalsClient) ListKeyCredentials(ctx context.Context, objectID string) (result KeyCredentialListResult, err error) { - req, err := client.ListKeyCredentialsPreparer(ctx, objectID) - if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "ListKeyCredentials", nil, "Failure preparing request") - return - } - - resp, err := client.ListKeyCredentialsSender(req) - if err != nil { - result.Response = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "ListKeyCredentials", resp, "Failure sending request") - return - } - - result, err = client.ListKeyCredentialsResponder(resp) - if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "ListKeyCredentials", resp, "Failure responding to request") - } - - return -} - -// ListKeyCredentialsPreparer prepares the ListKeyCredentials request. -func (client ServicePrincipalsClient) ListKeyCredentialsPreparer(ctx context.Context, objectID string) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "objectId": autorest.Encode("path", objectID), - "tenantID": autorest.Encode("path", client.TenantID), - } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsGet(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/servicePrincipals/{objectId}/keyCredentials", pathParameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// ListKeyCredentialsSender sends the ListKeyCredentials request. The method will close the -// http.Response Body if it receives an error. -func (client ServicePrincipalsClient) ListKeyCredentialsSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) -} - -// ListKeyCredentialsResponder handles the response to the ListKeyCredentials request. The method always -// closes the http.Response Body. -func (client ServicePrincipalsClient) ListKeyCredentialsResponder(resp *http.Response) (result KeyCredentialListResult, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result), - autorest.ByClosing()) - result.Response = autorest.Response{Response: resp} - return -} - -// ListNext gets a list of service principals from the current tenant. -// -// nextLink is next link for the list operation. -func (client ServicePrincipalsClient) ListNext(ctx context.Context, nextLink string) (result ServicePrincipalListResult, err error) { - req, err := client.ListNextPreparer(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "ListNext", nil, "Failure preparing request") - return - } - - resp, err := client.ListNextSender(req) - if err != nil { - result.Response = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "ListNext", resp, "Failure sending request") - return - } - - result, err = client.ListNextResponder(resp) - if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "ListNext", resp, "Failure responding to request") - } - - return -} - -// ListNextPreparer prepares the ListNext request. -func (client ServicePrincipalsClient) ListNextPreparer(ctx context.Context, nextLink string) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "nextLink": nextLink, - "tenantID": autorest.Encode("path", client.TenantID), - } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsGet(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/{nextLink}", pathParameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// ListNextSender sends the ListNext request. The method will close the -// http.Response Body if it receives an error. -func (client ServicePrincipalsClient) ListNextSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) -} - -// ListNextResponder handles the response to the ListNext request. The method always -// closes the http.Response Body. -func (client ServicePrincipalsClient) ListNextResponder(resp *http.Response) (result ServicePrincipalListResult, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result), - autorest.ByClosing()) - result.Response = autorest.Response{Response: resp} - return -} - -// ListOwners the owners are a set of non-admin users who are allowed to modify this object. -// -// objectID is the object ID of the service principal for which to get owners. -func (client ServicePrincipalsClient) ListOwners(ctx context.Context, objectID string) (result DirectoryObjectListResult, err error) { - req, err := client.ListOwnersPreparer(ctx, objectID) - if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "ListOwners", nil, "Failure preparing request") - return - } - - resp, err := client.ListOwnersSender(req) - if err != nil { - result.Response = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "ListOwners", resp, "Failure sending request") - return - } - - result, err = client.ListOwnersResponder(resp) - if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "ListOwners", resp, "Failure responding to request") - } - - return -} - -// ListOwnersPreparer prepares the ListOwners request. -func (client ServicePrincipalsClient) ListOwnersPreparer(ctx context.Context, objectID string) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "objectId": autorest.Encode("path", objectID), - "tenantID": autorest.Encode("path", client.TenantID), - } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsGet(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/servicePrincipals/{objectId}/owners", pathParameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// ListOwnersSender sends the ListOwners request. The method will close the -// http.Response Body if it receives an error. -func (client ServicePrincipalsClient) ListOwnersSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) -} - -// ListOwnersResponder handles the response to the ListOwners request. The method always -// closes the http.Response Body. -func (client ServicePrincipalsClient) ListOwnersResponder(resp *http.Response) (result DirectoryObjectListResult, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result), - autorest.ByClosing()) - result.Response = autorest.Response{Response: resp} - return -} - -// ListPasswordCredentials gets the passwordCredentials associated with a service principal. -// -// objectID is the object ID of the service principal. -func (client ServicePrincipalsClient) ListPasswordCredentials(ctx context.Context, objectID string) (result PasswordCredentialListResult, err error) { - req, err := client.ListPasswordCredentialsPreparer(ctx, objectID) - if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "ListPasswordCredentials", nil, "Failure preparing request") - return - } - - resp, err := client.ListPasswordCredentialsSender(req) - if err != nil { - result.Response = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "ListPasswordCredentials", resp, "Failure sending request") - return - } - - result, err = client.ListPasswordCredentialsResponder(resp) - if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "ListPasswordCredentials", resp, "Failure responding to request") - } - - return -} - -// ListPasswordCredentialsPreparer prepares the ListPasswordCredentials request. -func (client ServicePrincipalsClient) ListPasswordCredentialsPreparer(ctx context.Context, objectID string) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "objectId": autorest.Encode("path", objectID), - "tenantID": autorest.Encode("path", client.TenantID), - } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsGet(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/servicePrincipals/{objectId}/passwordCredentials", pathParameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// ListPasswordCredentialsSender sends the ListPasswordCredentials request. The method will close the -// http.Response Body if it receives an error. -func (client ServicePrincipalsClient) ListPasswordCredentialsSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) -} - -// ListPasswordCredentialsResponder handles the response to the ListPasswordCredentials request. The method always -// closes the http.Response Body. -func (client ServicePrincipalsClient) ListPasswordCredentialsResponder(resp *http.Response) (result PasswordCredentialListResult, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result), - autorest.ByClosing()) - result.Response = autorest.Response{Response: resp} - return -} - -// UpdateKeyCredentials update the keyCredentials associated with a service principal. -// -// objectID is the object ID for which to get service principal information. parameters is parameters to update the -// keyCredentials of an existing service principal. -func (client ServicePrincipalsClient) UpdateKeyCredentials(ctx context.Context, objectID string, parameters KeyCredentialsUpdateParameters) (result autorest.Response, err error) { - req, err := client.UpdateKeyCredentialsPreparer(ctx, objectID, parameters) - if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "UpdateKeyCredentials", nil, "Failure preparing request") - return - } - - resp, err := client.UpdateKeyCredentialsSender(req) - if err != nil { - result.Response = resp - err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "UpdateKeyCredentials", resp, "Failure sending request") - return - } - - result, err = client.UpdateKeyCredentialsResponder(resp) - if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "UpdateKeyCredentials", resp, "Failure responding to request") - } - - return -} - -// UpdateKeyCredentialsPreparer prepares the UpdateKeyCredentials request. -func (client ServicePrincipalsClient) UpdateKeyCredentialsPreparer(ctx context.Context, objectID string, parameters KeyCredentialsUpdateParameters) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "objectId": autorest.Encode("path", objectID), - "tenantID": autorest.Encode("path", client.TenantID), - } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsJSON(), - autorest.AsPatch(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/servicePrincipals/{objectId}/keyCredentials", pathParameters), - autorest.WithJSON(parameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// UpdateKeyCredentialsSender sends the UpdateKeyCredentials request. The method will close the -// http.Response Body if it receives an error. -func (client ServicePrincipalsClient) UpdateKeyCredentialsSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) -} - -// UpdateKeyCredentialsResponder handles the response to the UpdateKeyCredentials request. The method always -// closes the http.Response Body. -func (client ServicePrincipalsClient) UpdateKeyCredentialsResponder(resp *http.Response) (result autorest.Response, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), - autorest.ByClosing()) - result.Response = resp - return -} - -// UpdatePasswordCredentials updates the passwordCredentials associated with a service principal. -// -// objectID is the object ID of the service principal. parameters is parameters to update the passwordCredentials of an -// existing service principal. -func (client ServicePrincipalsClient) UpdatePasswordCredentials(ctx context.Context, objectID string, parameters PasswordCredentialsUpdateParameters) (result autorest.Response, err error) { - req, err := client.UpdatePasswordCredentialsPreparer(ctx, objectID, parameters) - if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "UpdatePasswordCredentials", nil, "Failure preparing request") - return - } - - resp, err := client.UpdatePasswordCredentialsSender(req) - if err != nil { - result.Response = resp - err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "UpdatePasswordCredentials", resp, "Failure sending request") - return - } - - result, err = client.UpdatePasswordCredentialsResponder(resp) - if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "UpdatePasswordCredentials", resp, "Failure responding to request") - } - - return -} - -// UpdatePasswordCredentialsPreparer prepares the UpdatePasswordCredentials request. -func (client ServicePrincipalsClient) UpdatePasswordCredentialsPreparer(ctx context.Context, objectID string, parameters PasswordCredentialsUpdateParameters) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "objectId": autorest.Encode("path", objectID), - "tenantID": autorest.Encode("path", client.TenantID), - } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsJSON(), - autorest.AsPatch(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/servicePrincipals/{objectId}/passwordCredentials", pathParameters), - autorest.WithJSON(parameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// UpdatePasswordCredentialsSender sends the UpdatePasswordCredentials request. The method will close the -// http.Response Body if it receives an error. -func (client ServicePrincipalsClient) UpdatePasswordCredentialsSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) -} - -// UpdatePasswordCredentialsResponder handles the response to the UpdatePasswordCredentials request. The method always -// closes the http.Response Body. -func (client ServicePrincipalsClient) UpdatePasswordCredentialsResponder(resp *http.Response) (result autorest.Response, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), - autorest.ByClosing()) - result.Response = resp - return -} diff --git a/services/graphrbac/1.6/graphrbac/users.go b/services/graphrbac/1.6/graphrbac/users.go index ad1350f64c97..89699ab4270b 100644 --- a/services/graphrbac/1.6/graphrbac/users.go +++ b/services/graphrbac/1.6/graphrbac/users.go @@ -18,515 +18,407 @@ package graphrbac // Changes may cause incorrect behavior and will be lost if the code is regenerated. import ( + "bytes" "context" - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/Azure/go-autorest/autorest/to" - "github.com/Azure/go-autorest/autorest/validation" + "encoding/json" + "github.com/Azure/azure-pipeline-go/pipeline" + "io/ioutil" "net/http" ) // UsersClient is the the Graph RBAC Management Client type UsersClient struct { - BaseClient + ManagementClient } // NewUsersClient creates an instance of the UsersClient client. -func NewUsersClient(tenantID string) UsersClient { - return NewUsersClientWithBaseURI(DefaultBaseURI, tenantID) -} - -// NewUsersClientWithBaseURI creates an instance of the UsersClient client. -func NewUsersClientWithBaseURI(baseURI string, tenantID string) UsersClient { - return UsersClient{NewWithBaseURI(baseURI, tenantID)} +func NewUsersClient(p pipeline.Pipeline) UsersClient { + return UsersClient{NewManagementClient(p)} } // Create create a new user. // // parameters is parameters to create a user. -func (client UsersClient) Create(ctx context.Context, parameters UserCreateParameters) (result User, err error) { - if err := validation.Validate([]validation.Validation{ - {TargetValue: parameters, - Constraints: []validation.Constraint{{Target: "parameters.AccountEnabled", Name: validation.Null, Rule: true, Chain: nil}, - {Target: "parameters.DisplayName", Name: validation.Null, Rule: true, Chain: nil}, - {Target: "parameters.PasswordProfile", Name: validation.Null, Rule: true, - Chain: []validation.Constraint{{Target: "parameters.PasswordProfile.Password", Name: validation.Null, Rule: true, Chain: nil}}}, - {Target: "parameters.UserPrincipalName", Name: validation.Null, Rule: true, Chain: nil}, - {Target: "parameters.MailNickname", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { - return result, validation.NewErrorWithValidationError(err, "graphrbac.UsersClient", "Create") +func (client UsersClient) Create(ctx context.Context, parameters UserCreateParameters) (*User, error) { + if err := validate([]validation{ + {targetValue: parameters, + constraints: []constraint{{target: "parameters.AccountEnabled", name: null, rule: true, chain: nil}, + {target: "parameters.DisplayName", name: null, rule: true, chain: nil}, + {target: "parameters.PasswordProfile", name: null, rule: true, + chain: []constraint{{target: "parameters.PasswordProfile.Password", name: null, rule: true, chain: nil}}}, + {target: "parameters.UserPrincipalName", name: null, rule: true, chain: nil}, + {target: "parameters.MailNickname", name: null, rule: true, chain: nil}}}}); err != nil { + return nil, err + } + req, err := client.createPreparer(parameters) + if err != nil { + return nil, err } - - req, err := client.CreatePreparer(ctx, parameters) + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.createResponder}, req) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.UsersClient", "Create", nil, "Failure preparing request") - return + return nil, err } + return resp.(*User), err +} - resp, err := client.CreateSender(req) +// createPreparer prepares the Create request. +func (client UsersClient) createPreparer(parameters UserCreateParameters) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/users" + req, err := pipeline.NewRequest("POST", u, nil) if err != nil { - result.Response = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "graphrbac.UsersClient", "Create", resp, "Failure sending request") - return + return req, pipeline.NewError(err, "failed to create request") } - - result, err = client.CreateResponder(resp) + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + b, err := json.Marshal(parameters) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.UsersClient", "Create", resp, "Failure responding to request") + return req, pipeline.NewError(err, "failed to marshal request body") } - - return + req.Header.Set("Content-Type", "application/json") + err = req.SetBody(bytes.NewReader(b)) + if err != nil { + return req, pipeline.NewError(err, "failed to set request body") + } + return req, nil } -// CreatePreparer prepares the Create request. -func (client UsersClient) CreatePreparer(ctx context.Context, parameters UserCreateParameters) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "tenantID": autorest.Encode("path", client.TenantID), +// createResponder handles the response to the Create request. +func (client UsersClient) createResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK, http.StatusCreated) + if resp == nil { + return nil, err } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, + result := &User{rawResponse: resp.Response()} + if err != nil { + return result, err } - - preparer := autorest.CreatePreparer( - autorest.AsJSON(), - autorest.AsPost(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/users", pathParameters), - autorest.WithJSON(parameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// CreateSender sends the Create request. The method will close the -// http.Response Body if it receives an error. -func (client UsersClient) CreateSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) -} - -// CreateResponder handles the response to the Create request. The method always -// closes the http.Response Body. -func (client UsersClient) CreateResponder(resp *http.Response) (result User, 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 + defer resp.Response().Body.Close() + b, err := ioutil.ReadAll(resp.Response().Body) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to read response body") + } + if len(b) > 0 { + err = json.Unmarshal(b, result) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to unmarshal response body") + } + } + return result, nil } // Delete delete a user. // // upnOrObjectID is the object ID or principal name of the user to delete. -func (client UsersClient) Delete(ctx context.Context, upnOrObjectID string) (result autorest.Response, err error) { - req, err := client.DeletePreparer(ctx, upnOrObjectID) +func (client UsersClient) Delete(ctx context.Context, upnOrObjectID string) (*http.Response, error) { + req, err := client.deletePreparer(upnOrObjectID) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.UsersClient", "Delete", nil, "Failure preparing request") - return + return nil, err } - - resp, err := client.DeleteSender(req) + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.deleteResponder}, req) if err != nil { - result.Response = resp - err = autorest.NewErrorWithError(err, "graphrbac.UsersClient", "Delete", resp, "Failure sending request") - return + return nil, err } + return resp.Response(), err +} - result, err = client.DeleteResponder(resp) +// deletePreparer prepares the Delete request. +func (client UsersClient) deletePreparer(upnOrObjectID string) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/users/{upnOrObjectId}" + req, err := pipeline.NewRequest("DELETE", u, nil) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.UsersClient", "Delete", resp, "Failure responding to request") + return req, pipeline.NewError(err, "failed to create request") } - - return + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + return req, nil } -// DeletePreparer prepares the Delete request. -func (client UsersClient) DeletePreparer(ctx context.Context, upnOrObjectID string) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "tenantID": autorest.Encode("path", client.TenantID), - "upnOrObjectId": autorest.Encode("path", upnOrObjectID), - } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, +// deleteResponder handles the response to the Delete request. +func (client UsersClient) deleteResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK, http.StatusNoContent) + if resp == nil { + return nil, err } - - preparer := autorest.CreatePreparer( - autorest.AsDelete(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/users/{upnOrObjectId}", pathParameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// DeleteSender sends the Delete request. The method will close the -// http.Response Body if it receives an error. -func (client UsersClient) DeleteSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) -} - -// DeleteResponder handles the response to the Delete request. The method always -// closes the http.Response Body. -func (client UsersClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), - autorest.ByClosing()) - result.Response = resp - return + return resp, err } // Get gets user information from the directory. // // upnOrObjectID is the object ID or principal name of the user for which to get information. -func (client UsersClient) Get(ctx context.Context, upnOrObjectID string) (result User, err error) { - req, err := client.GetPreparer(ctx, upnOrObjectID) +func (client UsersClient) Get(ctx context.Context, upnOrObjectID string) (*User, error) { + req, err := client.getPreparer(upnOrObjectID) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.UsersClient", "Get", nil, "Failure preparing request") - return + return nil, err } - - resp, err := client.GetSender(req) + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.getResponder}, req) if err != nil { - result.Response = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "graphrbac.UsersClient", "Get", resp, "Failure sending request") - return + return nil, err } + return resp.(*User), err +} - result, err = client.GetResponder(resp) +// getPreparer prepares the Get request. +func (client UsersClient) getPreparer(upnOrObjectID string) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/users/{upnOrObjectId}" + req, err := pipeline.NewRequest("GET", u, nil) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.UsersClient", "Get", resp, "Failure responding to request") + return req, pipeline.NewError(err, "failed to create request") } - - return + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + return req, nil } -// GetPreparer prepares the Get request. -func (client UsersClient) GetPreparer(ctx context.Context, upnOrObjectID string) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "tenantID": autorest.Encode("path", client.TenantID), - "upnOrObjectId": autorest.Encode("path", upnOrObjectID), +// getResponder handles the response to the Get request. +func (client UsersClient) getResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK) + if resp == nil { + return nil, err } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, + result := &User{rawResponse: resp.Response()} + if err != nil { + return result, err } - - preparer := autorest.CreatePreparer( - autorest.AsGet(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/users/{upnOrObjectId}", 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 UsersClient) 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 UsersClient) GetResponder(resp *http.Response) (result User, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result), - autorest.ByClosing()) - result.Response = autorest.Response{Response: resp} - return + defer resp.Response().Body.Close() + b, err := ioutil.ReadAll(resp.Response().Body) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to read response body") + } + if len(b) > 0 { + err = json.Unmarshal(b, result) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to unmarshal response body") + } + } + return result, nil } // GetMemberGroups gets a collection that contains the object IDs of the groups of which the user is a member. // // objectID is the object ID of the user for which to get group membership. parameters is user filtering parameters. -func (client UsersClient) GetMemberGroups(ctx context.Context, objectID string, parameters UserGetMemberGroupsParameters) (result UserGetMemberGroupsResult, err error) { - if err := validation.Validate([]validation.Validation{ - {TargetValue: parameters, - Constraints: []validation.Constraint{{Target: "parameters.SecurityEnabledOnly", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { - return result, validation.NewErrorWithValidationError(err, "graphrbac.UsersClient", "GetMemberGroups") +func (client UsersClient) GetMemberGroups(ctx context.Context, objectID string, parameters UserGetMemberGroupsParameters) (*UserGetMemberGroupsResult, error) { + if err := validate([]validation{ + {targetValue: parameters, + constraints: []constraint{{target: "parameters.SecurityEnabledOnly", name: null, rule: true, chain: nil}}}}); err != nil { + return nil, err } - - req, err := client.GetMemberGroupsPreparer(ctx, objectID, parameters) + req, err := client.getMemberGroupsPreparer(objectID, parameters) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.UsersClient", "GetMemberGroups", nil, "Failure preparing request") - return + return nil, err } - - resp, err := client.GetMemberGroupsSender(req) + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.getMemberGroupsResponder}, req) if err != nil { - result.Response = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "graphrbac.UsersClient", "GetMemberGroups", resp, "Failure sending request") - return + return nil, err } + return resp.(*UserGetMemberGroupsResult), err +} - result, err = client.GetMemberGroupsResponder(resp) +// getMemberGroupsPreparer prepares the GetMemberGroups request. +func (client UsersClient) getMemberGroupsPreparer(objectID string, parameters UserGetMemberGroupsParameters) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/users/{objectId}/getMemberGroups" + req, err := pipeline.NewRequest("POST", u, nil) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.UsersClient", "GetMemberGroups", resp, "Failure responding to request") + return req, pipeline.NewError(err, "failed to create request") } - - return -} - -// GetMemberGroupsPreparer prepares the GetMemberGroups request. -func (client UsersClient) GetMemberGroupsPreparer(ctx context.Context, objectID string, parameters UserGetMemberGroupsParameters) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "objectId": autorest.Encode("path", objectID), - "tenantID": autorest.Encode("path", client.TenantID), + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + b, err := json.Marshal(parameters) + if err != nil { + return req, pipeline.NewError(err, "failed to marshal request body") } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, + req.Header.Set("Content-Type", "application/json") + err = req.SetBody(bytes.NewReader(b)) + if err != nil { + return req, pipeline.NewError(err, "failed to set request body") } - - preparer := autorest.CreatePreparer( - autorest.AsJSON(), - autorest.AsPost(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/users/{objectId}/getMemberGroups", pathParameters), - autorest.WithJSON(parameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) + return req, nil } -// GetMemberGroupsSender sends the GetMemberGroups request. The method will close the -// http.Response Body if it receives an error. -func (client UsersClient) GetMemberGroupsSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) -} - -// GetMemberGroupsResponder handles the response to the GetMemberGroups request. The method always -// closes the http.Response Body. -func (client UsersClient) GetMemberGroupsResponder(resp *http.Response) (result UserGetMemberGroupsResult, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result), - autorest.ByClosing()) - result.Response = autorest.Response{Response: resp} - return +// getMemberGroupsResponder handles the response to the GetMemberGroups request. +func (client UsersClient) getMemberGroupsResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK) + if resp == nil { + return nil, err + } + result := &UserGetMemberGroupsResult{rawResponse: resp.Response()} + if err != nil { + return result, err + } + defer resp.Response().Body.Close() + b, err := ioutil.ReadAll(resp.Response().Body) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to read response body") + } + if len(b) > 0 { + err = json.Unmarshal(b, result) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to unmarshal response body") + } + } + return result, nil } // List gets list of users for the current tenant. // // filter is the filter to apply to the operation. -func (client UsersClient) List(ctx context.Context, filter string) (result UserListResultPage, err error) { - result.fn = func(lastResult UserListResult) (UserListResult, error) { - if lastResult.OdataNextLink == nil || len(to.String(lastResult.OdataNextLink)) < 1 { - return UserListResult{}, nil - } - return client.ListNext(ctx, *lastResult.OdataNextLink) - } - req, err := client.ListPreparer(ctx, filter) +func (client UsersClient) List(ctx context.Context, filter *string) (*UserListResult, error) { + req, err := client.listPreparer(filter) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.UsersClient", "List", nil, "Failure preparing request") - return + return nil, err } - - resp, err := client.ListSender(req) + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.listResponder}, req) if err != nil { - result.ulr.Response = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "graphrbac.UsersClient", "List", resp, "Failure sending request") - return + return nil, err } + return resp.(*UserListResult), err +} - result.ulr, err = client.ListResponder(resp) +// listPreparer prepares the List request. +func (client UsersClient) listPreparer(filter *string) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/users" + req, err := pipeline.NewRequest("GET", u, nil) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.UsersClient", "List", resp, "Failure responding to request") + return req, pipeline.NewError(err, "failed to create request") } - - return + params := req.URL.Query() + if filter != nil { + params.Set("$filter", *filter) + } + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + return req, nil } -// ListPreparer prepares the List request. -func (client UsersClient) ListPreparer(ctx context.Context, filter string) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "tenantID": autorest.Encode("path", client.TenantID), +// listResponder handles the response to the List request. +func (client UsersClient) listResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK) + if resp == nil { + return nil, err } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, + result := &UserListResult{rawResponse: resp.Response()} + if err != nil { + return result, err } - if len(filter) > 0 { - queryParameters["$filter"] = autorest.Encode("query", filter) + defer resp.Response().Body.Close() + b, err := ioutil.ReadAll(resp.Response().Body) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to read response body") } - - preparer := autorest.CreatePreparer( - autorest.AsGet(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/users", pathParameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// ListSender sends the List request. The method will close the -// http.Response Body if it receives an error. -func (client UsersClient) ListSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) -} - -// ListResponder handles the response to the List request. The method always -// closes the http.Response Body. -func (client UsersClient) ListResponder(resp *http.Response) (result UserListResult, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result), - autorest.ByClosing()) - result.Response = autorest.Response{Response: resp} - return -} - -// ListComplete enumerates all values, automatically crossing page boundaries as required. -func (client UsersClient) ListComplete(ctx context.Context, filter string) (result UserListResultIterator, err error) { - result.page, err = client.List(ctx, filter) - return + if len(b) > 0 { + err = json.Unmarshal(b, result) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to unmarshal response body") + } + } + return result, nil } // ListNext gets a list of users for the current tenant. // // nextLink is next link for the list operation. -func (client UsersClient) ListNext(ctx context.Context, nextLink string) (result UserListResult, err error) { - req, err := client.ListNextPreparer(ctx, nextLink) +func (client UsersClient) ListNext(ctx context.Context, nextLink string) (*UserListResult, error) { + req, err := client.listNextPreparer(nextLink) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.UsersClient", "ListNext", nil, "Failure preparing request") - return + return nil, err } - - resp, err := client.ListNextSender(req) + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.listNextResponder}, req) if err != nil { - result.Response = autorest.Response{Response: resp} - err = autorest.NewErrorWithError(err, "graphrbac.UsersClient", "ListNext", resp, "Failure sending request") - return + return nil, err } + return resp.(*UserListResult), err +} - result, err = client.ListNextResponder(resp) +// listNextPreparer prepares the ListNext request. +func (client UsersClient) listNextPreparer(nextLink string) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/{nextLink}" + req, err := pipeline.NewRequest("GET", u, nil) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.UsersClient", "ListNext", resp, "Failure responding to request") + return req, pipeline.NewError(err, "failed to create request") } - - return + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + return req, nil } -// ListNextPreparer prepares the ListNext request. -func (client UsersClient) ListNextPreparer(ctx context.Context, nextLink string) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "nextLink": nextLink, - "tenantID": autorest.Encode("path", client.TenantID), +// listNextResponder handles the response to the ListNext request. +func (client UsersClient) listNextResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK) + if resp == nil { + return nil, err } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, + result := &UserListResult{rawResponse: resp.Response()} + if err != nil { + return result, err } - - preparer := autorest.CreatePreparer( - autorest.AsGet(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/{nextLink}", pathParameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// ListNextSender sends the ListNext request. The method will close the -// http.Response Body if it receives an error. -func (client UsersClient) ListNextSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) -} - -// ListNextResponder handles the response to the ListNext request. The method always -// closes the http.Response Body. -func (client UsersClient) ListNextResponder(resp *http.Response) (result UserListResult, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result), - autorest.ByClosing()) - result.Response = autorest.Response{Response: resp} - return + defer resp.Response().Body.Close() + b, err := ioutil.ReadAll(resp.Response().Body) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to read response body") + } + if len(b) > 0 { + err = json.Unmarshal(b, result) + if err != nil { + return result, NewResponseError(err, resp.Response(), "failed to unmarshal response body") + } + } + return result, nil } // Update updates a user. // // upnOrObjectID is the object ID or principal name of the user to update. parameters is parameters to update an // existing user. -func (client UsersClient) Update(ctx context.Context, upnOrObjectID string, parameters UserUpdateParameters) (result autorest.Response, err error) { - req, err := client.UpdatePreparer(ctx, upnOrObjectID, parameters) +func (client UsersClient) Update(ctx context.Context, upnOrObjectID string, parameters UserUpdateParameters) (*http.Response, error) { + req, err := client.updatePreparer(upnOrObjectID, parameters) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.UsersClient", "Update", nil, "Failure preparing request") - return + return nil, err } - - resp, err := client.UpdateSender(req) + resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.updateResponder}, req) if err != nil { - result.Response = resp - err = autorest.NewErrorWithError(err, "graphrbac.UsersClient", "Update", resp, "Failure sending request") - return + return nil, err } + return resp.Response(), err +} - result, err = client.UpdateResponder(resp) +// updatePreparer prepares the Update request. +func (client UsersClient) updatePreparer(upnOrObjectID string, parameters UserUpdateParameters) (pipeline.Request, error) { + u := client.url + u.Path = "/{tenantID}/users/{upnOrObjectId}" + req, err := pipeline.NewRequest("PATCH", u, nil) if err != nil { - err = autorest.NewErrorWithError(err, "graphrbac.UsersClient", "Update", resp, "Failure responding to request") + return req, pipeline.NewError(err, "failed to create request") } - - return -} - -// UpdatePreparer prepares the Update request. -func (client UsersClient) UpdatePreparer(ctx context.Context, upnOrObjectID string, parameters UserUpdateParameters) (*http.Request, error) { - pathParameters := map[string]interface{}{ - "tenantID": autorest.Encode("path", client.TenantID), - "upnOrObjectId": autorest.Encode("path", upnOrObjectID), + params := req.URL.Query() + params.Set("api-version", APIVersion) + req.URL.RawQuery = params.Encode() + b, err := json.Marshal(parameters) + if err != nil { + return req, pipeline.NewError(err, "failed to marshal request body") } - - const APIVersion = "1.6" - queryParameters := map[string]interface{}{ - "api-version": APIVersion, + req.Header.Set("Content-Type", "application/json") + err = req.SetBody(bytes.NewReader(b)) + if err != nil { + return req, pipeline.NewError(err, "failed to set request body") } - - preparer := autorest.CreatePreparer( - autorest.AsJSON(), - autorest.AsPatch(), - autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/{tenantID}/users/{upnOrObjectId}", pathParameters), - autorest.WithJSON(parameters), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) + return req, nil } -// UpdateSender sends the Update request. The method will close the -// http.Response Body if it receives an error. -func (client UsersClient) UpdateSender(req *http.Request) (*http.Response, error) { - return autorest.SendWithSender(client, req, - autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) -} - -// UpdateResponder handles the response to the Update request. The method always -// closes the http.Response Body. -func (client UsersClient) UpdateResponder(resp *http.Response) (result autorest.Response, err error) { - err = autorest.Respond( - resp, - client.ByInspecting(), - azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), - autorest.ByClosing()) - result.Response = resp - return +// updateResponder handles the response to the Update request. +func (client UsersClient) updateResponder(resp pipeline.Response) (pipeline.Response, error) { + err := validateResponse(resp, http.StatusOK, http.StatusNoContent) + if resp == nil { + return nil, err + } + return resp, err } diff --git a/services/graphrbac/1.6/graphrbac/validation.go b/services/graphrbac/1.6/graphrbac/validation.go new file mode 100644 index 000000000000..c99cbcfeb986 --- /dev/null +++ b/services/graphrbac/1.6/graphrbac/validation.go @@ -0,0 +1,381 @@ +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 ( + "fmt" + "github.com/Azure/azure-pipeline-go/pipeline" + "reflect" + "regexp" + "strings" +) + +// Constraint stores constraint name, target field name +// Rule and chain validations. +type constraint struct { + // Target field name for validation. + target string + + // Constraint name e.g. minLength, MaxLength, Pattern, etc. + name string + + // Rule for constraint e.g. greater than 10, less than 5 etc. + rule interface{} + + // Chain validations for struct type + chain []constraint +} + +// Validation stores parameter-wise validation. +type validation struct { + targetValue interface{} + constraints []constraint +} + +// Constraint list +const ( + empty = "Empty" + null = "Null" + readOnly = "ReadOnly" + pattern = "Pattern" + maxLength = "MaxLength" + minLength = "MinLength" + maxItems = "MaxItems" + minItems = "MinItems" + multipleOf = "MultipleOf" + uniqueItems = "UniqueItems" + inclusiveMaximum = "InclusiveMaximum" + exclusiveMaximum = "ExclusiveMaximum" + exclusiveMinimum = "ExclusiveMinimum" + inclusiveMinimum = "InclusiveMinimum" +) + +// Validate method validates constraints on parameter +// passed in validation array. +func validate(m []validation) error { + for _, item := range m { + v := reflect.ValueOf(item.targetValue) + for _, constraint := range item.constraints { + var err error + switch v.Kind() { + case reflect.Ptr: + err = validatePtr(v, constraint) + case reflect.String: + err = validateString(v, constraint) + case reflect.Struct: + err = validateStruct(v, constraint) + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + err = validateInt(v, constraint) + case reflect.Float32, reflect.Float64: + err = validateFloat(v, constraint) + case reflect.Array, reflect.Slice, reflect.Map: + err = validateArrayMap(v, constraint) + default: + err = createError(v, constraint, fmt.Sprintf("unknown type %v", v.Kind())) + } + if err != nil { + return err + } + } + } + return nil +} + +func validateStruct(x reflect.Value, v constraint, name ...string) error { + //Get field name from target name which is in format a.b.c + s := strings.Split(v.target, ".") + f := x.FieldByName(s[len(s)-1]) + if isZero(f) { + return createError(x, v, fmt.Sprintf("field %q doesn't exist", v.target)) + } + err := validate([]validation{ + { + targetValue: getInterfaceValue(f), + constraints: []constraint{v}, + }, + }) + return err +} + +func validatePtr(x reflect.Value, v constraint) error { + if v.name == readOnly { + if !x.IsNil() { + return createError(x.Elem(), v, "readonly parameter; must send as nil or empty in request") + } + return nil + } + if x.IsNil() { + return checkNil(x, v) + } + if v.chain != nil { + return validate([]validation{ + { + targetValue: getInterfaceValue(x.Elem()), + constraints: v.chain, + }, + }) + } + return nil +} + +func validateInt(x reflect.Value, v constraint) error { + i := x.Int() + r, ok := v.rule.(int) + if !ok { + return createError(x, v, fmt.Sprintf("rule must be integer value for %v constraint; got: %v", v.name, v.rule)) + } + switch v.name { + case multipleOf: + if i%int64(r) != 0 { + return createError(x, v, fmt.Sprintf("value must be a multiple of %v", r)) + } + case exclusiveMinimum: + if i <= int64(r) { + return createError(x, v, fmt.Sprintf("value must be greater than %v", r)) + } + case exclusiveMaximum: + if i >= int64(r) { + return createError(x, v, fmt.Sprintf("value must be less than %v", r)) + } + case inclusiveMinimum: + if i < int64(r) { + return createError(x, v, fmt.Sprintf("value must be greater than or equal to %v", r)) + } + case inclusiveMaximum: + if i > int64(r) { + return createError(x, v, fmt.Sprintf("value must be less than or equal to %v", r)) + } + default: + return createError(x, v, fmt.Sprintf("constraint %v is not applicable for type integer", v.name)) + } + return nil +} + +func validateFloat(x reflect.Value, v constraint) error { + f := x.Float() + r, ok := v.rule.(float64) + if !ok { + return createError(x, v, fmt.Sprintf("rule must be float value for %v constraint; got: %v", v.name, v.rule)) + } + switch v.name { + case exclusiveMinimum: + if f <= r { + return createError(x, v, fmt.Sprintf("value must be greater than %v", r)) + } + case exclusiveMaximum: + if f >= r { + return createError(x, v, fmt.Sprintf("value must be less than %v", r)) + } + case inclusiveMinimum: + if f < r { + return createError(x, v, fmt.Sprintf("value must be greater than or equal to %v", r)) + } + case inclusiveMaximum: + if f > r { + return createError(x, v, fmt.Sprintf("value must be less than or equal to %v", r)) + } + default: + return createError(x, v, fmt.Sprintf("constraint %s is not applicable for type float", v.name)) + } + return nil +} + +func validateString(x reflect.Value, v constraint) error { + s := x.String() + switch v.name { + case empty: + if len(s) == 0 { + return checkEmpty(x, v) + } + case pattern: + reg, err := regexp.Compile(v.rule.(string)) + if err != nil { + return createError(x, v, err.Error()) + } + if !reg.MatchString(s) { + return createError(x, v, fmt.Sprintf("value doesn't match pattern %v", v.rule)) + } + case maxLength: + if _, ok := v.rule.(int); !ok { + return createError(x, v, fmt.Sprintf("rule must be integer value for %v constraint; got: %v", v.name, v.rule)) + } + if len(s) > v.rule.(int) { + return createError(x, v, fmt.Sprintf("value length must be less than %v", v.rule)) + } + case minLength: + if _, ok := v.rule.(int); !ok { + return createError(x, v, fmt.Sprintf("rule must be integer value for %v constraint; got: %v", v.name, v.rule)) + } + if len(s) < v.rule.(int) { + return createError(x, v, fmt.Sprintf("value length must be greater than %v", v.rule)) + } + case readOnly: + if len(s) > 0 { + return createError(reflect.ValueOf(s), v, "readonly parameter; must send as nil or empty in request") + } + default: + return createError(x, v, fmt.Sprintf("constraint %s is not applicable to string type", v.name)) + } + if v.chain != nil { + return validate([]validation{ + { + targetValue: getInterfaceValue(x), + constraints: v.chain, + }, + }) + } + return nil +} + +func validateArrayMap(x reflect.Value, v constraint) error { + switch v.name { + case null: + if x.IsNil() { + return checkNil(x, v) + } + case empty: + if x.IsNil() || x.Len() == 0 { + return checkEmpty(x, v) + } + case maxItems: + if _, ok := v.rule.(int); !ok { + return createError(x, v, fmt.Sprintf("rule must be integer for %v constraint; got: %v", v.name, v.rule)) + } + if x.Len() > v.rule.(int) { + return createError(x, v, fmt.Sprintf("maximum item limit is %v; got: %v", v.rule, x.Len())) + } + case minItems: + if _, ok := v.rule.(int); !ok { + return createError(x, v, fmt.Sprintf("rule must be integer for %v constraint; got: %v", v.name, v.rule)) + } + if x.Len() < v.rule.(int) { + return createError(x, v, fmt.Sprintf("minimum item limit is %v; got: %v", v.rule, x.Len())) + } + case uniqueItems: + if x.Kind() == reflect.Array || x.Kind() == reflect.Slice { + if !checkForUniqueInArray(x) { + return createError(x, v, fmt.Sprintf("all items in parameter %q must be unique; got:%v", v.target, x)) + } + } else if x.Kind() == reflect.Map { + if !checkForUniqueInMap(x) { + return createError(x, v, fmt.Sprintf("all items in parameter %q must be unique; got:%v", v.target, x)) + } + } else { + return createError(x, v, fmt.Sprintf("type must be array, slice or map for constraint %v; got: %v", v.name, x.Kind())) + } + case readOnly: + if x.Len() != 0 { + return createError(x, v, "readonly parameter; must send as nil or empty in request") + } + case pattern: + reg, err := regexp.Compile(v.rule.(string)) + if err != nil { + return createError(x, v, err.Error()) + } + keys := x.MapKeys() + for _, k := range keys { + if !reg.MatchString(k.String()) { + return createError(k, v, fmt.Sprintf("map key doesn't match pattern %v", v.rule)) + } + } + default: + return createError(x, v, fmt.Sprintf("constraint %v is not applicable to array, slice and map type", v.name)) + } + if v.chain != nil { + return validate([]validation{ + { + targetValue: getInterfaceValue(x), + constraints: v.chain, + }, + }) + } + return nil +} + +func checkNil(x reflect.Value, v constraint) error { + if _, ok := v.rule.(bool); !ok { + return createError(x, v, fmt.Sprintf("rule must be bool value for %v constraint; got: %v", v.name, v.rule)) + } + if v.rule.(bool) { + return createError(x, v, "value can not be null; required parameter") + } + return nil +} + +func checkEmpty(x reflect.Value, v constraint) error { + if _, ok := v.rule.(bool); !ok { + return createError(x, v, fmt.Sprintf("rule must be bool value for %v constraint; got: %v", v.name, v.rule)) + } + if v.rule.(bool) { + return createError(x, v, "value can not be null or empty; required parameter") + } + return nil +} + +func checkForUniqueInArray(x reflect.Value) bool { + if x == reflect.Zero(reflect.TypeOf(x)) || x.Len() == 0 { + return false + } + arrOfInterface := make([]interface{}, x.Len()) + for i := 0; i < x.Len(); i++ { + arrOfInterface[i] = x.Index(i).Interface() + } + m := make(map[interface{}]bool) + for _, val := range arrOfInterface { + if m[val] { + return false + } + m[val] = true + } + return true +} + +func checkForUniqueInMap(x reflect.Value) bool { + if x == reflect.Zero(reflect.TypeOf(x)) || x.Len() == 0 { + return false + } + mapOfInterface := make(map[interface{}]interface{}, x.Len()) + keys := x.MapKeys() + for _, k := range keys { + mapOfInterface[k.Interface()] = x.MapIndex(k).Interface() + } + m := make(map[interface{}]bool) + for _, val := range mapOfInterface { + if m[val] { + return false + } + m[val] = true + } + return true +} + +func getInterfaceValue(x reflect.Value) interface{} { + if x.Kind() == reflect.Invalid { + return nil + } + return x.Interface() +} + +func isZero(x interface{}) bool { + return x == reflect.Zero(reflect.TypeOf(x)).Interface() +} + +func createError(x reflect.Value, v constraint, message string) error { + return pipeline.NewError(nil, fmt.Sprintf("validation failed: parameter=%s constraint=%s value=%#v details: %s", + v.target, v.name, getInterfaceValue(x), message)) +} diff --git a/services/graphrbac/1.6/graphrbac/version.go b/services/graphrbac/1.6/graphrbac/version.go index 6f243c50ef45..1f63b3c7eab9 100644 --- a/services/graphrbac/1.6/graphrbac/version.go +++ b/services/graphrbac/1.6/graphrbac/version.go @@ -19,10 +19,10 @@ package graphrbac // UserAgent returns the UserAgent string to use when sending http.Requests. func UserAgent() string { - return "Azure-SDK-For-Go/v12.1.1-beta services" + return "Azure-SDK-For-Go/v12.2.1-beta arm-graphrbac/1.6" } // Version returns the semantic version (see http://semver.org) of the client. func Version() string { - return "v12.1.1-beta" + return "v12.2.1-beta" }