From a1b1c09e911c6aa4ac0f563c0cf4bba4a3c31d67 Mon Sep 17 00:00:00 2001 From: Brendan Bergen Date: Mon, 9 Sep 2024 17:28:15 -0600 Subject: [PATCH] Encryption At Host Dynamic Validation - Frontend will now validate that Encryption At Host is enabled on customer's subscription before installing clusters - In memory of Swetha. Thanks for your amazing contributions to our team, I'm glad we can finally get your work across the line with this one. Co-authored-by: Swetha Chirumamilla --- go.mod | 1 + go.sum | 2 + pkg/frontend/encryptionathost_validation.go | 67 +++ .../encryptionathost_validation_test.go | 97 ++++ pkg/frontend/frontend.go | 14 +- pkg/frontend/openshiftcluster_putorpatch.go | 5 + .../azuresdk/armfeatures/generate.go | 8 + .../subscription_feature_registrations.go | 15 + .../azuresdk/armfeatures/armfeatures.go | 51 ++ .../resources/armfeatures/CHANGELOG.md | 20 + .../resources/armfeatures/LICENSE.txt | 21 + .../resources/armfeatures/README.md | 92 ++++ .../resources/armfeatures/assets.json | 6 + .../resources/armfeatures/autorest.md | 13 + .../resources/armfeatures/build.go | 7 + .../resources/armfeatures/ci.yml | 28 + .../resources/armfeatures/client.go | 349 ++++++++++++ .../resources/armfeatures/client_factory.go | 56 ++ .../resources/armfeatures/constants.go | 58 ++ .../resources/armfeatures/feature_client.go | 89 +++ .../resources/armfeatures/models.go | 187 +++++++ .../resources/armfeatures/models_serde.go | 519 ++++++++++++++++++ .../resources/armfeatures/options.go | 70 +++ .../resources/armfeatures/response_types.go | 75 +++ ...subscriptionfeatureregistrations_client.go | 350 ++++++++++++ .../resources/armfeatures/time_rfc3339.go | 86 +++ vendor/modules.txt | 3 + 27 files changed, 2283 insertions(+), 6 deletions(-) create mode 100644 pkg/frontend/encryptionathost_validation.go create mode 100644 pkg/frontend/encryptionathost_validation_test.go create mode 100644 pkg/util/azureclient/azuresdk/armfeatures/generate.go create mode 100644 pkg/util/azureclient/azuresdk/armfeatures/subscription_feature_registrations.go create mode 100644 pkg/util/mocks/azureclient/azuresdk/armfeatures/armfeatures.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/CHANGELOG.md create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/LICENSE.txt create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/README.md create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/assets.json create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/autorest.md create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/build.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/ci.yml create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/client.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/client_factory.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/constants.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/feature_client.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/models.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/models_serde.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/options.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/response_types.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/subscriptionfeatureregistrations_client.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/time_rfc3339.go diff --git a/go.mod b/go.mod index b54f93a9da3..31d1629df09 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/dns/armdns v1.2.0 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/keyvault/armkeyvault v1.4.0 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v2 v2.2.1 + github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures v1.2.0 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage v1.5.0 github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.3.2 github.com/Azure/go-autorest/autorest v0.11.29 diff --git a/go.sum b/go.sum index c7f77acd6a1..f052e278fe5 100644 --- a/go.sum +++ b/go.sum @@ -22,6 +22,8 @@ github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/keyvault/armkeyvault v1.4. github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/keyvault/armkeyvault v1.4.0/go.mod h1:StGsLbuJh06Bd8IBfnAlIFV3fLb+gkczONWf15hpX2E= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v2 v2.2.1 h1:bWh0Z2rOEDfB/ywv/l0iHN1JgyazE6kW/aIA89+CEK0= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v2 v2.2.1/go.mod h1:Bzf34hhAE9NSxailk8xVeLEZbUjOXcC+GnU1mMKdhLw= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures v1.2.0 h1:wIDqH4WA5uJ6irRqjzodeSw6Pmp0tu3oIbwzBZEdMfQ= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures v1.2.0/go.mod h1:g8mnARUMaYRsg80mxm3PxjF7+oUotB/lneDbwYbGNxg= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1 h1:7CBQ+Ei8SP2c6ydQTGCCrS35bDxgTMfoP2miAwK++OU= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1/go.mod h1:c/wcGeGx5FUPbM/JltUYHZcKmigwyVLJlDq+4HdtXaw= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage v1.5.0 h1:AifHbc4mg0x9zW52WOpKbsHaDKuRhlI7TVl47thgQ70= diff --git a/pkg/frontend/encryptionathost_validation.go b/pkg/frontend/encryptionathost_validation.go new file mode 100644 index 00000000000..6eb8193d244 --- /dev/null +++ b/pkg/frontend/encryptionathost_validation.go @@ -0,0 +1,67 @@ +package frontend + +// Copyright (c) Microsoft Corporation. +// Licensed under the Apache License 2.0. + +import ( + "context" + "net/http" + + sdk_armfeatures "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures" + + "github.com/Azure/ARO-RP/pkg/api" + "github.com/Azure/ARO-RP/pkg/env" + "github.com/Azure/ARO-RP/pkg/util/azureclient/azuresdk/armfeatures" +) + +type EncryptionAtHostValidator interface { + ValidateEncryptionAtHost(ctx context.Context, environment env.Interface, subscriptionID, tenantID string, oc *api.OpenShiftCluster) error +} + +type encryptionAtHostValidator struct{} + +func (e encryptionAtHostValidator) ValidateEncryptionAtHost(ctx context.Context, environment env.Interface, subscriptionID, tenantID string, oc *api.OpenShiftCluster) error { + credential, err := environment.FPNewClientCertificateCredential(tenantID) + if err != nil { + return err + } + + subFeatureRegistrationsClient, err := sdk_armfeatures.NewSubscriptionFeatureRegistrationsClient(subscriptionID, credential, nil) + if err != nil { + return err + } + return validateEncryptionAtHostGivenClient(ctx, subFeatureRegistrationsClient, oc) +} + +func validateEncryptionAtHostGivenClient(ctx context.Context, subFeatureRegistrationsClient armfeatures.SubscriptionFeatureRegistrationsClient, oc *api.OpenShiftCluster) error { + var clusterUsesEncryptionAtHost = false + profilesToCheck := append([]api.WorkerProfile{{EncryptionAtHost: oc.Properties.MasterProfile.EncryptionAtHost}}, oc.Properties.WorkerProfiles...) + for _, profile := range profilesToCheck { + if profile.EncryptionAtHost == api.EncryptionAtHostEnabled { + clusterUsesEncryptionAtHost = true + break + } + } + if !clusterUsesEncryptionAtHost { + return nil + } + return validateSubscriptionIsRegisteredForEncryptionAtHost(ctx, subFeatureRegistrationsClient) +} + +func validateSubscriptionIsRegisteredForEncryptionAtHost(ctx context.Context, subFeatureRegistrationsClient armfeatures.SubscriptionFeatureRegistrationsClient) error { + response, err := subFeatureRegistrationsClient.Get(ctx, "Microsoft.Compute", "EncryptionAtHost", nil) + if err != nil { + return err + } + if *response.Properties.State != sdk_armfeatures.SubscriptionFeatureRegistrationStateRegistered { + return &api.CloudError{ + StatusCode: http.StatusBadRequest, + CloudErrorBody: &api.CloudErrorBody{ + Code: api.CloudErrorCodeInvalidParameter, + Message: "Microsoft.Compute/EncryptionAtHost feature is not enabled for this subscription. Register the feature using 'az feature register --namespace Microsoft.Compute --name EncryptionAtHost'", + Target: "armfeatures.SubscriptionFeatureRegistrationProperties", + }, + } + } + return nil +} diff --git a/pkg/frontend/encryptionathost_validation_test.go b/pkg/frontend/encryptionathost_validation_test.go new file mode 100644 index 00000000000..8efd02239d2 --- /dev/null +++ b/pkg/frontend/encryptionathost_validation_test.go @@ -0,0 +1,97 @@ +package frontend + +// Copyright (c) Microsoft Corporation. +// Licensed under the Apache License 2.0. + +import ( + "context" + "testing" + + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures" + "github.com/golang/mock/gomock" + + "github.com/Azure/ARO-RP/pkg/api" + mock_armfeatures "github.com/Azure/ARO-RP/pkg/util/mocks/azureclient/azuresdk/armfeatures" + utilerror "github.com/Azure/ARO-RP/test/util/error" +) + +func TestValidateEncryptionAtHost(t *testing.T) { + getClusterWithNodeProfiles := func(MasterProfile api.MasterProfile, WorkerProfiles []api.WorkerProfile) *api.OpenShiftCluster { + return &api.OpenShiftCluster{ + Properties: api.OpenShiftClusterProperties{ + MasterProfile: MasterProfile, + WorkerProfiles: WorkerProfiles, + }, + } + } + + getSubscriptionWithFeatureState := func(state armfeatures.SubscriptionFeatureRegistrationState) *armfeatures.SubscriptionFeatureRegistrationsClientGetResponse { + return &armfeatures.SubscriptionFeatureRegistrationsClientGetResponse{ + SubscriptionFeatureRegistration: armfeatures.SubscriptionFeatureRegistration{ + Properties: &armfeatures.SubscriptionFeatureRegistrationProperties{ + State: &state, + }, + }, + } + } + + for _, tt := range []struct { + name string + oc *api.OpenShiftCluster + mockResponse *armfeatures.SubscriptionFeatureRegistrationsClientGetResponse + mockErr error + wantErr string + wantNumArmCalls int + }{ + { + name: "valid: cluster encryption at host disabled and subscription feature isn't registered", + oc: getClusterWithNodeProfiles(api.MasterProfile{EncryptionAtHost: api.EncryptionAtHostDisabled}, []api.WorkerProfile{{EncryptionAtHost: api.EncryptionAtHostDisabled}}), + mockResponse: getSubscriptionWithFeatureState(armfeatures.SubscriptionFeatureRegistrationStateNotRegistered), + wantNumArmCalls: 0, + }, + { + name: "valid: cluster encryption at host disabled and subscription feature is registered", + oc: getClusterWithNodeProfiles(api.MasterProfile{EncryptionAtHost: api.EncryptionAtHostDisabled}, []api.WorkerProfile{{EncryptionAtHost: api.EncryptionAtHostDisabled}}), + mockResponse: getSubscriptionWithFeatureState(armfeatures.SubscriptionFeatureRegistrationStateRegistered), + wantNumArmCalls: 0, + }, + { + name: "valid: cluster encryption at host enabled and subscription feature is registered", + oc: getClusterWithNodeProfiles(api.MasterProfile{EncryptionAtHost: api.EncryptionAtHostEnabled}, []api.WorkerProfile{{EncryptionAtHost: api.EncryptionAtHostEnabled}}), + mockResponse: getSubscriptionWithFeatureState(armfeatures.SubscriptionFeatureRegistrationStateRegistered), + wantNumArmCalls: 1, + }, + { + name: "invalid: cluster master and worker encryption at host enabled and subscription feature isn't registered", + oc: getClusterWithNodeProfiles(api.MasterProfile{EncryptionAtHost: api.EncryptionAtHostEnabled}, []api.WorkerProfile{{EncryptionAtHost: api.EncryptionAtHostEnabled}}), + mockResponse: getSubscriptionWithFeatureState(armfeatures.SubscriptionFeatureRegistrationStateNotRegistered), + wantErr: "400: InvalidParameter: armfeatures.SubscriptionFeatureRegistrationProperties: Microsoft.Compute/EncryptionAtHost feature is not enabled for this subscription. Register the feature using 'az feature register --namespace Microsoft.Compute --name EncryptionAtHost'", + wantNumArmCalls: 1, + }, + { + name: "invalid: cluster master encryption at host enabled and subscription feature isn't registered", + oc: getClusterWithNodeProfiles(api.MasterProfile{EncryptionAtHost: api.EncryptionAtHostEnabled}, []api.WorkerProfile{{EncryptionAtHost: api.EncryptionAtHostDisabled}}), + mockResponse: getSubscriptionWithFeatureState(armfeatures.SubscriptionFeatureRegistrationStateNotRegistered), + wantErr: "400: InvalidParameter: armfeatures.SubscriptionFeatureRegistrationProperties: Microsoft.Compute/EncryptionAtHost feature is not enabled for this subscription. Register the feature using 'az feature register --namespace Microsoft.Compute --name EncryptionAtHost'", + wantNumArmCalls: 1, + }, + { + name: "invalid: cluster worker encryption at host enabled and subscription feature isn't registered", + oc: getClusterWithNodeProfiles(api.MasterProfile{EncryptionAtHost: api.EncryptionAtHostDisabled}, []api.WorkerProfile{{EncryptionAtHost: api.EncryptionAtHostEnabled}}), + mockResponse: getSubscriptionWithFeatureState(armfeatures.SubscriptionFeatureRegistrationStateNotRegistered), + wantErr: "400: InvalidParameter: armfeatures.SubscriptionFeatureRegistrationProperties: Microsoft.Compute/EncryptionAtHost feature is not enabled for this subscription. Register the feature using 'az feature register --namespace Microsoft.Compute --name EncryptionAtHost'", + wantNumArmCalls: 1, + }, + } { + t.Run(tt.name, func(t *testing.T) { + controller := gomock.NewController(t) + defer controller.Finish() + + subFeatureRegistrationsClient := mock_armfeatures.NewMockSubscriptionFeatureRegistrationsClient(controller) + subFeatureRegistrationsClient.EXPECT().Get(gomock.Any(), "Microsoft.Compute", "EncryptionAtHost", gomock.Any()).Return(*tt.mockResponse, tt.mockErr).Times(tt.wantNumArmCalls) + + err := validateEncryptionAtHostGivenClient(context.Background(), subFeatureRegistrationsClient, tt.oc) + utilerror.AssertErrorMessage(t, err, tt.wantErr) + }) + } +} diff --git a/pkg/frontend/frontend.go b/pkg/frontend/frontend.go index 83e9d97b660..4d3d4577417 100644 --- a/pkg/frontend/frontend.go +++ b/pkg/frontend/frontend.go @@ -86,9 +86,10 @@ type frontend struct { azureActionsFactory azureActionsFactory appLensActionsFactory appLensActionsFactory - skuValidator SkuValidator - quotaValidator QuotaValidator - providersValidator ProvidersValidator + skuValidator SkuValidator + quotaValidator QuotaValidator + providersValidator ProvidersValidator + encryptionathostValidator EncryptionAtHostValidator clusterEnricher clusterdata.BestEffortEnricher @@ -161,9 +162,10 @@ func NewFrontend(ctx context.Context, azureActionsFactory: azureActionsFactory, appLensActionsFactory: appLensActionsFactory, - quotaValidator: quotaValidator{}, - skuValidator: skuValidator{}, - providersValidator: providersValidator{}, + quotaValidator: quotaValidator{}, + skuValidator: skuValidator{}, + providersValidator: providersValidator{}, + encryptionathostValidator: encryptionAtHostValidator{}, clusterEnricher: enricher, diff --git a/pkg/frontend/openshiftcluster_putorpatch.go b/pkg/frontend/openshiftcluster_putorpatch.go index e802b5f3518..1001101253b 100644 --- a/pkg/frontend/openshiftcluster_putorpatch.go +++ b/pkg/frontend/openshiftcluster_putorpatch.go @@ -387,6 +387,11 @@ func (f *frontend) ValidateNewCluster(ctx context.Context, subscription *api.Sub return err } + err = f.encryptionathostValidator.ValidateEncryptionAtHost(ctx, f.env, subscription.ID, subscription.Subscription.Properties.TenantID, cluster) + if err != nil { + return err + } + return nil } diff --git a/pkg/util/azureclient/azuresdk/armfeatures/generate.go b/pkg/util/azureclient/azuresdk/armfeatures/generate.go new file mode 100644 index 00000000000..1dbef30fa97 --- /dev/null +++ b/pkg/util/azureclient/azuresdk/armfeatures/generate.go @@ -0,0 +1,8 @@ +package armfeatures + +// Copyright (c) Microsoft Corporation. +// Licensed under the Apache License 2.0. + +//go:generate rm -rf ../../../../../pkg/util/mocks/azureclient/azuresdk/$GOPACKAGE +//go:generate mockgen -destination=../../../mocks/azureclient/azuresdk/$GOPACKAGE/$GOPACKAGE.go github.com/Azure/ARO-RP/pkg/util/azureclient/azuresdk/$GOPACKAGE SubscriptionFeatureRegistrationsClient +//go:generate goimports -local=github.com/Azure/ARO-RP -e -w ../../../mocks/azureclient/azuresdk/$GOPACKAGE/$GOPACKAGE.go diff --git a/pkg/util/azureclient/azuresdk/armfeatures/subscription_feature_registrations.go b/pkg/util/azureclient/azuresdk/armfeatures/subscription_feature_registrations.go new file mode 100644 index 00000000000..5a4a6c49be6 --- /dev/null +++ b/pkg/util/azureclient/azuresdk/armfeatures/subscription_feature_registrations.go @@ -0,0 +1,15 @@ +package armfeatures + +// Copyright (c) Microsoft Corporation. +// Licensed under the Apache License 2.0. + +import ( + "context" + + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures" +) + +// SubscriptionFeatureRegistrationsClient is a minimal interface for azure SubscriptionFeatureRegistrationsClient +type SubscriptionFeatureRegistrationsClient interface { + Get(ctx context.Context, providerNamespace string, featureName string, options *armfeatures.SubscriptionFeatureRegistrationsClientGetOptions) (armfeatures.SubscriptionFeatureRegistrationsClientGetResponse, error) +} diff --git a/pkg/util/mocks/azureclient/azuresdk/armfeatures/armfeatures.go b/pkg/util/mocks/azureclient/azuresdk/armfeatures/armfeatures.go new file mode 100644 index 00000000000..1d8f5261cc4 --- /dev/null +++ b/pkg/util/mocks/azureclient/azuresdk/armfeatures/armfeatures.go @@ -0,0 +1,51 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/Azure/ARO-RP/pkg/util/azureclient/azuresdk/armfeatures (interfaces: SubscriptionFeatureRegistrationsClient) + +// Package mock_armfeatures is a generated GoMock package. +package mock_armfeatures + +import ( + context "context" + reflect "reflect" + + armfeatures "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures" + gomock "github.com/golang/mock/gomock" +) + +// MockSubscriptionFeatureRegistrationsClient is a mock of SubscriptionFeatureRegistrationsClient interface. +type MockSubscriptionFeatureRegistrationsClient struct { + ctrl *gomock.Controller + recorder *MockSubscriptionFeatureRegistrationsClientMockRecorder +} + +// MockSubscriptionFeatureRegistrationsClientMockRecorder is the mock recorder for MockSubscriptionFeatureRegistrationsClient. +type MockSubscriptionFeatureRegistrationsClientMockRecorder struct { + mock *MockSubscriptionFeatureRegistrationsClient +} + +// NewMockSubscriptionFeatureRegistrationsClient creates a new mock instance. +func NewMockSubscriptionFeatureRegistrationsClient(ctrl *gomock.Controller) *MockSubscriptionFeatureRegistrationsClient { + mock := &MockSubscriptionFeatureRegistrationsClient{ctrl: ctrl} + mock.recorder = &MockSubscriptionFeatureRegistrationsClientMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockSubscriptionFeatureRegistrationsClient) EXPECT() *MockSubscriptionFeatureRegistrationsClientMockRecorder { + return m.recorder +} + +// Get mocks base method. +func (m *MockSubscriptionFeatureRegistrationsClient) Get(arg0 context.Context, arg1, arg2 string, arg3 *armfeatures.SubscriptionFeatureRegistrationsClientGetOptions) (armfeatures.SubscriptionFeatureRegistrationsClientGetResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Get", arg0, arg1, arg2, arg3) + ret0, _ := ret[0].(armfeatures.SubscriptionFeatureRegistrationsClientGetResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Get indicates an expected call of Get. +func (mr *MockSubscriptionFeatureRegistrationsClientMockRecorder) Get(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockSubscriptionFeatureRegistrationsClient)(nil).Get), arg0, arg1, arg2, arg3) +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/CHANGELOG.md b/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/CHANGELOG.md new file mode 100644 index 00000000000..d653480c866 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/CHANGELOG.md @@ -0,0 +1,20 @@ +# Release History + +## 1.2.0 (2023-11-24) +### Features Added + +- Support for test fakes and OpenTelemetry trace spans. + + +## 1.1.0 (2023-03-27) +### Features Added + +- New struct `ClientFactory` which is a client factory used to create any client in this module + +## 1.0.0 (2022-05-16) + +The package of `github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures` is using our [next generation design principles](https://azure.github.io/azure-sdk/general_introduction.html) since version 1.0.0, which contains breaking changes. + +To migrate the existing applications to the latest version, please refer to [Migration Guide](https://aka.ms/azsdk/go/mgmt/migration). + +To learn more, please refer to our documentation [Quick Start](https://aka.ms/azsdk/go/mgmt). \ No newline at end of file diff --git a/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/LICENSE.txt b/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/LICENSE.txt new file mode 100644 index 00000000000..dc0c2ffb3dc --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) Microsoft Corporation. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/README.md b/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/README.md new file mode 100644 index 00000000000..4c6cc6305d4 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/README.md @@ -0,0 +1,92 @@ +# Azure Features Module for Go + +[![PkgGoDev](https://pkg.go.dev/badge/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures)](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures) + +The `armfeatures` module provides operations for working with Azure Features. + +[Source code](https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/resourcemanager/resources/armfeatures) + +# Getting started + +## Prerequisites + +- an [Azure subscription](https://azure.microsoft.com/free/) +- Go 1.18 or above (You could download and install the latest version of Go from [here](https://go.dev/doc/install). It will replace the existing Go on your machine. If you want to install multiple Go versions on the same machine, you could refer this [doc](https://go.dev/doc/manage-install).) + +## Install the package + +This project uses [Go modules](https://github.com/golang/go/wiki/Modules) for versioning and dependency management. + +Install the Azure Features module: + +```sh +go get github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures +``` + +## Authorization + +When creating a client, you will need to provide a credential for authenticating with Azure Features. The `azidentity` module provides facilities for various ways of authenticating with Azure including client/secret, certificate, managed identity, and more. + +```go +cred, err := azidentity.NewDefaultAzureCredential(nil) +``` + +For more information on authentication, please see the documentation for `azidentity` at [pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity). + +## Client Factory + +Azure Features module consists of one or more clients. We provide a client factory which could be used to create any client in this module. + +```go +clientFactory, err := armfeatures.NewClientFactory(, cred, nil) +``` + +You can use `ClientOptions` in package `github.com/Azure/azure-sdk-for-go/sdk/azcore/arm` to set endpoint to connect with public and sovereign clouds as well as Azure Stack. For more information, please see the documentation for `azcore` at [pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azcore](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azcore). + +```go +options := arm.ClientOptions { + ClientOptions: azcore.ClientOptions { + Cloud: cloud.AzureChina, + }, +} +clientFactory, err := armfeatures.NewClientFactory(, cred, &options) +``` + +## Clients + +A client groups a set of related APIs, providing access to its functionality. Create one or more clients to access the APIs you require using client factory. + +```go +client := clientFactory.NewClient() +``` + +## Fakes + +The fake package contains types used for constructing in-memory fake servers used in unit tests. +This allows writing tests to cover various success/error conditions without the need for connecting to a live service. + +Please see https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/samples/fakes for details and examples on how to use fakes. + +## Provide Feedback + +If you encounter bugs or have suggestions, please +[open an issue](https://github.com/Azure/azure-sdk-for-go/issues) and assign the `Features` label. + +# Contributing + +This project welcomes contributions and suggestions. Most contributions require +you to agree to a Contributor License Agreement (CLA) declaring that you have +the right to, and actually do, grant us the rights to use your contribution. +For details, visit [https://cla.microsoft.com](https://cla.microsoft.com). + +When you submit a pull request, a CLA-bot will automatically determine whether +you need to provide a CLA and decorate the PR appropriately (e.g., label, +comment). Simply follow the instructions provided by the bot. You will only +need to do this once across all repos using our CLA. + +This project has adopted the +[Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). +For more information, see the +[Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) +or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any +additional questions or comments. \ No newline at end of file diff --git a/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/assets.json b/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/assets.json new file mode 100644 index 00000000000..0c8400cedf3 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/assets.json @@ -0,0 +1,6 @@ +{ + "AssetsRepo": "Azure/azure-sdk-assets", + "AssetsRepoPrefixPath": "go", + "TagPrefix": "go/resourcemanager/resources/armfeatures", + "Tag": "go/resourcemanager/resources/armfeatures_314d60e072" +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/autorest.md b/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/autorest.md new file mode 100644 index 00000000000..1a48abbc75a --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/autorest.md @@ -0,0 +1,13 @@ +### AutoRest Configuration + +> see https://aka.ms/autorest + +``` yaml +azure-arm: true +require: +- https://github.com/Azure/azure-rest-api-specs/blob/0cc5e2efd6ffccf30e80d1e150b488dd87198b94/specification/resources/resource-manager/readme.md +- https://github.com/Azure/azure-rest-api-specs/blob/0cc5e2efd6ffccf30e80d1e150b488dd87198b94/specification/resources/resource-manager/readme.go.md +license-header: MICROSOFT_MIT_NO_VERSION +module-version: 1.2.0 +package-features: true +``` \ No newline at end of file diff --git a/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/build.go b/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/build.go new file mode 100644 index 00000000000..0fee408476a --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/build.go @@ -0,0 +1,7 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +// This file enables 'go generate' to regenerate this specific SDK +//go:generate pwsh ../../../../eng/scripts/build.ps1 -skipBuild -cleanGenerated -format -tidy -generate resourcemanager/resources/armfeatures + +package armfeatures diff --git a/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/ci.yml b/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/ci.yml new file mode 100644 index 00000000000..cc73e50395b --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/ci.yml @@ -0,0 +1,28 @@ +# NOTE: Please refer to https://aka.ms/azsdk/engsys/ci-yaml before editing this file. +trigger: + branches: + include: + - main + - feature/* + - hotfix/* + - release/* + paths: + include: + - sdk/resourcemanager/resources/armfeatures/ + +pr: + branches: + include: + - main + - feature/* + - hotfix/* + - release/* + paths: + include: + - sdk/resourcemanager/resources/armfeatures/ + +stages: +- template: /eng/pipelines/templates/jobs/archetype-sdk-client.yml + parameters: + IncludeRelease: true + ServiceDirectory: 'resourcemanager/resources/armfeatures' diff --git a/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/client.go b/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/client.go new file mode 100644 index 00000000000..767899bcd7e --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/client.go @@ -0,0 +1,349 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armfeatures + +import ( + "context" + "errors" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "net/url" + "strings" +) + +// Client contains the methods for the Features group. +// Don't use this type directly, use NewClient() instead. +type Client struct { + internal *arm.Client + subscriptionID string +} + +// NewClient creates a new instance of Client with the specified values. +// - subscriptionID - The Azure subscription ID. +// - credential - used to authorize requests. Usually a credential from azidentity. +// - options - pass nil to accept the default values. +func NewClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*Client, error) { + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) + if err != nil { + return nil, err + } + client := &Client{ + subscriptionID: subscriptionID, + internal: cl, + } + return client, nil +} + +// Get - Gets the preview feature with the specified name. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2021-07-01 +// - resourceProviderNamespace - The resource provider namespace for the feature. +// - featureName - The name of the feature to get. +// - options - ClientGetOptions contains the optional parameters for the Client.Get method. +func (client *Client) Get(ctx context.Context, resourceProviderNamespace string, featureName string, options *ClientGetOptions) (ClientGetResponse, error) { + var err error + const operationName = "Client.Get" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() + req, err := client.getCreateRequest(ctx, resourceProviderNamespace, featureName, options) + if err != nil { + return ClientGetResponse{}, err + } + httpResp, err := client.internal.Pipeline().Do(req) + if err != nil { + return ClientGetResponse{}, err + } + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ClientGetResponse{}, err + } + resp, err := client.getHandleResponse(httpResp) + return resp, err +} + +// getCreateRequest creates the Get request. +func (client *Client) getCreateRequest(ctx context.Context, resourceProviderNamespace string, featureName string, options *ClientGetOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Features/providers/{resourceProviderNamespace}/features/{featureName}" + if resourceProviderNamespace == "" { + return nil, errors.New("parameter resourceProviderNamespace cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceProviderNamespace}", url.PathEscape(resourceProviderNamespace)) + if featureName == "" { + return nil, errors.New("parameter featureName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{featureName}", url.PathEscape(featureName)) + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-07-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json, text/json"} + return req, nil +} + +// getHandleResponse handles the Get response. +func (client *Client) getHandleResponse(resp *http.Response) (ClientGetResponse, error) { + result := ClientGetResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.FeatureResult); err != nil { + return ClientGetResponse{}, err + } + return result, nil +} + +// NewListPager - Gets all the preview features in a provider namespace that are available through AFEC for the subscription. +// +// Generated from API version 2021-07-01 +// - resourceProviderNamespace - The namespace of the resource provider for getting features. +// - options - ClientListOptions contains the optional parameters for the Client.NewListPager method. +func (client *Client) NewListPager(resourceProviderNamespace string, options *ClientListOptions) *runtime.Pager[ClientListResponse] { + return runtime.NewPager(runtime.PagingHandler[ClientListResponse]{ + More: func(page ClientListResponse) bool { + return page.NextLink != nil && len(*page.NextLink) > 0 + }, + Fetcher: func(ctx context.Context, page *ClientListResponse) (ClientListResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "Client.NewListPager") + nextLink := "" + if page != nil { + nextLink = *page.NextLink + } + resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { + return client.listCreateRequest(ctx, resourceProviderNamespace, options) + }, nil) + if err != nil { + return ClientListResponse{}, err + } + return client.listHandleResponse(resp) + }, + Tracer: client.internal.Tracer(), + }) +} + +// listCreateRequest creates the List request. +func (client *Client) listCreateRequest(ctx context.Context, resourceProviderNamespace string, options *ClientListOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Features/providers/{resourceProviderNamespace}/features" + if resourceProviderNamespace == "" { + return nil, errors.New("parameter resourceProviderNamespace cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceProviderNamespace}", url.PathEscape(resourceProviderNamespace)) + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-07-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json, text/json"} + return req, nil +} + +// listHandleResponse handles the List response. +func (client *Client) listHandleResponse(resp *http.Response) (ClientListResponse, error) { + result := ClientListResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.FeatureOperationsListResult); err != nil { + return ClientListResponse{}, err + } + return result, nil +} + +// NewListAllPager - Gets all the preview features that are available through AFEC for the subscription. +// +// Generated from API version 2021-07-01 +// - options - ClientListAllOptions contains the optional parameters for the Client.NewListAllPager method. +func (client *Client) NewListAllPager(options *ClientListAllOptions) *runtime.Pager[ClientListAllResponse] { + return runtime.NewPager(runtime.PagingHandler[ClientListAllResponse]{ + More: func(page ClientListAllResponse) bool { + return page.NextLink != nil && len(*page.NextLink) > 0 + }, + Fetcher: func(ctx context.Context, page *ClientListAllResponse) (ClientListAllResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "Client.NewListAllPager") + nextLink := "" + if page != nil { + nextLink = *page.NextLink + } + resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { + return client.listAllCreateRequest(ctx, options) + }, nil) + if err != nil { + return ClientListAllResponse{}, err + } + return client.listAllHandleResponse(resp) + }, + Tracer: client.internal.Tracer(), + }) +} + +// listAllCreateRequest creates the ListAll request. +func (client *Client) listAllCreateRequest(ctx context.Context, options *ClientListAllOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Features/features" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-07-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json, text/json"} + return req, nil +} + +// listAllHandleResponse handles the ListAll response. +func (client *Client) listAllHandleResponse(resp *http.Response) (ClientListAllResponse, error) { + result := ClientListAllResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.FeatureOperationsListResult); err != nil { + return ClientListAllResponse{}, err + } + return result, nil +} + +// Register - Registers the preview feature for the subscription. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2021-07-01 +// - resourceProviderNamespace - The namespace of the resource provider. +// - featureName - The name of the feature to register. +// - options - ClientRegisterOptions contains the optional parameters for the Client.Register method. +func (client *Client) Register(ctx context.Context, resourceProviderNamespace string, featureName string, options *ClientRegisterOptions) (ClientRegisterResponse, error) { + var err error + const operationName = "Client.Register" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() + req, err := client.registerCreateRequest(ctx, resourceProviderNamespace, featureName, options) + if err != nil { + return ClientRegisterResponse{}, err + } + httpResp, err := client.internal.Pipeline().Do(req) + if err != nil { + return ClientRegisterResponse{}, err + } + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ClientRegisterResponse{}, err + } + resp, err := client.registerHandleResponse(httpResp) + return resp, err +} + +// registerCreateRequest creates the Register request. +func (client *Client) registerCreateRequest(ctx context.Context, resourceProviderNamespace string, featureName string, options *ClientRegisterOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Features/providers/{resourceProviderNamespace}/features/{featureName}/register" + if resourceProviderNamespace == "" { + return nil, errors.New("parameter resourceProviderNamespace cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceProviderNamespace}", url.PathEscape(resourceProviderNamespace)) + if featureName == "" { + return nil, errors.New("parameter featureName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{featureName}", url.PathEscape(featureName)) + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-07-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json, text/json"} + return req, nil +} + +// registerHandleResponse handles the Register response. +func (client *Client) registerHandleResponse(resp *http.Response) (ClientRegisterResponse, error) { + result := ClientRegisterResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.FeatureResult); err != nil { + return ClientRegisterResponse{}, err + } + return result, nil +} + +// Unregister - Unregisters the preview feature for the subscription. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2021-07-01 +// - resourceProviderNamespace - The namespace of the resource provider. +// - featureName - The name of the feature to unregister. +// - options - ClientUnregisterOptions contains the optional parameters for the Client.Unregister method. +func (client *Client) Unregister(ctx context.Context, resourceProviderNamespace string, featureName string, options *ClientUnregisterOptions) (ClientUnregisterResponse, error) { + var err error + const operationName = "Client.Unregister" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() + req, err := client.unregisterCreateRequest(ctx, resourceProviderNamespace, featureName, options) + if err != nil { + return ClientUnregisterResponse{}, err + } + httpResp, err := client.internal.Pipeline().Do(req) + if err != nil { + return ClientUnregisterResponse{}, err + } + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return ClientUnregisterResponse{}, err + } + resp, err := client.unregisterHandleResponse(httpResp) + return resp, err +} + +// unregisterCreateRequest creates the Unregister request. +func (client *Client) unregisterCreateRequest(ctx context.Context, resourceProviderNamespace string, featureName string, options *ClientUnregisterOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Features/providers/{resourceProviderNamespace}/features/{featureName}/unregister" + if resourceProviderNamespace == "" { + return nil, errors.New("parameter resourceProviderNamespace cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceProviderNamespace}", url.PathEscape(resourceProviderNamespace)) + if featureName == "" { + return nil, errors.New("parameter featureName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{featureName}", url.PathEscape(featureName)) + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-07-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json, text/json"} + return req, nil +} + +// unregisterHandleResponse handles the Unregister response. +func (client *Client) unregisterHandleResponse(resp *http.Response) (ClientUnregisterResponse, error) { + result := ClientUnregisterResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.FeatureResult); err != nil { + return ClientUnregisterResponse{}, err + } + return result, nil +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/client_factory.go b/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/client_factory.go new file mode 100644 index 00000000000..9b131cfb417 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/client_factory.go @@ -0,0 +1,56 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armfeatures + +import ( + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" +) + +// ClientFactory is a client factory used to create any client in this module. +// Don't use this type directly, use NewClientFactory instead. +type ClientFactory struct { + subscriptionID string + credential azcore.TokenCredential + options *arm.ClientOptions +} + +// NewClientFactory creates a new instance of ClientFactory with the specified values. +// The parameter values will be propagated to any client created from this factory. +// - subscriptionID - The Azure subscription ID. +// - credential - used to authorize requests. Usually a credential from azidentity. +// - options - pass nil to accept the default values. +func NewClientFactory(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*ClientFactory, error) { + _, err := arm.NewClient(moduleName, moduleVersion, credential, options) + if err != nil { + return nil, err + } + return &ClientFactory{ + subscriptionID: subscriptionID, credential: credential, + options: options.Clone(), + }, nil +} + +// NewClient creates a new instance of Client. +func (c *ClientFactory) NewClient() *Client { + subClient, _ := NewClient(c.subscriptionID, c.credential, c.options) + return subClient +} + +// NewFeatureClient creates a new instance of FeatureClient. +func (c *ClientFactory) NewFeatureClient() *FeatureClient { + subClient, _ := NewFeatureClient(c.credential, c.options) + return subClient +} + +// NewSubscriptionFeatureRegistrationsClient creates a new instance of SubscriptionFeatureRegistrationsClient. +func (c *ClientFactory) NewSubscriptionFeatureRegistrationsClient() *SubscriptionFeatureRegistrationsClient { + subClient, _ := NewSubscriptionFeatureRegistrationsClient(c.subscriptionID, c.credential, c.options) + return subClient +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/constants.go b/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/constants.go new file mode 100644 index 00000000000..eb6e8a88741 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/constants.go @@ -0,0 +1,58 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armfeatures + +const ( + moduleName = "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures" + moduleVersion = "v1.2.0" +) + +// SubscriptionFeatureRegistrationApprovalType - The feature approval type. +type SubscriptionFeatureRegistrationApprovalType string + +const ( + SubscriptionFeatureRegistrationApprovalTypeApprovalRequired SubscriptionFeatureRegistrationApprovalType = "ApprovalRequired" + SubscriptionFeatureRegistrationApprovalTypeAutoApproval SubscriptionFeatureRegistrationApprovalType = "AutoApproval" + SubscriptionFeatureRegistrationApprovalTypeNotSpecified SubscriptionFeatureRegistrationApprovalType = "NotSpecified" +) + +// PossibleSubscriptionFeatureRegistrationApprovalTypeValues returns the possible values for the SubscriptionFeatureRegistrationApprovalType const type. +func PossibleSubscriptionFeatureRegistrationApprovalTypeValues() []SubscriptionFeatureRegistrationApprovalType { + return []SubscriptionFeatureRegistrationApprovalType{ + SubscriptionFeatureRegistrationApprovalTypeApprovalRequired, + SubscriptionFeatureRegistrationApprovalTypeAutoApproval, + SubscriptionFeatureRegistrationApprovalTypeNotSpecified, + } +} + +// SubscriptionFeatureRegistrationState - The state. +type SubscriptionFeatureRegistrationState string + +const ( + SubscriptionFeatureRegistrationStateNotRegistered SubscriptionFeatureRegistrationState = "NotRegistered" + SubscriptionFeatureRegistrationStateNotSpecified SubscriptionFeatureRegistrationState = "NotSpecified" + SubscriptionFeatureRegistrationStatePending SubscriptionFeatureRegistrationState = "Pending" + SubscriptionFeatureRegistrationStateRegistered SubscriptionFeatureRegistrationState = "Registered" + SubscriptionFeatureRegistrationStateRegistering SubscriptionFeatureRegistrationState = "Registering" + SubscriptionFeatureRegistrationStateUnregistered SubscriptionFeatureRegistrationState = "Unregistered" + SubscriptionFeatureRegistrationStateUnregistering SubscriptionFeatureRegistrationState = "Unregistering" +) + +// PossibleSubscriptionFeatureRegistrationStateValues returns the possible values for the SubscriptionFeatureRegistrationState const type. +func PossibleSubscriptionFeatureRegistrationStateValues() []SubscriptionFeatureRegistrationState { + return []SubscriptionFeatureRegistrationState{ + SubscriptionFeatureRegistrationStateNotRegistered, + SubscriptionFeatureRegistrationStateNotSpecified, + SubscriptionFeatureRegistrationStatePending, + SubscriptionFeatureRegistrationStateRegistered, + SubscriptionFeatureRegistrationStateRegistering, + SubscriptionFeatureRegistrationStateUnregistered, + SubscriptionFeatureRegistrationStateUnregistering, + } +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/feature_client.go b/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/feature_client.go new file mode 100644 index 00000000000..b50bb8d3e35 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/feature_client.go @@ -0,0 +1,89 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armfeatures + +import ( + "context" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" +) + +// FeatureClient contains the methods for the FeatureClient group. +// Don't use this type directly, use NewFeatureClient() instead. +type FeatureClient struct { + internal *arm.Client +} + +// NewFeatureClient creates a new instance of FeatureClient with the specified values. +// - credential - used to authorize requests. Usually a credential from azidentity. +// - options - pass nil to accept the default values. +func NewFeatureClient(credential azcore.TokenCredential, options *arm.ClientOptions) (*FeatureClient, error) { + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) + if err != nil { + return nil, err + } + client := &FeatureClient{ + internal: cl, + } + return client, nil +} + +// NewListOperationsPager - Lists all of the available Microsoft.Features REST API operations. +// +// Generated from API version 2021-07-01 +// - options - FeatureClientListOperationsOptions contains the optional parameters for the FeatureClient.NewListOperationsPager +// method. +func (client *FeatureClient) NewListOperationsPager(options *FeatureClientListOperationsOptions) *runtime.Pager[FeatureClientListOperationsResponse] { + return runtime.NewPager(runtime.PagingHandler[FeatureClientListOperationsResponse]{ + More: func(page FeatureClientListOperationsResponse) bool { + return page.NextLink != nil && len(*page.NextLink) > 0 + }, + Fetcher: func(ctx context.Context, page *FeatureClientListOperationsResponse) (FeatureClientListOperationsResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "FeatureClient.NewListOperationsPager") + nextLink := "" + if page != nil { + nextLink = *page.NextLink + } + resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { + return client.listOperationsCreateRequest(ctx, options) + }, nil) + if err != nil { + return FeatureClientListOperationsResponse{}, err + } + return client.listOperationsHandleResponse(resp) + }, + Tracer: client.internal.Tracer(), + }) +} + +// listOperationsCreateRequest creates the ListOperations request. +func (client *FeatureClient) listOperationsCreateRequest(ctx context.Context, options *FeatureClientListOperationsOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.Features/operations" + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-07-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json, text/json"} + return req, nil +} + +// listOperationsHandleResponse handles the ListOperations response. +func (client *FeatureClient) listOperationsHandleResponse(resp *http.Response) (FeatureClientListOperationsResponse, error) { + result := FeatureClientListOperationsResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.OperationListResult); err != nil { + return FeatureClientListOperationsResponse{}, err + } + return result, nil +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/models.go b/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/models.go new file mode 100644 index 00000000000..22ce5dfe733 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/models.go @@ -0,0 +1,187 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armfeatures + +import "time" + +// AuthorizationProfile - Authorization Profile +type AuthorizationProfile struct { + // READ-ONLY; The approved time + ApprovedTime *time.Time + + // READ-ONLY; The approver + Approver *string + + // READ-ONLY; The requested time + RequestedTime *time.Time + + // READ-ONLY; The requester + Requester *string + + // READ-ONLY; The requester object id + RequesterObjectID *string +} + +// ErrorDefinition - Error definition. +type ErrorDefinition struct { + // Internal error details. + Details []*ErrorDefinition + + // READ-ONLY; Service specific error code which serves as the substatus for the HTTP error code. + Code *string + + // READ-ONLY; Description of the error. + Message *string +} + +// ErrorResponse - Error response indicates that the service is not able to process the incoming request. +type ErrorResponse struct { + // The error details. + Error *ErrorDefinition +} + +// FeatureOperationsListResult - List of previewed features. +type FeatureOperationsListResult struct { + // The URL to use for getting the next set of results. + NextLink *string + + // The array of features. + Value []*FeatureResult +} + +// FeatureProperties - Information about feature. +type FeatureProperties struct { + // The registration state of the feature for the subscription. + State *string +} + +// FeatureResult - Previewed feature information. +type FeatureResult struct { + // The resource ID of the feature. + ID *string + + // The name of the feature. + Name *string + + // Properties of the previewed feature. + Properties *FeatureProperties + + // The resource type of the feature. + Type *string +} + +// Operation - Microsoft.Features operation +type Operation struct { + // The object that represents the operation. + Display *OperationDisplay + + // Operation name: {provider}/{resource}/{operation} + Name *string +} + +// OperationDisplay - The object that represents the operation. +type OperationDisplay struct { + // Operation type: Read, write, delete, etc. + Operation *string + + // Service provider: Microsoft.Features + Provider *string + + // Resource on which the operation is performed: Profile, endpoint, etc. + Resource *string +} + +// OperationListResult - Result of the request to list Microsoft.Features operations. It contains a list of operations and +// a URL link to get the next set of results. +type OperationListResult struct { + // URL to get the next set of operation list results if there are any. + NextLink *string + + // List of Microsoft.Features operations. + Value []*Operation +} + +// ProxyResource - An Azure proxy resource. +type ProxyResource struct { + // READ-ONLY; Azure resource Id. + ID *string + + // READ-ONLY; Azure resource name. + Name *string + + // READ-ONLY; Azure resource type. + Type *string +} + +// SubscriptionFeatureRegistration - Subscription feature registration details +type SubscriptionFeatureRegistration struct { + Properties *SubscriptionFeatureRegistrationProperties + + // READ-ONLY; Azure resource Id. + ID *string + + // READ-ONLY; Azure resource name. + Name *string + + // READ-ONLY; Azure resource type. + Type *string +} + +// SubscriptionFeatureRegistrationList - The list of subscription feature registrations. +type SubscriptionFeatureRegistrationList struct { + // The link used to get the next page of subscription feature registrations list. + NextLink *string + + // The list of subscription feature registrations. + Value []*SubscriptionFeatureRegistration +} + +type SubscriptionFeatureRegistrationProperties struct { + // Authorization Profile + AuthorizationProfile *AuthorizationProfile + + // The feature description. + Description *string + + // Key-value pairs for meta data. + Metadata map[string]*string + + // Indicates whether feature should be displayed in Portal. + ShouldFeatureDisplayInPortal *bool + + // The state. + State *SubscriptionFeatureRegistrationState + + // READ-ONLY; The feature approval type. + ApprovalType *SubscriptionFeatureRegistrationApprovalType + + // READ-ONLY; The featureDisplayName. + DisplayName *string + + // READ-ONLY; The feature documentation link. + DocumentationLink *string + + // READ-ONLY; The featureName. + FeatureName *string + + // READ-ONLY; The providerNamespace. + ProviderNamespace *string + + // READ-ONLY; The feature registration date. + RegistrationDate *time.Time + + // READ-ONLY; The feature release date. + ReleaseDate *time.Time + + // READ-ONLY; The subscriptionId. + SubscriptionID *string + + // READ-ONLY; The tenantId. + TenantID *string +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/models_serde.go b/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/models_serde.go new file mode 100644 index 00000000000..ca4a215d3ba --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/models_serde.go @@ -0,0 +1,519 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armfeatures + +import ( + "encoding/json" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "reflect" +) + +// MarshalJSON implements the json.Marshaller interface for type AuthorizationProfile. +func (a AuthorizationProfile) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populateDateTimeRFC3339(objectMap, "approvedTime", a.ApprovedTime) + populate(objectMap, "approver", a.Approver) + populateDateTimeRFC3339(objectMap, "requestedTime", a.RequestedTime) + populate(objectMap, "requester", a.Requester) + populate(objectMap, "requesterObjectId", a.RequesterObjectID) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type AuthorizationProfile. +func (a *AuthorizationProfile) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", a, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "approvedTime": + err = unpopulateDateTimeRFC3339(val, "ApprovedTime", &a.ApprovedTime) + delete(rawMsg, key) + case "approver": + err = unpopulate(val, "Approver", &a.Approver) + delete(rawMsg, key) + case "requestedTime": + err = unpopulateDateTimeRFC3339(val, "RequestedTime", &a.RequestedTime) + delete(rawMsg, key) + case "requester": + err = unpopulate(val, "Requester", &a.Requester) + delete(rawMsg, key) + case "requesterObjectId": + err = unpopulate(val, "RequesterObjectID", &a.RequesterObjectID) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", a, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type ErrorDefinition. +func (e ErrorDefinition) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "code", e.Code) + populate(objectMap, "details", e.Details) + populate(objectMap, "message", e.Message) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ErrorDefinition. +func (e *ErrorDefinition) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", e, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "code": + err = unpopulate(val, "Code", &e.Code) + delete(rawMsg, key) + case "details": + err = unpopulate(val, "Details", &e.Details) + delete(rawMsg, key) + case "message": + err = unpopulate(val, "Message", &e.Message) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", e, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type ErrorResponse. +func (e ErrorResponse) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "error", e.Error) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ErrorResponse. +func (e *ErrorResponse) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", e, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "error": + err = unpopulate(val, "Error", &e.Error) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", e, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type FeatureOperationsListResult. +func (f FeatureOperationsListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "nextLink", f.NextLink) + populate(objectMap, "value", f.Value) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type FeatureOperationsListResult. +func (f *FeatureOperationsListResult) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", f, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "nextLink": + err = unpopulate(val, "NextLink", &f.NextLink) + delete(rawMsg, key) + case "value": + err = unpopulate(val, "Value", &f.Value) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", f, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type FeatureProperties. +func (f FeatureProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "state", f.State) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type FeatureProperties. +func (f *FeatureProperties) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", f, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "state": + err = unpopulate(val, "State", &f.State) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", f, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type FeatureResult. +func (f FeatureResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "id", f.ID) + populate(objectMap, "name", f.Name) + populate(objectMap, "properties", f.Properties) + populate(objectMap, "type", f.Type) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type FeatureResult. +func (f *FeatureResult) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", f, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "id": + err = unpopulate(val, "ID", &f.ID) + delete(rawMsg, key) + case "name": + err = unpopulate(val, "Name", &f.Name) + delete(rawMsg, key) + case "properties": + err = unpopulate(val, "Properties", &f.Properties) + delete(rawMsg, key) + case "type": + err = unpopulate(val, "Type", &f.Type) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", f, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type Operation. +func (o Operation) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "display", o.Display) + populate(objectMap, "name", o.Name) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type Operation. +func (o *Operation) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "display": + err = unpopulate(val, "Display", &o.Display) + delete(rawMsg, key) + case "name": + err = unpopulate(val, "Name", &o.Name) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type OperationDisplay. +func (o OperationDisplay) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "operation", o.Operation) + populate(objectMap, "provider", o.Provider) + populate(objectMap, "resource", o.Resource) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type OperationDisplay. +func (o *OperationDisplay) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "operation": + err = unpopulate(val, "Operation", &o.Operation) + delete(rawMsg, key) + case "provider": + err = unpopulate(val, "Provider", &o.Provider) + delete(rawMsg, key) + case "resource": + err = unpopulate(val, "Resource", &o.Resource) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type OperationListResult. +func (o OperationListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "nextLink", o.NextLink) + populate(objectMap, "value", o.Value) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type OperationListResult. +func (o *OperationListResult) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "nextLink": + err = unpopulate(val, "NextLink", &o.NextLink) + delete(rawMsg, key) + case "value": + err = unpopulate(val, "Value", &o.Value) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type ProxyResource. +func (p ProxyResource) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "id", p.ID) + populate(objectMap, "name", p.Name) + populate(objectMap, "type", p.Type) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ProxyResource. +func (p *ProxyResource) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", p, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "id": + err = unpopulate(val, "ID", &p.ID) + delete(rawMsg, key) + case "name": + err = unpopulate(val, "Name", &p.Name) + delete(rawMsg, key) + case "type": + err = unpopulate(val, "Type", &p.Type) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", p, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type SubscriptionFeatureRegistration. +func (s SubscriptionFeatureRegistration) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "id", s.ID) + populate(objectMap, "name", s.Name) + populate(objectMap, "properties", s.Properties) + populate(objectMap, "type", s.Type) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type SubscriptionFeatureRegistration. +func (s *SubscriptionFeatureRegistration) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "id": + err = unpopulate(val, "ID", &s.ID) + delete(rawMsg, key) + case "name": + err = unpopulate(val, "Name", &s.Name) + delete(rawMsg, key) + case "properties": + err = unpopulate(val, "Properties", &s.Properties) + delete(rawMsg, key) + case "type": + err = unpopulate(val, "Type", &s.Type) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type SubscriptionFeatureRegistrationList. +func (s SubscriptionFeatureRegistrationList) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "nextLink", s.NextLink) + populate(objectMap, "value", s.Value) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type SubscriptionFeatureRegistrationList. +func (s *SubscriptionFeatureRegistrationList) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "nextLink": + err = unpopulate(val, "NextLink", &s.NextLink) + delete(rawMsg, key) + case "value": + err = unpopulate(val, "Value", &s.Value) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type SubscriptionFeatureRegistrationProperties. +func (s SubscriptionFeatureRegistrationProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "approvalType", s.ApprovalType) + populate(objectMap, "authorizationProfile", s.AuthorizationProfile) + populate(objectMap, "description", s.Description) + populate(objectMap, "displayName", s.DisplayName) + populate(objectMap, "documentationLink", s.DocumentationLink) + populate(objectMap, "featureName", s.FeatureName) + populate(objectMap, "metadata", s.Metadata) + populate(objectMap, "providerNamespace", s.ProviderNamespace) + populateDateTimeRFC3339(objectMap, "registrationDate", s.RegistrationDate) + populateDateTimeRFC3339(objectMap, "releaseDate", s.ReleaseDate) + populate(objectMap, "shouldFeatureDisplayInPortal", s.ShouldFeatureDisplayInPortal) + populate(objectMap, "state", s.State) + populate(objectMap, "subscriptionId", s.SubscriptionID) + populate(objectMap, "tenantId", s.TenantID) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type SubscriptionFeatureRegistrationProperties. +func (s *SubscriptionFeatureRegistrationProperties) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "approvalType": + err = unpopulate(val, "ApprovalType", &s.ApprovalType) + delete(rawMsg, key) + case "authorizationProfile": + err = unpopulate(val, "AuthorizationProfile", &s.AuthorizationProfile) + delete(rawMsg, key) + case "description": + err = unpopulate(val, "Description", &s.Description) + delete(rawMsg, key) + case "displayName": + err = unpopulate(val, "DisplayName", &s.DisplayName) + delete(rawMsg, key) + case "documentationLink": + err = unpopulate(val, "DocumentationLink", &s.DocumentationLink) + delete(rawMsg, key) + case "featureName": + err = unpopulate(val, "FeatureName", &s.FeatureName) + delete(rawMsg, key) + case "metadata": + err = unpopulate(val, "Metadata", &s.Metadata) + delete(rawMsg, key) + case "providerNamespace": + err = unpopulate(val, "ProviderNamespace", &s.ProviderNamespace) + delete(rawMsg, key) + case "registrationDate": + err = unpopulateDateTimeRFC3339(val, "RegistrationDate", &s.RegistrationDate) + delete(rawMsg, key) + case "releaseDate": + err = unpopulateDateTimeRFC3339(val, "ReleaseDate", &s.ReleaseDate) + delete(rawMsg, key) + case "shouldFeatureDisplayInPortal": + err = unpopulate(val, "ShouldFeatureDisplayInPortal", &s.ShouldFeatureDisplayInPortal) + delete(rawMsg, key) + case "state": + err = unpopulate(val, "State", &s.State) + delete(rawMsg, key) + case "subscriptionId": + err = unpopulate(val, "SubscriptionID", &s.SubscriptionID) + delete(rawMsg, key) + case "tenantId": + err = unpopulate(val, "TenantID", &s.TenantID) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + } + return nil +} + +func populate(m map[string]any, k string, v any) { + if v == nil { + return + } else if azcore.IsNullValue(v) { + m[k] = nil + } else if !reflect.ValueOf(v).IsNil() { + m[k] = v + } +} + +func unpopulate(data json.RawMessage, fn string, v any) error { + if data == nil { + return nil + } + if err := json.Unmarshal(data, v); err != nil { + return fmt.Errorf("struct field %s: %v", fn, err) + } + return nil +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/options.go b/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/options.go new file mode 100644 index 00000000000..5092b41920c --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/options.go @@ -0,0 +1,70 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armfeatures + +// ClientGetOptions contains the optional parameters for the Client.Get method. +type ClientGetOptions struct { + // placeholder for future optional parameters +} + +// ClientListAllOptions contains the optional parameters for the Client.NewListAllPager method. +type ClientListAllOptions struct { + // placeholder for future optional parameters +} + +// ClientListOptions contains the optional parameters for the Client.NewListPager method. +type ClientListOptions struct { + // placeholder for future optional parameters +} + +// ClientRegisterOptions contains the optional parameters for the Client.Register method. +type ClientRegisterOptions struct { + // placeholder for future optional parameters +} + +// ClientUnregisterOptions contains the optional parameters for the Client.Unregister method. +type ClientUnregisterOptions struct { + // placeholder for future optional parameters +} + +// FeatureClientListOperationsOptions contains the optional parameters for the FeatureClient.NewListOperationsPager method. +type FeatureClientListOperationsOptions struct { + // placeholder for future optional parameters +} + +// SubscriptionFeatureRegistrationsClientCreateOrUpdateOptions contains the optional parameters for the SubscriptionFeatureRegistrationsClient.CreateOrUpdate +// method. +type SubscriptionFeatureRegistrationsClientCreateOrUpdateOptions struct { + // Subscription Feature Registration Type details. + SubscriptionFeatureRegistrationType *SubscriptionFeatureRegistration +} + +// SubscriptionFeatureRegistrationsClientDeleteOptions contains the optional parameters for the SubscriptionFeatureRegistrationsClient.Delete +// method. +type SubscriptionFeatureRegistrationsClientDeleteOptions struct { + // placeholder for future optional parameters +} + +// SubscriptionFeatureRegistrationsClientGetOptions contains the optional parameters for the SubscriptionFeatureRegistrationsClient.Get +// method. +type SubscriptionFeatureRegistrationsClientGetOptions struct { + // placeholder for future optional parameters +} + +// SubscriptionFeatureRegistrationsClientListAllBySubscriptionOptions contains the optional parameters for the SubscriptionFeatureRegistrationsClient.NewListAllBySubscriptionPager +// method. +type SubscriptionFeatureRegistrationsClientListAllBySubscriptionOptions struct { + // placeholder for future optional parameters +} + +// SubscriptionFeatureRegistrationsClientListBySubscriptionOptions contains the optional parameters for the SubscriptionFeatureRegistrationsClient.NewListBySubscriptionPager +// method. +type SubscriptionFeatureRegistrationsClientListBySubscriptionOptions struct { + // placeholder for future optional parameters +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/response_types.go b/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/response_types.go new file mode 100644 index 00000000000..d30455ab2a5 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/response_types.go @@ -0,0 +1,75 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armfeatures + +// ClientGetResponse contains the response from method Client.Get. +type ClientGetResponse struct { + // Previewed feature information. + FeatureResult +} + +// ClientListAllResponse contains the response from method Client.NewListAllPager. +type ClientListAllResponse struct { + // List of previewed features. + FeatureOperationsListResult +} + +// ClientListResponse contains the response from method Client.NewListPager. +type ClientListResponse struct { + // List of previewed features. + FeatureOperationsListResult +} + +// ClientRegisterResponse contains the response from method Client.Register. +type ClientRegisterResponse struct { + // Previewed feature information. + FeatureResult +} + +// ClientUnregisterResponse contains the response from method Client.Unregister. +type ClientUnregisterResponse struct { + // Previewed feature information. + FeatureResult +} + +// FeatureClientListOperationsResponse contains the response from method FeatureClient.NewListOperationsPager. +type FeatureClientListOperationsResponse struct { + // Result of the request to list Microsoft.Features operations. It contains a list of operations and a URL link to get the + // next set of results. + OperationListResult +} + +// SubscriptionFeatureRegistrationsClientCreateOrUpdateResponse contains the response from method SubscriptionFeatureRegistrationsClient.CreateOrUpdate. +type SubscriptionFeatureRegistrationsClientCreateOrUpdateResponse struct { + // Subscription feature registration details + SubscriptionFeatureRegistration +} + +// SubscriptionFeatureRegistrationsClientDeleteResponse contains the response from method SubscriptionFeatureRegistrationsClient.Delete. +type SubscriptionFeatureRegistrationsClientDeleteResponse struct { + // placeholder for future response values +} + +// SubscriptionFeatureRegistrationsClientGetResponse contains the response from method SubscriptionFeatureRegistrationsClient.Get. +type SubscriptionFeatureRegistrationsClientGetResponse struct { + // Subscription feature registration details + SubscriptionFeatureRegistration +} + +// SubscriptionFeatureRegistrationsClientListAllBySubscriptionResponse contains the response from method SubscriptionFeatureRegistrationsClient.NewListAllBySubscriptionPager. +type SubscriptionFeatureRegistrationsClientListAllBySubscriptionResponse struct { + // The list of subscription feature registrations. + SubscriptionFeatureRegistrationList +} + +// SubscriptionFeatureRegistrationsClientListBySubscriptionResponse contains the response from method SubscriptionFeatureRegistrationsClient.NewListBySubscriptionPager. +type SubscriptionFeatureRegistrationsClientListBySubscriptionResponse struct { + // The list of subscription feature registrations. + SubscriptionFeatureRegistrationList +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/subscriptionfeatureregistrations_client.go b/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/subscriptionfeatureregistrations_client.go new file mode 100644 index 00000000000..cc67099e7d0 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/subscriptionfeatureregistrations_client.go @@ -0,0 +1,350 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armfeatures + +import ( + "context" + "errors" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "net/url" + "strings" +) + +// SubscriptionFeatureRegistrationsClient contains the methods for the SubscriptionFeatureRegistrations group. +// Don't use this type directly, use NewSubscriptionFeatureRegistrationsClient() instead. +type SubscriptionFeatureRegistrationsClient struct { + internal *arm.Client + subscriptionID string +} + +// NewSubscriptionFeatureRegistrationsClient creates a new instance of SubscriptionFeatureRegistrationsClient with the specified values. +// - subscriptionID - The Azure subscription ID. +// - credential - used to authorize requests. Usually a credential from azidentity. +// - options - pass nil to accept the default values. +func NewSubscriptionFeatureRegistrationsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*SubscriptionFeatureRegistrationsClient, error) { + cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) + if err != nil { + return nil, err + } + client := &SubscriptionFeatureRegistrationsClient{ + subscriptionID: subscriptionID, + internal: cl, + } + return client, nil +} + +// CreateOrUpdate - Create or update a feature registration. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2021-07-01 +// - providerNamespace - The provider namespace. +// - featureName - The feature name. +// - options - SubscriptionFeatureRegistrationsClientCreateOrUpdateOptions contains the optional parameters for the SubscriptionFeatureRegistrationsClient.CreateOrUpdate +// method. +func (client *SubscriptionFeatureRegistrationsClient) CreateOrUpdate(ctx context.Context, providerNamespace string, featureName string, options *SubscriptionFeatureRegistrationsClientCreateOrUpdateOptions) (SubscriptionFeatureRegistrationsClientCreateOrUpdateResponse, error) { + var err error + const operationName = "SubscriptionFeatureRegistrationsClient.CreateOrUpdate" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() + req, err := client.createOrUpdateCreateRequest(ctx, providerNamespace, featureName, options) + if err != nil { + return SubscriptionFeatureRegistrationsClientCreateOrUpdateResponse{}, err + } + httpResp, err := client.internal.Pipeline().Do(req) + if err != nil { + return SubscriptionFeatureRegistrationsClientCreateOrUpdateResponse{}, err + } + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return SubscriptionFeatureRegistrationsClientCreateOrUpdateResponse{}, err + } + resp, err := client.createOrUpdateHandleResponse(httpResp) + return resp, err +} + +// createOrUpdateCreateRequest creates the CreateOrUpdate request. +func (client *SubscriptionFeatureRegistrationsClient) createOrUpdateCreateRequest(ctx context.Context, providerNamespace string, featureName string, options *SubscriptionFeatureRegistrationsClientCreateOrUpdateOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Features/featureProviders/{providerNamespace}/subscriptionFeatureRegistrations/{featureName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if providerNamespace == "" { + return nil, errors.New("parameter providerNamespace cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{providerNamespace}", url.PathEscape(providerNamespace)) + if featureName == "" { + return nil, errors.New("parameter featureName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{featureName}", url.PathEscape(featureName)) + req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-07-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + if options != nil && options.SubscriptionFeatureRegistrationType != nil { + if err := runtime.MarshalAsJSON(req, *options.SubscriptionFeatureRegistrationType); err != nil { + return nil, err + } + return req, nil + } + return req, nil +} + +// createOrUpdateHandleResponse handles the CreateOrUpdate response. +func (client *SubscriptionFeatureRegistrationsClient) createOrUpdateHandleResponse(resp *http.Response) (SubscriptionFeatureRegistrationsClientCreateOrUpdateResponse, error) { + result := SubscriptionFeatureRegistrationsClientCreateOrUpdateResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.SubscriptionFeatureRegistration); err != nil { + return SubscriptionFeatureRegistrationsClientCreateOrUpdateResponse{}, err + } + return result, nil +} + +// Delete - Deletes a feature registration +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2021-07-01 +// - providerNamespace - The provider namespace. +// - featureName - The feature name. +// - options - SubscriptionFeatureRegistrationsClientDeleteOptions contains the optional parameters for the SubscriptionFeatureRegistrationsClient.Delete +// method. +func (client *SubscriptionFeatureRegistrationsClient) Delete(ctx context.Context, providerNamespace string, featureName string, options *SubscriptionFeatureRegistrationsClientDeleteOptions) (SubscriptionFeatureRegistrationsClientDeleteResponse, error) { + var err error + const operationName = "SubscriptionFeatureRegistrationsClient.Delete" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() + req, err := client.deleteCreateRequest(ctx, providerNamespace, featureName, options) + if err != nil { + return SubscriptionFeatureRegistrationsClientDeleteResponse{}, err + } + httpResp, err := client.internal.Pipeline().Do(req) + if err != nil { + return SubscriptionFeatureRegistrationsClientDeleteResponse{}, err + } + if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusNoContent) { + err = runtime.NewResponseError(httpResp) + return SubscriptionFeatureRegistrationsClientDeleteResponse{}, err + } + return SubscriptionFeatureRegistrationsClientDeleteResponse{}, nil +} + +// deleteCreateRequest creates the Delete request. +func (client *SubscriptionFeatureRegistrationsClient) deleteCreateRequest(ctx context.Context, providerNamespace string, featureName string, options *SubscriptionFeatureRegistrationsClientDeleteOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Features/featureProviders/{providerNamespace}/subscriptionFeatureRegistrations/{featureName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if providerNamespace == "" { + return nil, errors.New("parameter providerNamespace cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{providerNamespace}", url.PathEscape(providerNamespace)) + if featureName == "" { + return nil, errors.New("parameter featureName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{featureName}", url.PathEscape(featureName)) + req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-07-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// Get - Returns a feature registration +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2021-07-01 +// - providerNamespace - The provider namespace. +// - featureName - The feature name. +// - options - SubscriptionFeatureRegistrationsClientGetOptions contains the optional parameters for the SubscriptionFeatureRegistrationsClient.Get +// method. +func (client *SubscriptionFeatureRegistrationsClient) Get(ctx context.Context, providerNamespace string, featureName string, options *SubscriptionFeatureRegistrationsClientGetOptions) (SubscriptionFeatureRegistrationsClientGetResponse, error) { + var err error + const operationName = "SubscriptionFeatureRegistrationsClient.Get" + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) + ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) + defer func() { endSpan(err) }() + req, err := client.getCreateRequest(ctx, providerNamespace, featureName, options) + if err != nil { + return SubscriptionFeatureRegistrationsClientGetResponse{}, err + } + httpResp, err := client.internal.Pipeline().Do(req) + if err != nil { + return SubscriptionFeatureRegistrationsClientGetResponse{}, err + } + if !runtime.HasStatusCode(httpResp, http.StatusOK) { + err = runtime.NewResponseError(httpResp) + return SubscriptionFeatureRegistrationsClientGetResponse{}, err + } + resp, err := client.getHandleResponse(httpResp) + return resp, err +} + +// getCreateRequest creates the Get request. +func (client *SubscriptionFeatureRegistrationsClient) getCreateRequest(ctx context.Context, providerNamespace string, featureName string, options *SubscriptionFeatureRegistrationsClientGetOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Features/featureProviders/{providerNamespace}/subscriptionFeatureRegistrations/{featureName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if providerNamespace == "" { + return nil, errors.New("parameter providerNamespace cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{providerNamespace}", url.PathEscape(providerNamespace)) + if featureName == "" { + return nil, errors.New("parameter featureName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{featureName}", url.PathEscape(featureName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-07-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// getHandleResponse handles the Get response. +func (client *SubscriptionFeatureRegistrationsClient) getHandleResponse(resp *http.Response) (SubscriptionFeatureRegistrationsClientGetResponse, error) { + result := SubscriptionFeatureRegistrationsClientGetResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.SubscriptionFeatureRegistration); err != nil { + return SubscriptionFeatureRegistrationsClientGetResponse{}, err + } + return result, nil +} + +// NewListAllBySubscriptionPager - Returns subscription feature registrations for given subscription. +// +// Generated from API version 2021-07-01 +// - options - SubscriptionFeatureRegistrationsClientListAllBySubscriptionOptions contains the optional parameters for the SubscriptionFeatureRegistrationsClient.NewListAllBySubscriptionPager +// method. +func (client *SubscriptionFeatureRegistrationsClient) NewListAllBySubscriptionPager(options *SubscriptionFeatureRegistrationsClientListAllBySubscriptionOptions) *runtime.Pager[SubscriptionFeatureRegistrationsClientListAllBySubscriptionResponse] { + return runtime.NewPager(runtime.PagingHandler[SubscriptionFeatureRegistrationsClientListAllBySubscriptionResponse]{ + More: func(page SubscriptionFeatureRegistrationsClientListAllBySubscriptionResponse) bool { + return page.NextLink != nil && len(*page.NextLink) > 0 + }, + Fetcher: func(ctx context.Context, page *SubscriptionFeatureRegistrationsClientListAllBySubscriptionResponse) (SubscriptionFeatureRegistrationsClientListAllBySubscriptionResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "SubscriptionFeatureRegistrationsClient.NewListAllBySubscriptionPager") + nextLink := "" + if page != nil { + nextLink = *page.NextLink + } + resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { + return client.listAllBySubscriptionCreateRequest(ctx, options) + }, nil) + if err != nil { + return SubscriptionFeatureRegistrationsClientListAllBySubscriptionResponse{}, err + } + return client.listAllBySubscriptionHandleResponse(resp) + }, + Tracer: client.internal.Tracer(), + }) +} + +// listAllBySubscriptionCreateRequest creates the ListAllBySubscription request. +func (client *SubscriptionFeatureRegistrationsClient) listAllBySubscriptionCreateRequest(ctx context.Context, options *SubscriptionFeatureRegistrationsClientListAllBySubscriptionOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Features/subscriptionFeatureRegistrations" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-07-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// listAllBySubscriptionHandleResponse handles the ListAllBySubscription response. +func (client *SubscriptionFeatureRegistrationsClient) listAllBySubscriptionHandleResponse(resp *http.Response) (SubscriptionFeatureRegistrationsClientListAllBySubscriptionResponse, error) { + result := SubscriptionFeatureRegistrationsClientListAllBySubscriptionResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.SubscriptionFeatureRegistrationList); err != nil { + return SubscriptionFeatureRegistrationsClientListAllBySubscriptionResponse{}, err + } + return result, nil +} + +// NewListBySubscriptionPager - Returns subscription feature registrations for given subscription and provider namespace. +// +// Generated from API version 2021-07-01 +// - providerNamespace - The provider namespace. +// - options - SubscriptionFeatureRegistrationsClientListBySubscriptionOptions contains the optional parameters for the SubscriptionFeatureRegistrationsClient.NewListBySubscriptionPager +// method. +func (client *SubscriptionFeatureRegistrationsClient) NewListBySubscriptionPager(providerNamespace string, options *SubscriptionFeatureRegistrationsClientListBySubscriptionOptions) *runtime.Pager[SubscriptionFeatureRegistrationsClientListBySubscriptionResponse] { + return runtime.NewPager(runtime.PagingHandler[SubscriptionFeatureRegistrationsClientListBySubscriptionResponse]{ + More: func(page SubscriptionFeatureRegistrationsClientListBySubscriptionResponse) bool { + return page.NextLink != nil && len(*page.NextLink) > 0 + }, + Fetcher: func(ctx context.Context, page *SubscriptionFeatureRegistrationsClientListBySubscriptionResponse) (SubscriptionFeatureRegistrationsClientListBySubscriptionResponse, error) { + ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "SubscriptionFeatureRegistrationsClient.NewListBySubscriptionPager") + nextLink := "" + if page != nil { + nextLink = *page.NextLink + } + resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { + return client.listBySubscriptionCreateRequest(ctx, providerNamespace, options) + }, nil) + if err != nil { + return SubscriptionFeatureRegistrationsClientListBySubscriptionResponse{}, err + } + return client.listBySubscriptionHandleResponse(resp) + }, + Tracer: client.internal.Tracer(), + }) +} + +// listBySubscriptionCreateRequest creates the ListBySubscription request. +func (client *SubscriptionFeatureRegistrationsClient) listBySubscriptionCreateRequest(ctx context.Context, providerNamespace string, options *SubscriptionFeatureRegistrationsClientListBySubscriptionOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Features/featureProviders/{providerNamespace}/subscriptionFeatureRegistrations" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if providerNamespace == "" { + return nil, errors.New("parameter providerNamespace cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{providerNamespace}", url.PathEscape(providerNamespace)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-07-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// listBySubscriptionHandleResponse handles the ListBySubscription response. +func (client *SubscriptionFeatureRegistrationsClient) listBySubscriptionHandleResponse(resp *http.Response) (SubscriptionFeatureRegistrationsClientListBySubscriptionResponse, error) { + result := SubscriptionFeatureRegistrationsClientListBySubscriptionResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.SubscriptionFeatureRegistrationList); err != nil { + return SubscriptionFeatureRegistrationsClientListBySubscriptionResponse{}, err + } + return result, nil +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/time_rfc3339.go b/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/time_rfc3339.go new file mode 100644 index 00000000000..19d49fb2bc1 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures/time_rfc3339.go @@ -0,0 +1,86 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armfeatures + +import ( + "encoding/json" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "reflect" + "regexp" + "strings" + "time" +) + +// Azure reports time in UTC but it doesn't include the 'Z' time zone suffix in some cases. +var tzOffsetRegex = regexp.MustCompile(`(Z|z|\+|-)(\d+:\d+)*"*$`) + +const ( + utcDateTimeJSON = `"2006-01-02T15:04:05.999999999"` + utcDateTime = "2006-01-02T15:04:05.999999999" + dateTimeJSON = `"` + time.RFC3339Nano + `"` +) + +type dateTimeRFC3339 time.Time + +func (t dateTimeRFC3339) MarshalJSON() ([]byte, error) { + tt := time.Time(t) + return tt.MarshalJSON() +} + +func (t dateTimeRFC3339) MarshalText() ([]byte, error) { + tt := time.Time(t) + return tt.MarshalText() +} + +func (t *dateTimeRFC3339) UnmarshalJSON(data []byte) error { + layout := utcDateTimeJSON + if tzOffsetRegex.Match(data) { + layout = dateTimeJSON + } + return t.Parse(layout, string(data)) +} + +func (t *dateTimeRFC3339) UnmarshalText(data []byte) error { + layout := utcDateTime + if tzOffsetRegex.Match(data) { + layout = time.RFC3339Nano + } + return t.Parse(layout, string(data)) +} + +func (t *dateTimeRFC3339) Parse(layout, value string) error { + p, err := time.Parse(layout, strings.ToUpper(value)) + *t = dateTimeRFC3339(p) + return err +} + +func populateDateTimeRFC3339(m map[string]any, k string, t *time.Time) { + if t == nil { + return + } else if azcore.IsNullValue(t) { + m[k] = nil + return + } else if reflect.ValueOf(t).IsNil() { + return + } + m[k] = (*dateTimeRFC3339)(t) +} + +func unpopulateDateTimeRFC3339(data json.RawMessage, fn string, t **time.Time) error { + if data == nil || strings.EqualFold(string(data), "null") { + return nil + } + var aux dateTimeRFC3339 + if err := json.Unmarshal(data, &aux); err != nil { + return fmt.Errorf("struct field %s: %v", fn, err) + } + *t = (*time.Time)(&aux) + return nil +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 31ab50bd04c..9768ac27579 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -70,6 +70,9 @@ github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/keyvault/armkeyvault # github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v2 v2.2.1 ## explicit; go 1.18 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v2 +# github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures v1.2.0 +## explicit; go 1.18 +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures # github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage v1.5.0 ## explicit; go 1.18 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage