diff --git a/services/preview/msi/mgmt/2015-08-31-preview/msi/models.go b/services/preview/msi/mgmt/2015-08-31-preview/msi/models.go index eff1b71c9e01..a0743441c749 100644 --- a/services/preview/msi/mgmt/2015-08-31-preview/msi/models.go +++ b/services/preview/msi/mgmt/2015-08-31-preview/msi/models.go @@ -64,31 +64,28 @@ type CloudErrorBody struct { // Identity describes an identity resource. type Identity struct { autorest.Response `json:"-"` - // ID - READ-ONLY; The id of the created identity. - ID *string `json:"id,omitempty"` - // Name - READ-ONLY; The name of the created identity. - Name *string `json:"name,omitempty"` - // Location - The Azure region where the identity lives. - Location *string `json:"location,omitempty"` // Tags - Resource tags Tags map[string]*string `json:"tags"` - // IdentityProperties - The properties associated with the identity. + // IdentityProperties - READ-ONLY; The properties associated with the identity. *IdentityProperties `json:"properties,omitempty"` // Type - READ-ONLY; The type of resource i.e. Microsoft.ManagedIdentity/userAssignedIdentities. Possible values include: 'MicrosoftManagedIdentityuserAssignedIdentities' Type UserAssignedIdentities `json:"type,omitempty"` + // ID - READ-ONLY; The id of the resource. + ID *string `json:"id,omitempty"` + // Name - READ-ONLY; The name of the resource. + Name *string `json:"name,omitempty"` + // Location - The Azure region where the resource lives. + Location *string `json:"location,omitempty"` } // MarshalJSON is the custom marshaler for Identity. func (i Identity) MarshalJSON() ([]byte, error) { objectMap := make(map[string]interface{}) - if i.Location != nil { - objectMap["location"] = i.Location - } if i.Tags != nil { objectMap["tags"] = i.Tags } - if i.IdentityProperties != nil { - objectMap["properties"] = i.IdentityProperties + if i.Location != nil { + objectMap["location"] = i.Location } return json.Marshal(objectMap) } @@ -102,59 +99,59 @@ func (i *Identity) UnmarshalJSON(body []byte) error { } for k, v := range m { switch k { - case "id": + case "tags": if v != nil { - var ID string - err = json.Unmarshal(*v, &ID) + var tags map[string]*string + err = json.Unmarshal(*v, &tags) if err != nil { return err } - i.ID = &ID + i.Tags = tags } - case "name": + case "properties": if v != nil { - var name string - err = json.Unmarshal(*v, &name) + var identityProperties IdentityProperties + err = json.Unmarshal(*v, &identityProperties) if err != nil { return err } - i.Name = &name + i.IdentityProperties = &identityProperties } - case "location": + case "type": if v != nil { - var location string - err = json.Unmarshal(*v, &location) + var typeVar UserAssignedIdentities + err = json.Unmarshal(*v, &typeVar) if err != nil { return err } - i.Location = &location + i.Type = typeVar } - case "tags": + case "id": if v != nil { - var tags map[string]*string - err = json.Unmarshal(*v, &tags) + var ID string + err = json.Unmarshal(*v, &ID) if err != nil { return err } - i.Tags = tags + i.ID = &ID } - case "properties": + case "name": if v != nil { - var identityProperties IdentityProperties - err = json.Unmarshal(*v, &identityProperties) + var name string + err = json.Unmarshal(*v, &name) if err != nil { return err } - i.IdentityProperties = &identityProperties + i.Name = &name } - case "type": + case "location": if v != nil { - var typeVar UserAssignedIdentities - err = json.Unmarshal(*v, &typeVar) + var location string + err = json.Unmarshal(*v, &location) if err != nil { return err } - i.Type = typeVar + i.Location = &location } } } @@ -340,6 +337,100 @@ func NewOperationListResultPage(getNextPage func(context.Context, OperationListR return OperationListResultPage{fn: getNextPage} } +// Resource describes common properties of a resource. +type Resource struct { + // ID - READ-ONLY; The id of the resource. + ID *string `json:"id,omitempty"` + // Name - READ-ONLY; The name of the resource. + Name *string `json:"name,omitempty"` + // Location - The Azure region where the resource lives. + Location *string `json:"location,omitempty"` +} + +// SystemAssignedIdentity describes a system assigned identity resource. +type SystemAssignedIdentity struct { + autorest.Response `json:"-"` + // IdentityProperties - READ-ONLY; The properties associated with the identity. + *IdentityProperties `json:"properties,omitempty"` + // Type - READ-ONLY; The type of resource i.e. Microsoft.Compute/virtualMachineScaleSets + Type *string `json:"type,omitempty"` + // ID - READ-ONLY; The id of the resource. + ID *string `json:"id,omitempty"` + // Name - READ-ONLY; The name of the resource. + Name *string `json:"name,omitempty"` + // Location - The Azure region where the resource lives. + Location *string `json:"location,omitempty"` +} + +// MarshalJSON is the custom marshaler for SystemAssignedIdentity. +func (sai SystemAssignedIdentity) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if sai.Location != nil { + objectMap["location"] = sai.Location + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for SystemAssignedIdentity struct. +func (sai *SystemAssignedIdentity) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "properties": + if v != nil { + var identityProperties IdentityProperties + err = json.Unmarshal(*v, &identityProperties) + if err != nil { + return err + } + sai.IdentityProperties = &identityProperties + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + sai.Type = &typeVar + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + sai.ID = &ID + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + sai.Name = &name + } + case "location": + if v != nil { + var location string + err = json.Unmarshal(*v, &location) + if err != nil { + return err + } + sai.Location = &location + } + } + } + + return nil +} + // UserAssignedIdentitiesListResult values returned by the List operation. type UserAssignedIdentitiesListResult struct { autorest.Response `json:"-"` diff --git a/services/preview/msi/mgmt/2015-08-31-preview/msi/msiapi/interfaces.go b/services/preview/msi/mgmt/2015-08-31-preview/msi/msiapi/interfaces.go index 855d26fd9cac..152257bac8b6 100644 --- a/services/preview/msi/mgmt/2015-08-31-preview/msi/msiapi/interfaces.go +++ b/services/preview/msi/mgmt/2015-08-31-preview/msi/msiapi/interfaces.go @@ -23,6 +23,13 @@ import ( "github.com/Azure/go-autorest/autorest" ) +// SystemAssignedIdentitiesClientAPI contains the set of methods on the SystemAssignedIdentitiesClient type. +type SystemAssignedIdentitiesClientAPI interface { + GetByScope(ctx context.Context, scope string) (result msi.SystemAssignedIdentity, err error) +} + +var _ SystemAssignedIdentitiesClientAPI = (*msi.SystemAssignedIdentitiesClient)(nil) + // OperationsClientAPI contains the set of methods on the OperationsClient type. type OperationsClientAPI interface { List(ctx context.Context) (result msi.OperationListResultPage, err error) diff --git a/services/preview/msi/mgmt/2015-08-31-preview/msi/systemassignedidentities.go b/services/preview/msi/mgmt/2015-08-31-preview/msi/systemassignedidentities.go new file mode 100644 index 000000000000..29ae3a760763 --- /dev/null +++ b/services/preview/msi/mgmt/2015-08-31-preview/msi/systemassignedidentities.go @@ -0,0 +1,117 @@ +package msi + +// 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/tracing" + "net/http" +) + +// SystemAssignedIdentitiesClient is the the Managed Service Identity Client. +type SystemAssignedIdentitiesClient struct { + BaseClient +} + +// NewSystemAssignedIdentitiesClient creates an instance of the SystemAssignedIdentitiesClient client. +func NewSystemAssignedIdentitiesClient(subscriptionID string) SystemAssignedIdentitiesClient { + return NewSystemAssignedIdentitiesClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewSystemAssignedIdentitiesClientWithBaseURI creates an instance of the SystemAssignedIdentitiesClient client using +// a custom endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign +// clouds, Azure stack). +func NewSystemAssignedIdentitiesClientWithBaseURI(baseURI string, subscriptionID string) SystemAssignedIdentitiesClient { + return SystemAssignedIdentitiesClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// GetByScope gets the systemAssignedIdentity available under the specified RP scope. +// Parameters: +// scope - the resource provider scope of the resource. Parent resource being extended by Managed Identities. +func (client SystemAssignedIdentitiesClient) GetByScope(ctx context.Context, scope string) (result SystemAssignedIdentity, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/SystemAssignedIdentitiesClient.GetByScope") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetByScopePreparer(ctx, scope) + if err != nil { + err = autorest.NewErrorWithError(err, "msi.SystemAssignedIdentitiesClient", "GetByScope", nil, "Failure preparing request") + return + } + + resp, err := client.GetByScopeSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "msi.SystemAssignedIdentitiesClient", "GetByScope", resp, "Failure sending request") + return + } + + result, err = client.GetByScopeResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "msi.SystemAssignedIdentitiesClient", "GetByScope", resp, "Failure responding to request") + } + + return +} + +// GetByScopePreparer prepares the GetByScope request. +func (client SystemAssignedIdentitiesClient) GetByScopePreparer(ctx context.Context, scope string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "scope": scope, + } + + const APIVersion = "2015-08-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{scope}/providers/Microsoft.ManagedIdentity/identities/default", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetByScopeSender sends the GetByScope request. The method will close the +// http.Response Body if it receives an error. +func (client SystemAssignedIdentitiesClient) GetByScopeSender(req *http.Request) (*http.Response, error) { + sd := autorest.GetSendDecorators(req.Context(), autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) + return autorest.SendWithSender(client, req, sd...) +} + +// GetByScopeResponder handles the response to the GetByScope request. The method always +// closes the http.Response Body. +func (client SystemAssignedIdentitiesClient) GetByScopeResponder(resp *http.Response) (result SystemAssignedIdentity, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/services/preview/msi/mgmt/2015-08-31-preview/msi/userassignedidentities.go b/services/preview/msi/mgmt/2015-08-31-preview/msi/userassignedidentities.go index 7a10c8cd0410..6404839e2b0a 100644 --- a/services/preview/msi/mgmt/2015-08-31-preview/msi/userassignedidentities.go +++ b/services/preview/msi/mgmt/2015-08-31-preview/msi/userassignedidentities.go @@ -92,8 +92,7 @@ func (client UserAssignedIdentitiesClient) CreateOrUpdatePreparer(ctx context.Co "api-version": APIVersion, } - parameters.ID = nil - parameters.Name = nil + parameters.IdentityProperties = nil parameters.Type = "" preparer := autorest.CreatePreparer( autorest.AsContentType("application/json; charset=utf-8"), @@ -551,8 +550,7 @@ func (client UserAssignedIdentitiesClient) UpdatePreparer(ctx context.Context, r "api-version": APIVersion, } - parameters.ID = nil - parameters.Name = nil + parameters.IdentityProperties = nil parameters.Type = "" preparer := autorest.CreatePreparer( autorest.AsContentType("application/json; charset=utf-8"),