Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
Signed-off-by: Shahram Kalantari <[email protected]>
  • Loading branch information
shahramk64 committed Sep 29, 2024
1 parent 045b901 commit 3800f31
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions pkg/common/oras/authprovider/azure/azureworkloadidentity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -114,15 +114,15 @@ func (s *AzureWIProviderFactory) Create(authProviderConfig provider.AuthProvider
return nil, re.ErrorCodeAuthDenied.NewError(re.AuthProvider, "", re.AzureWorkloadIdentityLink, err, "", re.HideStackTrace)
}

return &azureWIAuthProvider{
return &WIAuthProvider{

Check warning on line 117 in pkg/common/oras/authprovider/azure/azureworkloadidentity.go

View check run for this annotation

Codecov / codecov/patch

pkg/common/oras/authprovider/azure/azureworkloadidentity.go#L117

Added line #L117 was not covered by tests
aadToken: token,
tenantID: tenant,
clientID: clientID,
}, nil
}

// 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
}
Expand All @@ -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")
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/common/oras/authprovider/azure/azureworkloadidentity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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")
Expand All @@ -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")
},
}
Expand Down

0 comments on commit 3800f31

Please sign in to comment.