diff --git a/go.mod b/go.mod index 4c0830bd870..c0e5712285f 100644 --- a/go.mod +++ b/go.mod @@ -18,6 +18,7 @@ require ( github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/monitor/armmonitor v0.11.0 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/msi/armmsi v1.3.0 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6 v6.2.0 + 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.8.1 github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azcertificates v1.4.0 github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azsecrets v1.4.0 diff --git a/go.sum b/go.sum index 25f2d450078..9aa9beb397d 100644 --- a/go.sum +++ b/go.sum @@ -38,6 +38,8 @@ github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/msi/armmsi v1.3.0 h1:L7G3d github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/msi/armmsi v1.3.0/go.mod h1:Ms6gYEy0+A2knfKrwdatsggTXYA2+ICKug8w7STorFw= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6 v6.2.0 h1:HYGD75g0bQ3VO/Omedm54v4LrD3B1cGImuRF3AJ5wLo= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6 v6.2.0/go.mod h1:ulHyBFJOI0ONiRL4vcJTmS7rx18jQQlEPmAgo80cRdM= +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.2.0 h1:Dd+RhdJn0OTtVGaeDLZpcumkIVCtA/3/Fo42+eoYvVM= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.2.0/go.mod h1:5kakwfW5CjC9KK+Q4wjXAg+ShuIm2mBMua0ZFj2C8PE= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage v1.8.1 h1:/Zt+cDPnpC3OVDm/JKLOs7M2DKmLRIIp3XIx9pHHiig= diff --git a/pkg/frontend/features_validation.go b/pkg/frontend/features_validation.go new file mode 100644 index 00000000000..c61442655b7 --- /dev/null +++ b/pkg/frontend/features_validation.go @@ -0,0 +1,77 @@ +package frontend + +// Copyright (c) Microsoft Corporation. +// Licensed under the Apache License 2.0. + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + + "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 FeaturesValidator interface { + ValidateSubscriptionFeatures(ctx context.Context, environment env.Interface, subscriptionID string, fpCred azcore.TokenCredential, oc *api.OpenShiftCluster) error +} + +type featuresValidator struct{} + +func (f featuresValidator) ValidateSubscriptionFeatures(ctx context.Context, environment env.Interface, subscriptionID string, fpCred azcore.TokenCredential, oc *api.OpenShiftCluster) error { + var fieldPath string + if oc.Properties.MasterProfile.EncryptionAtHost == api.EncryptionAtHostEnabled { + fieldPath = "properties.masterProfile.encryptionAtHost" + } else if oc.Properties.WorkerProfiles[0].EncryptionAtHost == api.EncryptionAtHostEnabled { + fieldPath = "properties.workerProfiles[0].encryptionAtHost" + } + + if fieldPath != "" { + featuresClient, err := armfeatures.NewFeaturesClient(subscriptionID, fpCred, environment.Environment().ArmClientOptions()) + if err != nil { + return err + } + + return validateEncryptionAtHostFeature(ctx, featuresClient, subscriptionID, fieldPath) + } + return nil +} + +func validateEncryptionAtHostFeature( + ctx context.Context, + featuresClient armfeatures.FeaturesClient, + subscriptionID, fieldPath string, +) error { + resp, err := featuresClient.Get(ctx, "Microsoft.Compute", "EncryptionAtHost", nil) + if err != nil { + return err + } + + if resp.Properties == nil || resp.Properties.State == nil { + return api.NewCloudError( + http.StatusInternalServerError, + api.CloudErrorCodeInternalServerError, + "", + fmt.Sprintf( + "Microsoft.Compute/EncryptionAtHost"+ + " feature has no state for"+ + " subscription %s.", + subscriptionID)) + } + + if *resp.Properties.State != "Registered" { + return api.NewCloudError( + http.StatusBadRequest, + api.CloudErrorCodeInvalidParameter, + fieldPath, + fmt.Sprintf( + "Microsoft.Compute/EncryptionAtHost feature is not registered on subscription %s. "+ + "Please register the feature on your subscription before creating the cluster.", + subscriptionID)) + } + + return nil +} diff --git a/pkg/frontend/features_validation_test.go b/pkg/frontend/features_validation_test.go new file mode 100644 index 00000000000..697f2065a9c --- /dev/null +++ b/pkg/frontend/features_validation_test.go @@ -0,0 +1,104 @@ +package frontend + +// Copyright (c) Microsoft Corporation. +// Licensed under the Apache License 2.0. + +import ( + "context" + "errors" + "testing" + + "go.uber.org/mock/gomock" + + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures" + + mock_armfeatures "github.com/Azure/ARO-RP/pkg/util/mocks/azureclient/azuresdk/armfeatures" + "github.com/Azure/ARO-RP/pkg/util/pointerutils" +) + +func TestValidateEncryptionAtHostFeature(t *testing.T) { + ctx := context.Background() + + for _, tt := range []struct { + name string + fieldPath string + mockFeatureState *string + mockPropertiesNil bool + mockStateNil bool + mockGetErr error + wantErr string + }{ + { + name: "feature is registered - should return nil", + fieldPath: "properties.masterProfile.encryptionAtHost", + mockFeatureState: pointerutils.ToPtr("Registered"), + wantErr: "", + }, + { + name: "feature is not registered - should return 400 BadRequest", + fieldPath: "properties.masterProfile.encryptionAtHost", + mockFeatureState: pointerutils.ToPtr("NotRegistered"), + wantErr: "400: InvalidParameter: properties.masterProfile.encryptionAtHost: Microsoft.Compute/EncryptionAtHost feature is not registered on subscription test-subscription. Please register the feature on your subscription before creating the cluster.", + }, + { + name: "resp.Properties is nil - should return internal server error", + fieldPath: "properties.workerProfiles[0].encryptionAtHost", + mockPropertiesNil: true, + wantErr: "500: InternalServerError: : Microsoft.Compute/EncryptionAtHost feature has no state for subscription test-subscription.", + }, + { + name: "resp.Properties.State is nil - should return internal server error", + fieldPath: "properties.masterProfile.encryptionAtHost", + mockStateNil: true, + wantErr: "500: InternalServerError: : Microsoft.Compute/EncryptionAtHost feature has no state for subscription test-subscription.", + }, + { + name: "Get returns error", + fieldPath: "properties.masterProfile.encryptionAtHost", + mockGetErr: errors.New("random error"), + wantErr: "random error", + }, + } { + t.Run(tt.name, func(t *testing.T) { + controller := gomock.NewController(t) + defer controller.Finish() + + featuresClient := mock_armfeatures.NewMockFeaturesClient(controller) + + var mockResponse armfeatures.ClientGetResponse + if tt.mockPropertiesNil { + mockResponse = armfeatures.ClientGetResponse{ + FeatureResult: armfeatures.FeatureResult{ + Properties: nil, + }, + } + } else if tt.mockStateNil { + mockResponse = armfeatures.ClientGetResponse{ + FeatureResult: armfeatures.FeatureResult{ + Properties: &armfeatures.FeatureProperties{ + State: nil, + }, + }, + } + } else if tt.mockFeatureState != nil { + mockResponse = armfeatures.ClientGetResponse{ + FeatureResult: armfeatures.FeatureResult{ + Properties: &armfeatures.FeatureProperties{ + State: tt.mockFeatureState, + }, + }, + } + } + + featuresClient.EXPECT(). + Get(ctx, "Microsoft.Compute", "EncryptionAtHost", nil). + Return(mockResponse, tt.mockGetErr) + + err := validateEncryptionAtHostFeature(ctx, featuresClient, "test-subscription", tt.fieldPath) + if err != nil && err.Error() != tt.wantErr || + err == nil && tt.wantErr != "" { + t.Errorf("expected error %q, got %q", tt.wantErr, err) + } + }) + } +} diff --git a/pkg/frontend/frontend.go b/pkg/frontend/frontend.go index 254be2197a5..a16566d23e2 100644 --- a/pkg/frontend/frontend.go +++ b/pkg/frontend/frontend.go @@ -104,6 +104,7 @@ type frontend struct { skuValidator SkuValidator quotaValidator QuotaValidator providersValidator ProvidersValidator + featuresValidator FeaturesValidator clusterEnricher clusterdata.BestEffortEnricher @@ -188,6 +189,7 @@ func NewFrontend(ctx context.Context, quotaValidator: quotaValidator{}, skuValidator: skuValidator{}, providersValidator: providersValidator{}, + featuresValidator: featuresValidator{}, clusterEnricher: enricher, diff --git a/pkg/frontend/generate.go b/pkg/frontend/generate.go index 8f3de552f88..cee57c5c5d6 100644 --- a/pkg/frontend/generate.go +++ b/pkg/frontend/generate.go @@ -7,4 +7,5 @@ package frontend //go:generate mockgen -source quota_validation.go -destination=../util/mocks/$GOPACKAGE/quota_validation.go github.com/Azure/ARO-RP/pkg/frontend QuotaValidator //go:generate mockgen -source providers_validation.go -destination=../util/mocks/$GOPACKAGE/providers_validation.go github.com/Azure/ARO-RP/pkg/frontend ProvidersValidator //go:generate mockgen -source sku_validation.go -destination=../util/mocks/$GOPACKAGE/sku_validation.go github.com/Azure/ARO-RP/pkg/frontend SkuValidator +//go:generate mockgen -source features_validation.go -destination=../util/mocks/$GOPACKAGE/features_validation.go github.com/Azure/ARO-RP/pkg/frontend FeaturesValidator //go:generate mockgen -source adminreplies.go -destination=../util/mocks/$GOPACKAGE/adminreplies.go github.com/Azure/ARO-RP/pkg/frontend StreamResponder diff --git a/pkg/frontend/openshiftcluster_putorpatch.go b/pkg/frontend/openshiftcluster_putorpatch.go index 61e91a7fe17..11fced3f67f 100644 --- a/pkg/frontend/openshiftcluster_putorpatch.go +++ b/pkg/frontend/openshiftcluster_putorpatch.go @@ -450,12 +450,22 @@ func (f *frontend) ValidateNewCluster(ctx context.Context, subscription *api.Sub return err } - err = f.skuValidator.ValidateVMSku(ctx, f.env.Environment(), f.env, subscription.ID, subscription.Subscription.Properties.TenantID, cluster) + fpCred, err := f.env.FPNewClientCertificateCredential(subscription.Subscription.Properties.TenantID, nil) if err != nil { return err } - err = f.quotaValidator.ValidateQuota(ctx, f.env.Environment(), f.env, subscription.ID, subscription.Subscription.Properties.TenantID, cluster) + err = f.skuValidator.ValidateVMSku(ctx, f.env, subscription.ID, fpCred, cluster) + if err != nil { + return err + } + + err = f.featuresValidator.ValidateSubscriptionFeatures(ctx, f.env, subscription.ID, fpCred, cluster) + if err != nil { + return err + } + + err = f.quotaValidator.ValidateQuota(ctx, f.env.Environment(), f.env, subscription.ID, fpCred, cluster) if err != nil { return err } diff --git a/pkg/frontend/openshiftcluster_putorpatch_test.go b/pkg/frontend/openshiftcluster_putorpatch_test.go index 2335969c4c5..b28fc44f2e6 100644 --- a/pkg/frontend/openshiftcluster_putorpatch_test.go +++ b/pkg/frontend/openshiftcluster_putorpatch_test.go @@ -741,7 +741,7 @@ func TestPutorPatchOpenShiftClusterCreate(t *testing.T) { mockQuotaValidator.EXPECT().ValidateQuota(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(tt.quotaValidatorError).AnyTimes() mockSkuValidator := mock_frontend.NewMockSkuValidator(controller) - mockSkuValidator.EXPECT().ValidateVMSku(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(tt.skuValidatorError).AnyTimes() + mockSkuValidator.EXPECT().ValidateVMSku(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(tt.skuValidatorError).AnyTimes() mockProvidersValidator := mock_frontend.NewMockProvidersValidator(controller) mockProvidersValidator.EXPECT().ValidateProviders(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(tt.providersValidatorError).AnyTimes() @@ -1145,7 +1145,7 @@ func TestPutorPatchOpenShiftClusterUpdatePut(t *testing.T) { mockQuotaValidator.EXPECT().ValidateQuota(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(tt.quotaValidatorError).AnyTimes() mockSkuValidator := mock_frontend.NewMockSkuValidator(controller) - mockSkuValidator.EXPECT().ValidateVMSku(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(tt.skuValidatorError).AnyTimes() + mockSkuValidator.EXPECT().ValidateVMSku(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(tt.skuValidatorError).AnyTimes() mockProvidersValidator := mock_frontend.NewMockProvidersValidator(controller) mockProvidersValidator.EXPECT().ValidateProviders(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(tt.providersValidatorError).AnyTimes() @@ -1644,7 +1644,7 @@ func TestPutorPatchOpenShiftClusterUpdatePatch(t *testing.T) { mockQuotaValidator.EXPECT().ValidateQuota(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(tt.quotaValidatorError).AnyTimes() mockSkuValidator := mock_frontend.NewMockSkuValidator(controller) - mockSkuValidator.EXPECT().ValidateVMSku(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(tt.skuValidatorError).AnyTimes() + mockSkuValidator.EXPECT().ValidateVMSku(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(tt.skuValidatorError).AnyTimes() mockProvidersValidator := mock_frontend.NewMockProvidersValidator(controller) mockProvidersValidator.EXPECT().ValidateProviders(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(tt.providersValidatorError).AnyTimes() diff --git a/pkg/frontend/quota_validation.go b/pkg/frontend/quota_validation.go index aa9fb787680..131c93ae686 100644 --- a/pkg/frontend/quota_validation.go +++ b/pkg/frontend/quota_validation.go @@ -8,6 +8,10 @@ import ( "fmt" "net/http" + "github.com/jongio/azidext/go/azidext" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/ARO-RP/pkg/api" "github.com/Azure/ARO-RP/pkg/api/validate" "github.com/Azure/ARO-RP/pkg/env" @@ -17,7 +21,7 @@ import ( ) type QuotaValidator interface { - ValidateQuota(ctx context.Context, azEnv *azureclient.AROEnvironment, environment env.Interface, subscriptionID, tenantID string, oc *api.OpenShiftCluster) error + ValidateQuota(ctx context.Context, azEnv *azureclient.AROEnvironment, environment env.Interface, subscriptionID string, fpCred azcore.TokenCredential, oc *api.OpenShiftCluster) error } type quotaValidator struct{} @@ -39,20 +43,13 @@ func addRequiredResources(requiredResources map[string]int, vmSize api.VMSize, c // ValidateQuota checks usage quotas vs. resources required by cluster before cluster // creation // It is a method on struct so we can make use of interfaces. -func (q quotaValidator) ValidateQuota(ctx context.Context, azEnv *azureclient.AROEnvironment, environment env.Interface, subscriptionID, tenantID string, oc *api.OpenShiftCluster) error { - fpAuthorizer, err := environment.FPAuthorizer(tenantID, nil, environment.Environment().ResourceManagerScope) - if err != nil { - return err - } +func (q quotaValidator) ValidateQuota(ctx context.Context, azEnv *azureclient.AROEnvironment, environment env.Interface, subscriptionID string, fpCred azcore.TokenCredential, oc *api.OpenShiftCluster) error { + fpAuthorizer := azidext.NewTokenCredentialAdapter(fpCred, []string{environment.Environment().ResourceManagerScope}) - credential, err := environment.FPNewClientCertificateCredential(tenantID, []string{}) - if err != nil { - return err - } options := environment.Environment().ArmClientOptions() spComputeUsage := compute.NewUsageClient(azEnv, subscriptionID, fpAuthorizer) - spNetworkUsage, err := armnetwork.NewUsagesClient(subscriptionID, credential, options) + spNetworkUsage, err := armnetwork.NewUsagesClient(subscriptionID, fpCred, options) if err != nil { return err } diff --git a/pkg/frontend/shared_test.go b/pkg/frontend/shared_test.go index a20c305c27d..18f8a791d5c 100644 --- a/pkg/frontend/shared_test.go +++ b/pkg/frontend/shared_test.go @@ -21,6 +21,7 @@ import ( "github.com/sirupsen/logrus" "go.uber.org/mock/gomock" + "github.com/Azure/azure-sdk-for-go/sdk/azidentity" "github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azsecrets" "github.com/Azure/ARO-RP/pkg/api" @@ -132,6 +133,7 @@ func newTestInfraWithFeatures(t *testing.T, features map[env.Feature]bool) *test _env.EXPECT().Domain().AnyTimes().Return("aro.example") _env.EXPECT().Listen().AnyTimes().Return(l, nil) _env.EXPECT().NewMSITokenCredential().AnyTimes().Return(nil, fmt.Errorf("MSI not available in test")) + _env.EXPECT().FPNewClientCertificateCredential(gomock.Any(), gomock.Any()).AnyTimes().Return(&azidentity.ClientCertificateCredential{}, nil) for f, val := range features { _env.EXPECT().FeatureIsSet(f).AnyTimes().Return(val) } diff --git a/pkg/frontend/sku_validation.go b/pkg/frontend/sku_validation.go index 47bf319e2b0..300efc9ff50 100644 --- a/pkg/frontend/sku_validation.go +++ b/pkg/frontend/sku_validation.go @@ -8,28 +8,23 @@ import ( "fmt" "net/http" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" sdkcompute "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v7" "github.com/Azure/ARO-RP/pkg/api" "github.com/Azure/ARO-RP/pkg/env" - "github.com/Azure/ARO-RP/pkg/util/azureclient" "github.com/Azure/ARO-RP/pkg/util/azureclient/azuresdk/armcompute" "github.com/Azure/ARO-RP/pkg/util/computeskus" ) type SkuValidator interface { - ValidateVMSku(ctx context.Context, azEnv *azureclient.AROEnvironment, environment env.Interface, subscriptionID, tenantID string, oc *api.OpenShiftCluster) error + ValidateVMSku(ctx context.Context, environment env.Interface, subscriptionID string, fpCred azcore.TokenCredential, oc *api.OpenShiftCluster) error } type skuValidator struct{} -func (s skuValidator) ValidateVMSku(ctx context.Context, azEnv *azureclient.AROEnvironment, environment env.Interface, subscriptionID, tenantID string, oc *api.OpenShiftCluster) error { - fpCredClusterTenant, err := environment.FPNewClientCertificateCredential(tenantID, nil) - if err != nil { - return err - } - - armResourceSKUsClient, err := armcompute.NewResourceSKUsClient(subscriptionID, fpCredClusterTenant, environment.Environment().ArmClientOptions()) +func (s skuValidator) ValidateVMSku(ctx context.Context, environment env.Interface, subscriptionID string, fpCred azcore.TokenCredential, oc *api.OpenShiftCluster) error { + armResourceSKUsClient, err := armcompute.NewResourceSKUsClient(subscriptionID, fpCred, environment.Environment().ArmClientOptions()) if err != nil { return err } diff --git a/pkg/util/azureclient/azuresdk/armfeatures/client.go b/pkg/util/azureclient/azuresdk/armfeatures/client.go new file mode 100644 index 00000000000..09d61bdb31c --- /dev/null +++ b/pkg/util/azureclient/azuresdk/armfeatures/client.go @@ -0,0 +1,47 @@ +package armfeatures + +// Copyright (c) Microsoft Corporation. +// Licensed under the Apache License 2.0. + +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/resourcemanager/resources/armfeatures" + + "github.com/Azure/ARO-RP/pkg/util/azureclient" +) + +type FeaturesClient interface { + Get(ctx context.Context, resourceProviderNamespace string, featureName string, options *armfeatures.ClientGetOptions) (armfeatures.ClientGetResponse, error) +} + +type featuresClient struct { + *armfeatures.Client +} + +var _ FeaturesClient = &featuresClient{} + +// NewDefaultFeaturesClient creates a new FeaturesClient with default options +func NewDefaultFeaturesClient(environment *azureclient.AROEnvironment, subscriptionID string, credential azcore.TokenCredential) (FeaturesClient, error) { + options := &arm.ClientOptions{ + ClientOptions: azcore.ClientOptions{ + Cloud: environment.Cloud, + }, + } + + return NewFeaturesClient(subscriptionID, credential, options) +} + +// NewFeaturesClient creates a new FeaturesClient +func NewFeaturesClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (FeaturesClient, error) { + client, err := armfeatures.NewClient(subscriptionID, credential, options) + if err != nil { + return nil, err + } + + return &featuresClient{ + Client: client, + }, 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..7df46930cb7 --- /dev/null +++ b/pkg/util/azureclient/azuresdk/armfeatures/generate.go @@ -0,0 +1,7 @@ +package armfeatures + +// Copyright (c) Microsoft Corporation. +// Licensed under the Apache License 2.0. + +//go:generate rm -rf ../../../../util/mocks/$GOPACKAGE +//go:generate mockgen -destination=../../../../util/mocks/azureclient/azuresdk/$GOPACKAGE/$GOPACKAGE.go github.com/Azure/ARO-RP/pkg/util/azureclient/azuresdk/$GOPACKAGE FeaturesClient 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..b9147053b4f --- /dev/null +++ b/pkg/util/mocks/azureclient/azuresdk/armfeatures/armfeatures.go @@ -0,0 +1,58 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/Azure/ARO-RP/pkg/util/azureclient/azuresdk/armfeatures (interfaces: FeaturesClient) +// +// Generated by this command: +// +// mockgen -destination=../../../../util/mocks/azureclient/azuresdk/armfeatures/armfeatures.go github.com/Azure/ARO-RP/pkg/util/azureclient/azuresdk/armfeatures FeaturesClient +// + +// Package mock_armfeatures is a generated GoMock package. +package mock_armfeatures + +import ( + context "context" + reflect "reflect" + + gomock "go.uber.org/mock/gomock" + + armfeatures "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures" +) + +// MockFeaturesClient is a mock of FeaturesClient interface. +type MockFeaturesClient struct { + ctrl *gomock.Controller + recorder *MockFeaturesClientMockRecorder + isgomock struct{} +} + +// MockFeaturesClientMockRecorder is the mock recorder for MockFeaturesClient. +type MockFeaturesClientMockRecorder struct { + mock *MockFeaturesClient +} + +// NewMockFeaturesClient creates a new mock instance. +func NewMockFeaturesClient(ctrl *gomock.Controller) *MockFeaturesClient { + mock := &MockFeaturesClient{ctrl: ctrl} + mock.recorder = &MockFeaturesClientMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockFeaturesClient) EXPECT() *MockFeaturesClientMockRecorder { + return m.recorder +} + +// Get mocks base method. +func (m *MockFeaturesClient) Get(ctx context.Context, resourceProviderNamespace, featureName string, options *armfeatures.ClientGetOptions) (armfeatures.ClientGetResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Get", ctx, resourceProviderNamespace, featureName, options) + ret0, _ := ret[0].(armfeatures.ClientGetResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Get indicates an expected call of Get. +func (mr *MockFeaturesClientMockRecorder) Get(ctx, resourceProviderNamespace, featureName, options any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockFeaturesClient)(nil).Get), ctx, resourceProviderNamespace, featureName, options) +} diff --git a/pkg/util/mocks/frontend/features_validation.go b/pkg/util/mocks/frontend/features_validation.go new file mode 100644 index 00000000000..3620a4b74a0 --- /dev/null +++ b/pkg/util/mocks/frontend/features_validation.go @@ -0,0 +1,60 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: features_validation.go +// +// Generated by this command: +// +// mockgen -source features_validation.go -destination=../util/mocks/frontend/features_validation.go github.com/Azure/ARO-RP/pkg/frontend FeaturesValidator +// + +// Package mock_frontend is a generated GoMock package. +package mock_frontend + +import ( + context "context" + reflect "reflect" + + gomock "go.uber.org/mock/gomock" + + azcore "github.com/Azure/azure-sdk-for-go/sdk/azcore" + + api "github.com/Azure/ARO-RP/pkg/api" + env "github.com/Azure/ARO-RP/pkg/env" +) + +// MockFeaturesValidator is a mock of FeaturesValidator interface. +type MockFeaturesValidator struct { + ctrl *gomock.Controller + recorder *MockFeaturesValidatorMockRecorder + isgomock struct{} +} + +// MockFeaturesValidatorMockRecorder is the mock recorder for MockFeaturesValidator. +type MockFeaturesValidatorMockRecorder struct { + mock *MockFeaturesValidator +} + +// NewMockFeaturesValidator creates a new mock instance. +func NewMockFeaturesValidator(ctrl *gomock.Controller) *MockFeaturesValidator { + mock := &MockFeaturesValidator{ctrl: ctrl} + mock.recorder = &MockFeaturesValidatorMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockFeaturesValidator) EXPECT() *MockFeaturesValidatorMockRecorder { + return m.recorder +} + +// ValidateSubscriptionFeatures mocks base method. +func (m *MockFeaturesValidator) ValidateSubscriptionFeatures(ctx context.Context, environment env.Interface, subscriptionID string, fpCred azcore.TokenCredential, oc *api.OpenShiftCluster) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ValidateSubscriptionFeatures", ctx, environment, subscriptionID, fpCred, oc) + ret0, _ := ret[0].(error) + return ret0 +} + +// ValidateSubscriptionFeatures indicates an expected call of ValidateSubscriptionFeatures. +func (mr *MockFeaturesValidatorMockRecorder) ValidateSubscriptionFeatures(ctx, environment, subscriptionID, fpCred, oc any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateSubscriptionFeatures", reflect.TypeOf((*MockFeaturesValidator)(nil).ValidateSubscriptionFeatures), ctx, environment, subscriptionID, fpCred, oc) +} diff --git a/pkg/util/mocks/frontend/quota_validation.go b/pkg/util/mocks/frontend/quota_validation.go index 6e199d53b69..f86a0e55843 100644 --- a/pkg/util/mocks/frontend/quota_validation.go +++ b/pkg/util/mocks/frontend/quota_validation.go @@ -15,6 +15,8 @@ import ( gomock "go.uber.org/mock/gomock" + azcore "github.com/Azure/azure-sdk-for-go/sdk/azcore" + api "github.com/Azure/ARO-RP/pkg/api" env "github.com/Azure/ARO-RP/pkg/env" azureclient "github.com/Azure/ARO-RP/pkg/util/azureclient" @@ -45,15 +47,15 @@ func (m *MockQuotaValidator) EXPECT() *MockQuotaValidatorMockRecorder { } // ValidateQuota mocks base method. -func (m *MockQuotaValidator) ValidateQuota(ctx context.Context, azEnv *azureclient.AROEnvironment, environment env.Interface, subscriptionID, tenantID string, oc *api.OpenShiftCluster) error { +func (m *MockQuotaValidator) ValidateQuota(ctx context.Context, azEnv *azureclient.AROEnvironment, environment env.Interface, subscriptionID string, fpCred azcore.TokenCredential, oc *api.OpenShiftCluster) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ValidateQuota", ctx, azEnv, environment, subscriptionID, tenantID, oc) + ret := m.ctrl.Call(m, "ValidateQuota", ctx, azEnv, environment, subscriptionID, fpCred, oc) ret0, _ := ret[0].(error) return ret0 } // ValidateQuota indicates an expected call of ValidateQuota. -func (mr *MockQuotaValidatorMockRecorder) ValidateQuota(ctx, azEnv, environment, subscriptionID, tenantID, oc any) *gomock.Call { +func (mr *MockQuotaValidatorMockRecorder) ValidateQuota(ctx, azEnv, environment, subscriptionID, fpCred, oc any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateQuota", reflect.TypeOf((*MockQuotaValidator)(nil).ValidateQuota), ctx, azEnv, environment, subscriptionID, tenantID, oc) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateQuota", reflect.TypeOf((*MockQuotaValidator)(nil).ValidateQuota), ctx, azEnv, environment, subscriptionID, fpCred, oc) } diff --git a/pkg/util/mocks/frontend/sku_validation.go b/pkg/util/mocks/frontend/sku_validation.go index 32dc598fab4..a4e303f0f6c 100644 --- a/pkg/util/mocks/frontend/sku_validation.go +++ b/pkg/util/mocks/frontend/sku_validation.go @@ -15,9 +15,10 @@ import ( gomock "go.uber.org/mock/gomock" + azcore "github.com/Azure/azure-sdk-for-go/sdk/azcore" + api "github.com/Azure/ARO-RP/pkg/api" env "github.com/Azure/ARO-RP/pkg/env" - azureclient "github.com/Azure/ARO-RP/pkg/util/azureclient" ) // MockSkuValidator is a mock of SkuValidator interface. @@ -45,15 +46,15 @@ func (m *MockSkuValidator) EXPECT() *MockSkuValidatorMockRecorder { } // ValidateVMSku mocks base method. -func (m *MockSkuValidator) ValidateVMSku(ctx context.Context, azEnv *azureclient.AROEnvironment, environment env.Interface, subscriptionID, tenantID string, oc *api.OpenShiftCluster) error { +func (m *MockSkuValidator) ValidateVMSku(ctx context.Context, environment env.Interface, subscriptionID string, fpCred azcore.TokenCredential, oc *api.OpenShiftCluster) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ValidateVMSku", ctx, azEnv, environment, subscriptionID, tenantID, oc) + ret := m.ctrl.Call(m, "ValidateVMSku", ctx, environment, subscriptionID, fpCred, oc) ret0, _ := ret[0].(error) return ret0 } // ValidateVMSku indicates an expected call of ValidateVMSku. -func (mr *MockSkuValidatorMockRecorder) ValidateVMSku(ctx, azEnv, environment, subscriptionID, tenantID, oc any) *gomock.Call { +func (mr *MockSkuValidatorMockRecorder) ValidateVMSku(ctx, environment, subscriptionID, fpCred, oc any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateVMSku", reflect.TypeOf((*MockSkuValidator)(nil).ValidateVMSku), ctx, azEnv, environment, subscriptionID, tenantID, oc) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateVMSku", reflect.TypeOf((*MockSkuValidator)(nil).ValidateVMSku), ctx, environment, subscriptionID, fpCred, oc) }