From 3800f3192b87d3099339a5dfdc9bc54146b49136 Mon Sep 17 00:00:00 2001 From: Shahram Kalantari Date: Sun, 29 Sep 2024 19:22:49 +1000 Subject: [PATCH] chore: lint Signed-off-by: Shahram Kalantari --- .../authprovider/azure/azureworkloadidentity.go | 12 ++++++------ .../azure/azureworkloadidentity_test.go | 16 ++++++++-------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/pkg/common/oras/authprovider/azure/azureworkloadidentity.go b/pkg/common/oras/authprovider/azure/azureworkloadidentity.go index 183b7f87ac..241696bcfe 100644 --- a/pkg/common/oras/authprovider/azure/azureworkloadidentity.go +++ b/pkg/common/oras/authprovider/azure/azureworkloadidentity.go @@ -32,7 +32,7 @@ import ( ) type AzureWIProviderFactory struct{} //nolint:revive // ignore linter to have unique type name -type azureWIAuthProvider struct { +type WIAuthProvider struct { aadToken confidential.AuthResult tenantID string clientID string @@ -54,8 +54,8 @@ type authClient interface { ExchangeAADAccessTokenForACRRefreshToken(ctx context.Context, grantType, service string, options *azcontainerregistry.AuthenticationClientExchangeAADAccessTokenForACRRefreshTokenOptions) (azcontainerregistry.AuthenticationClientExchangeAADAccessTokenForACRRefreshTokenResponse, error) } -func NewAzureWIAuthProvider() *azureWIAuthProvider { - return &azureWIAuthProvider{ +func NewAzureWIAuthProvider() *WIAuthProvider { + return &WIAuthProvider{ authClientFactory: func(serverURL string, options *azcontainerregistry.AuthenticationClientOptions) (authClient, error) { client, err := azcontainerregistry.NewAuthenticationClient(serverURL, options) if err != nil { @@ -114,7 +114,7 @@ func (s *AzureWIProviderFactory) Create(authProviderConfig provider.AuthProvider return nil, re.ErrorCodeAuthDenied.NewError(re.AuthProvider, "", re.AzureWorkloadIdentityLink, err, "", re.HideStackTrace) } - return &azureWIAuthProvider{ + return &WIAuthProvider{ aadToken: token, tenantID: tenant, clientID: clientID, @@ -122,7 +122,7 @@ func (s *AzureWIProviderFactory) Create(authProviderConfig provider.AuthProvider } // Enabled checks for non empty tenant ID and AAD access token -func (d *azureWIAuthProvider) Enabled(_ context.Context) bool { +func (d *WIAuthProvider) Enabled(_ context.Context) bool { if d.tenantID == "" || d.clientID == "" { return false } @@ -134,7 +134,7 @@ func (d *azureWIAuthProvider) Enabled(_ context.Context) bool { return true } -func (d *azureWIAuthProvider) Provide(ctx context.Context, artifact string) (provider.AuthConfig, error) { +func (d *WIAuthProvider) Provide(ctx context.Context, artifact string) (provider.AuthConfig, error) { if !d.Enabled(ctx) { return provider.AuthConfig{}, re.ErrorCodeConfigInvalid.WithComponentType(re.AuthProvider).WithDetail("azure workload identity auth provider is not properly enabled") } diff --git a/pkg/common/oras/authprovider/azure/azureworkloadidentity_test.go b/pkg/common/oras/authprovider/azure/azureworkloadidentity_test.go index a10f374d31..b4a9a1f7cb 100644 --- a/pkg/common/oras/authprovider/azure/azureworkloadidentity_test.go +++ b/pkg/common/oras/authprovider/azure/azureworkloadidentity_test.go @@ -32,7 +32,7 @@ import ( // Verifies that Enabled checks if tenantID is empty or AAD token is empty func TestAzureWIEnabled_ExpectedResults(t *testing.T) { - azAuthProvider := azureWIAuthProvider{ + azAuthProvider := WIAuthProvider{ tenantID: "test_tenant", clientID: "test_client", aadToken: confidential.AuthResult{ @@ -152,26 +152,26 @@ func TestProvide_Success(t *testing.T) { ACRRefreshToken: azcontainerregistry.ACRRefreshToken{RefreshToken: &expectedRefreshToken}, }, nil) - provider := &azureWIAuthProvider{ + provider := &WIAuthProvider{ aadToken: confidential.AuthResult{ AccessToken: "mockToken", ExpiresOn: time.Now().Add(time.Hour), }, tenantID: "mockTenantID", clientID: "mockClientID", - authClientFactory: func(serverURL string, options *azcontainerregistry.AuthenticationClientOptions) (authClient, error) { + authClientFactory: func(_ string, _ *azcontainerregistry.AuthenticationClientOptions) (authClient, error) { return mockClient, nil }, - getRegistryHost: func(artifact string) (string, error) { + getRegistryHost: func(_ string) (string, error) { return "myregistry.azurecr.io", nil }, - getAADAccessToken: func(ctx context.Context, tenantID, clientID, resource string) (confidential.AuthResult, error) { + getAADAccessToken: func(_ context.Context, _, _, _ string) (confidential.AuthResult, error) { return confidential.AuthResult{ AccessToken: "mockToken", ExpiresOn: time.Now().Add(time.Hour), }, nil }, - reportMetrics: func(ctx context.Context, duration int64, artifactHostName string) {}, + reportMetrics: func(_ context.Context, _ int64, _ string) {}, } authConfig, err := provider.Provide(context.Background(), "artifact") @@ -182,8 +182,8 @@ func TestProvide_Success(t *testing.T) { } func TestProvide_Failure_InvalidHostName(t *testing.T) { - provider := &azureWIAuthProvider{ - getRegistryHost: func(artifact string) (string, error) { + provider := &WIAuthProvider{ + getRegistryHost: func(_ string) (string, error) { return "", errors.New("invalid hostname") }, }