Skip to content

Commit 3319a4d

Browse files
author
b-lnimmala
committed
Move FeatureClient to azureclient wrapper and rename files
1 parent 72a7022 commit 3319a4d

10 files changed

Lines changed: 123 additions & 62 deletions

File tree

pkg/frontend/encryptionathost_validation.go renamed to pkg/frontend/features_validation.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,12 @@ import (
88
"fmt"
99
"net/http"
1010

11-
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures"
12-
1311
"github.com/Azure/ARO-RP/pkg/api"
1412
"github.com/Azure/ARO-RP/pkg/env"
1513
"github.com/Azure/ARO-RP/pkg/util/azureclient"
14+
"github.com/Azure/ARO-RP/pkg/util/azureclient/azuresdk/armfeatures"
1615
)
1716

18-
type FeaturesClient interface {
19-
Get(ctx context.Context, resourceProviderNamespace string, featureName string, options *armfeatures.ClientGetOptions) (armfeatures.ClientGetResponse, error)
20-
}
21-
2217
type FeaturesValidator interface {
2318
ValidateSubscriptionFeatures(ctx context.Context, azEnv *azureclient.AROEnvironment, environment env.Interface, subscriptionID, tenantID string, oc *api.OpenShiftCluster) error
2419
}
@@ -39,7 +34,7 @@ func (f featuresValidator) ValidateSubscriptionFeatures(ctx context.Context, azE
3934
return err
4035
}
4136

42-
featuresClient, err := armfeatures.NewClient(subscriptionID, fpCred, azEnv.ArmClientOptions())
37+
featuresClient, err := armfeatures.NewFeaturesClient(subscriptionID, fpCred, azEnv.ArmClientOptions())
4338
if err != nil {
4439
return err
4540
}
@@ -51,7 +46,7 @@ func (f featuresValidator) ValidateSubscriptionFeatures(ctx context.Context, azE
5146

5247
func validateEncryptionAtHostFeature(
5348
ctx context.Context,
54-
featuresClient FeaturesClient,
49+
featuresClient armfeatures.FeaturesClient,
5550
subscriptionID, fieldPath string,
5651
) error {
5752
resp, err := featuresClient.Get(ctx, "Microsoft.Compute", "EncryptionAtHost", nil)

pkg/frontend/encryptionathost_validation_test.go renamed to pkg/frontend/features_validation_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures"
1414

15-
mock_frontend "github.com/Azure/ARO-RP/pkg/util/mocks/frontend"
15+
mock_armfeatures "github.com/Azure/ARO-RP/pkg/util/mocks/azureclient/azuresdk/armfeatures"
1616
"github.com/Azure/ARO-RP/pkg/util/pointerutils"
1717
)
1818

@@ -63,7 +63,7 @@ func TestValidateEncryptionAtHostFeature(t *testing.T) {
6363
controller := gomock.NewController(t)
6464
defer controller.Finish()
6565

66-
featuresClient := mock_frontend.NewMockFeaturesClient(controller)
66+
featuresClient := mock_armfeatures.NewMockFeaturesClient(controller)
6767

6868
var mockResponse armfeatures.ClientGetResponse
6969
if tt.mockPropertiesNil {

pkg/frontend/generate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ package frontend
77
//go:generate mockgen -source quota_validation.go -destination=../util/mocks/$GOPACKAGE/quota_validation.go github.com/Azure/ARO-RP/pkg/frontend QuotaValidator
88
//go:generate mockgen -source providers_validation.go -destination=../util/mocks/$GOPACKAGE/providers_validation.go github.com/Azure/ARO-RP/pkg/frontend ProvidersValidator
99
//go:generate mockgen -source sku_validation.go -destination=../util/mocks/$GOPACKAGE/sku_validation.go github.com/Azure/ARO-RP/pkg/frontend SkuValidator
10-
//go:generate mockgen -source encryptionathost_validation.go -destination=../util/mocks/$GOPACKAGE/encryptionathost_validation.go github.com/Azure/ARO-RP/pkg/frontend FeaturesClient,FeaturesValidator
10+
//go:generate mockgen -source features_validation.go -destination=../util/mocks/$GOPACKAGE/features_validation.go github.com/Azure/ARO-RP/pkg/frontend FeaturesValidator
1111
//go:generate mockgen -source adminreplies.go -destination=../util/mocks/$GOPACKAGE/adminreplies.go github.com/Azure/ARO-RP/pkg/frontend StreamResponder
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package armfeatures
2+
3+
// Copyright (c) Microsoft Corporation.
4+
// Licensed under the Apache License 2.0.
5+
6+
import (
7+
"context"
8+
9+
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
10+
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
11+
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures"
12+
13+
"github.com/Azure/ARO-RP/pkg/util/azureclient"
14+
)
15+
16+
type FeaturesClient interface {
17+
Get(ctx context.Context, resourceProviderNamespace string, featureName string, options *armfeatures.ClientGetOptions) (armfeatures.ClientGetResponse, error)
18+
}
19+
20+
type featuresClient struct {
21+
*armfeatures.Client
22+
}
23+
24+
var _ FeaturesClient = &featuresClient{}
25+
26+
// NewDefaultFeaturesClient creates a new FeaturesClient with default options
27+
func NewDefaultFeaturesClient(environment *azureclient.AROEnvironment, subscriptionID string, credential azcore.TokenCredential) (FeaturesClient, error) {
28+
options := &arm.ClientOptions{
29+
ClientOptions: azcore.ClientOptions{
30+
Cloud: environment.Cloud,
31+
},
32+
}
33+
34+
return NewFeaturesClient(subscriptionID, credential, options)
35+
}
36+
37+
// NewFeaturesClient creates a new FeaturesClient
38+
func NewFeaturesClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (FeaturesClient, error) {
39+
client, err := armfeatures.NewClient(subscriptionID, credential, options)
40+
if err != nil {
41+
return nil, err
42+
}
43+
44+
return &featuresClient{
45+
Client: client,
46+
}, nil
47+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package armfeatures
2+
3+
// Copyright (c) Microsoft Corporation.
4+
// Licensed under the Apache License 2.0.
5+
6+
//go:generate rm -rf ../../../../util/mocks/$GOPACKAGE
7+
//go:generate mockgen -destination=../../../../util/mocks/azureclient/azuresdk/$GOPACKAGE/$GOPACKAGE.go github.com/Azure/ARO-RP/pkg/util/azureclient/azuresdk/$GOPACKAGE FeaturesClient

pkg/util/mocks/azureclient/azuresdk/armfeatures/armfeatures.go

Lines changed: 57 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/util/mocks/frontend/encryptionathost_validation.go renamed to pkg/util/mocks/frontend/features_validation.go

Lines changed: 3 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/util/mocks/frontend/providers_validation.go

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/util/mocks/frontend/quota_validation.go

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/util/mocks/frontend/sku_validation.go

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)