diff --git a/services/msi/mgmt/2018-11-30/msi/models.go b/services/msi/mgmt/2018-11-30/msi/models.go index de91eb24a7c2..8e3abcfd047e 100644 --- a/services/msi/mgmt/2018-11-30/msi/models.go +++ b/services/msi/mgmt/2018-11-30/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 `json:"properties,omitempty"` + // UserAssignedIdentityProperties - READ-ONLY; The properties associated with the identity. + *UserAssignedIdentityProperties `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,6 +99,33 @@ func (i *Identity) UnmarshalJSON(body []byte) error { } for k, v := range m { switch k { + case "tags": + if v != nil { + var tags map[string]*string + err = json.Unmarshal(*v, &tags) + if err != nil { + return err + } + i.Tags = tags + } + case "properties": + if v != nil { + var userAssignedIdentityProperties UserAssignedIdentityProperties + err = json.Unmarshal(*v, &userAssignedIdentityProperties) + if err != nil { + return err + } + i.UserAssignedIdentityProperties = &userAssignedIdentityProperties + } + case "type": + if v != nil { + var typeVar UserAssignedIdentities + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + i.Type = typeVar + } case "id": if v != nil { var ID string @@ -129,6 +153,49 @@ func (i *Identity) UnmarshalJSON(body []byte) error { } i.Location = &location } + } + } + + return nil +} + +// IdentityPatch describes an identity resource. +type IdentityPatch struct { + // Tags - Resource tags + Tags map[string]*string `json:"tags"` + // UserAssignedIdentityProperties - READ-ONLY; The properties associated with the identity. + *UserAssignedIdentityProperties `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 IdentityPatch. +func (IP IdentityPatch) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if IP.Tags != nil { + objectMap["tags"] = IP.Tags + } + if IP.Location != nil { + objectMap["location"] = IP.Location + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for IdentityPatch struct. +func (IP *IdentityPatch) 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 "tags": if v != nil { var tags map[string]*string @@ -136,16 +203,16 @@ func (i *Identity) UnmarshalJSON(body []byte) error { if err != nil { return err } - i.Tags = tags + IP.Tags = tags } case "properties": if v != nil { - var identityProperties IdentityProperties - err = json.Unmarshal(*v, &identityProperties) + var userAssignedIdentityProperties UserAssignedIdentityProperties + err = json.Unmarshal(*v, &userAssignedIdentityProperties) if err != nil { return err } - i.IdentityProperties = &identityProperties + IP.UserAssignedIdentityProperties = &userAssignedIdentityProperties } case "type": if v != nil { @@ -154,7 +221,34 @@ func (i *Identity) UnmarshalJSON(body []byte) error { if err != nil { return err } - i.Type = typeVar + IP.Type = typeVar + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + IP.ID = &ID + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + IP.Name = &name + } + case "location": + if v != nil { + var location string + err = json.Unmarshal(*v, &location) + if err != nil { + return err + } + IP.Location = &location } } } @@ -162,18 +256,6 @@ func (i *Identity) UnmarshalJSON(body []byte) error { return nil } -// IdentityProperties the properties associated with the identity. -type IdentityProperties struct { - // TenantID - READ-ONLY; The id of the tenant which the identity belongs to. - TenantID *uuid.UUID `json:"tenantId,omitempty"` - // PrincipalID - READ-ONLY; The id of the service principal object associated with the created identity. - PrincipalID *uuid.UUID `json:"principalId,omitempty"` - // ClientID - READ-ONLY; The id of the app associated with the identity. This is a random generated UUID by MSI. - ClientID *uuid.UUID `json:"clientId,omitempty"` - // ClientSecretURL - READ-ONLY; The ManagedServiceIdentity DataPlane URL that can be queried to obtain the identity credentials. If identity is user assigned, then the clientSecretUrl will not be present in the response, otherwise it will be present. - ClientSecretURL *string `json:"clientSecretUrl,omitempty"` -} - // Operation operation supported by the Microsoft.ManagedIdentity REST API. type Operation struct { // Name - The name of the REST Operation. This is of the format {provider}/{resource}/{operation}. @@ -340,6 +422,112 @@ 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:"-"` + // SystemAssignedIdentityProperties - READ-ONLY; The properties associated with the identity. + *SystemAssignedIdentityProperties `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 systemAssignedIdentityProperties SystemAssignedIdentityProperties + err = json.Unmarshal(*v, &systemAssignedIdentityProperties) + if err != nil { + return err + } + sai.SystemAssignedIdentityProperties = &systemAssignedIdentityProperties + } + 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 +} + +// SystemAssignedIdentityProperties the properties associated with the system assigned identity. +type SystemAssignedIdentityProperties struct { + // TenantID - READ-ONLY; The id of the tenant which the identity belongs to. + TenantID *uuid.UUID `json:"tenantId,omitempty"` + // PrincipalID - READ-ONLY; The id of the service principal object associated with the created identity. + PrincipalID *uuid.UUID `json:"principalId,omitempty"` + // ClientID - READ-ONLY; The id of the app associated with the identity. This is a random generated UUID by MSI. + ClientID *uuid.UUID `json:"clientId,omitempty"` + // ClientSecretURL - READ-ONLY; The ManagedServiceIdentity DataPlane URL that can be queried to obtain the identity credentials. + ClientSecretURL *string `json:"clientSecretUrl,omitempty"` +} + // UserAssignedIdentitiesListResult values returned by the List operation. type UserAssignedIdentitiesListResult struct { autorest.Response `json:"-"` @@ -485,3 +673,13 @@ func (page UserAssignedIdentitiesListResultPage) Values() []Identity { func NewUserAssignedIdentitiesListResultPage(getNextPage func(context.Context, UserAssignedIdentitiesListResult) (UserAssignedIdentitiesListResult, error)) UserAssignedIdentitiesListResultPage { return UserAssignedIdentitiesListResultPage{fn: getNextPage} } + +// UserAssignedIdentityProperties the properties associated with the user assigned identity. +type UserAssignedIdentityProperties struct { + // TenantID - READ-ONLY; The id of the tenant which the identity belongs to. + TenantID *uuid.UUID `json:"tenantId,omitempty"` + // PrincipalID - READ-ONLY; The id of the service principal object associated with the created identity. + PrincipalID *uuid.UUID `json:"principalId,omitempty"` + // ClientID - READ-ONLY; The id of the app associated with the identity. This is a random generated UUID by MSI. + ClientID *uuid.UUID `json:"clientId,omitempty"` +} diff --git a/services/msi/mgmt/2018-11-30/msi/msiapi/interfaces.go b/services/msi/mgmt/2018-11-30/msi/msiapi/interfaces.go index 5d6051d6bb02..4a3920c44567 100644 --- a/services/msi/mgmt/2018-11-30/msi/msiapi/interfaces.go +++ b/services/msi/mgmt/2018-11-30/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) @@ -40,7 +47,7 @@ type UserAssignedIdentitiesClientAPI interface { ListByResourceGroupComplete(ctx context.Context, resourceGroupName string) (result msi.UserAssignedIdentitiesListResultIterator, err error) ListBySubscription(ctx context.Context) (result msi.UserAssignedIdentitiesListResultPage, err error) ListBySubscriptionComplete(ctx context.Context) (result msi.UserAssignedIdentitiesListResultIterator, err error) - Update(ctx context.Context, resourceGroupName string, resourceName string, parameters msi.Identity) (result msi.Identity, err error) + Update(ctx context.Context, resourceGroupName string, resourceName string, parameters msi.IdentityPatch) (result msi.Identity, err error) } var _ UserAssignedIdentitiesClientAPI = (*msi.UserAssignedIdentitiesClient)(nil) diff --git a/services/msi/mgmt/2018-11-30/msi/systemassignedidentities.go b/services/msi/mgmt/2018-11-30/msi/systemassignedidentities.go new file mode 100644 index 000000000000..15052202105d --- /dev/null +++ b/services/msi/mgmt/2018-11-30/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 = "2018-11-30" + 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/msi/mgmt/2018-11-30/msi/userassignedidentities.go b/services/msi/mgmt/2018-11-30/msi/userassignedidentities.go index 997e67790fb6..623cfda7ccc2 100644 --- a/services/msi/mgmt/2018-11-30/msi/userassignedidentities.go +++ b/services/msi/mgmt/2018-11-30/msi/userassignedidentities.go @@ -92,8 +92,7 @@ func (client UserAssignedIdentitiesClient) CreateOrUpdatePreparer(ctx context.Co "api-version": APIVersion, } - parameters.ID = nil - parameters.Name = nil + parameters.UserAssignedIdentityProperties = nil parameters.Type = "" preparer := autorest.CreatePreparer( autorest.AsContentType("application/json; charset=utf-8"), @@ -506,7 +505,7 @@ func (client UserAssignedIdentitiesClient) ListBySubscriptionComplete(ctx contex // resourceGroupName - the name of the Resource Group to which the identity belongs. // resourceName - the name of the identity resource. // parameters - parameters to update the identity -func (client UserAssignedIdentitiesClient) Update(ctx context.Context, resourceGroupName string, resourceName string, parameters Identity) (result Identity, err error) { +func (client UserAssignedIdentitiesClient) Update(ctx context.Context, resourceGroupName string, resourceName string, parameters IdentityPatch) (result Identity, err error) { if tracing.IsEnabled() { ctx = tracing.StartSpan(ctx, fqdn+"/UserAssignedIdentitiesClient.Update") defer func() { @@ -539,7 +538,7 @@ func (client UserAssignedIdentitiesClient) Update(ctx context.Context, resourceG } // UpdatePreparer prepares the Update request. -func (client UserAssignedIdentitiesClient) UpdatePreparer(ctx context.Context, resourceGroupName string, resourceName string, parameters Identity) (*http.Request, error) { +func (client UserAssignedIdentitiesClient) UpdatePreparer(ctx context.Context, resourceGroupName string, resourceName string, parameters IdentityPatch) (*http.Request, error) { pathParameters := map[string]interface{}{ "resourceGroupName": autorest.Encode("path", resourceGroupName), "resourceName": autorest.Encode("path", resourceName), @@ -551,8 +550,7 @@ func (client UserAssignedIdentitiesClient) UpdatePreparer(ctx context.Context, r "api-version": APIVersion, } - parameters.ID = nil - parameters.Name = nil + parameters.UserAssignedIdentityProperties = nil parameters.Type = "" preparer := autorest.CreatePreparer( autorest.AsContentType("application/json; charset=utf-8"),