Skip to content

Commit

Permalink
chore: address comments
Browse files Browse the repository at this point in the history
Signed-off-by: Shahram Kalantari <shahramk@gmail.com>
  • Loading branch information
shahramk64 committed Oct 21, 2024
1 parent d50d306 commit ac8e29e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 31 deletions.
10 changes: 5 additions & 5 deletions pkg/common/oras/authprovider/azure/azureidentity.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ type ManagedIdentityTokenGetter interface {
GetManagedIdentityToken(ctx context.Context, clientID string) (azcore.AccessToken, error)
}

// DefaultManagedIdentityTokenGetterImpl is the default implementation of getManagedIdentityToken.
type DefaultManagedIdentityTokenGetterImpl struct{}
// defaultManagedIdentityTokenGetterImpl is the default implementation of getManagedIdentityToken.
type defaultManagedIdentityTokenGetterImpl struct{}

func (g *DefaultManagedIdentityTokenGetterImpl) GetManagedIdentityToken(ctx context.Context, clientID string) (azcore.AccessToken, error) {
func (g *defaultManagedIdentityTokenGetterImpl) GetManagedIdentityToken(ctx context.Context, clientID string) (azcore.AccessToken, error) {
return getManagedIdentityToken(ctx, clientID, azidentity.NewManagedIdentityCredential)
}

Expand Down Expand Up @@ -119,8 +119,8 @@ func (s *azureManagedIdentityProviderFactory) Create(authProviderConfig provider
identityToken: token,
clientID: client,
tenantID: tenant,
authClientFactory: &DefaultAuthClientFactoryImpl{}, // Concrete implementation
getManagedIdentityToken: &DefaultManagedIdentityTokenGetterImpl{}, // Concrete implementation
authClientFactory: &defaultAuthClientFactoryImpl{}, // Concrete implementation
getManagedIdentityToken: &defaultManagedIdentityTokenGetterImpl{}, // Concrete implementation
}, nil
}

Expand Down
30 changes: 15 additions & 15 deletions pkg/common/oras/authprovider/azure/azureworkloadidentity.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ type AADAccessTokenGetter interface {
GetAADAccessToken(ctx context.Context, tenantID, clientID, resource string) (confidential.AuthResult, error)
}

// DefaultAADAccessTokenGetterImpl is the default implementation of AADAccessTokenGetter.
type DefaultAADAccessTokenGetterImpl struct{}
// defaultAADAccessTokenGetterImpl is the default implementation of AADAccessTokenGetter.
type defaultAADAccessTokenGetterImpl struct{}

func (g *DefaultAADAccessTokenGetterImpl) GetAADAccessToken(ctx context.Context, tenantID, clientID, resource string) (confidential.AuthResult, error) {
return DefaultGetAADAccessToken(ctx, tenantID, clientID, resource)
func (g *defaultAADAccessTokenGetterImpl) GetAADAccessToken(ctx context.Context, tenantID, clientID, resource string) (confidential.AuthResult, error) {
return defaultGetAADAccessToken(ctx, tenantID, clientID, resource)
}

func DefaultGetAADAccessToken(ctx context.Context, tenantID, clientID, resource string) (confidential.AuthResult, error) {
func defaultGetAADAccessToken(ctx context.Context, tenantID, clientID, resource string) (confidential.AuthResult, error) {
return azureauth.GetAADAccessToken(ctx, tenantID, clientID, resource)
}

Expand All @@ -51,14 +51,14 @@ type MetricsReporter interface {
ReportMetrics(ctx context.Context, duration int64, artifactHostName string)
}

// DefaultMetricsReporterImpl is the default implementation of MetricsReporter.
type DefaultMetricsReporterImpl struct{}
// defaultMetricsReporterImpl is the default implementation of MetricsReporter.
type defaultMetricsReporterImpl struct{}

func (r *DefaultMetricsReporterImpl) ReportMetrics(ctx context.Context, duration int64, artifactHostName string) {
DefaultReportMetrics(ctx, duration, artifactHostName)
func (r *defaultMetricsReporterImpl) ReportMetrics(ctx context.Context, duration int64, artifactHostName string) {
defaultReportMetrics(ctx, duration, artifactHostName)
}

func DefaultReportMetrics(ctx context.Context, duration int64, artifactHostName string) {
func defaultReportMetrics(ctx context.Context, duration int64, artifactHostName string) {
logger.GetLogger(ctx, logOpt).Infof("Metrics Report: Duration=%dms, Host=%s", duration, artifactHostName)
}

Expand Down Expand Up @@ -114,7 +114,7 @@ func (s *AzureWIProviderFactory) Create(authProviderConfig provider.AuthProvider
}

// retrieve an AAD Access token
token, err := DefaultGetAADAccessToken(context.Background(), tenant, clientID, AADResource)
token, err := defaultGetAADAccessToken(context.Background(), tenant, clientID, AADResource)
if err != nil {
return nil, re.ErrorCodeAuthDenied.NewError(re.AuthProvider, "", re.AzureWorkloadIdentityLink, err, "", re.HideStackTrace)
}
Expand All @@ -123,10 +123,10 @@ func (s *AzureWIProviderFactory) Create(authProviderConfig provider.AuthProvider
aadToken: token,
tenantID: tenant,
clientID: clientID,
authClientFactory: &DefaultAuthClientFactoryImpl{}, // Concrete implementation
getRegistryHost: &DefaultRegistryHostGetterImpl{}, // Concrete implementation
getAADAccessToken: &DefaultAADAccessTokenGetterImpl{}, // Concrete implementation
reportMetrics: &DefaultMetricsReporterImpl{},
authClientFactory: &defaultAuthClientFactoryImpl{}, // Concrete implementation
getRegistryHost: &defaultRegistryHostGetterImpl{}, // Concrete implementation
getAADAccessToken: &defaultAADAccessTokenGetterImpl{}, // Concrete implementation
reportMetrics: &defaultMetricsReporterImpl{},
}, nil
}

Expand Down
16 changes: 8 additions & 8 deletions pkg/common/oras/authprovider/azure/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ type AuthClientFactory interface {
CreateAuthClient(serverURL string, options *azcontainerregistry.AuthenticationClientOptions) (AuthClient, error)
}

// DefaultAuthClientFactoryImpl is the default implementation of AuthClientFactory.
type DefaultAuthClientFactoryImpl struct{}
// defaultAuthClientFactoryImpl is the default implementation of AuthClientFactory.
type defaultAuthClientFactoryImpl struct{}

func (f *DefaultAuthClientFactoryImpl) CreateAuthClient(serverURL string, options *azcontainerregistry.AuthenticationClientOptions) (AuthClient, error) {
return DefaultAuthClientFactory(serverURL, options)
func (f *defaultAuthClientFactoryImpl) CreateAuthClient(serverURL string, options *azcontainerregistry.AuthenticationClientOptions) (AuthClient, error) {
return defaultAuthClientFactory(serverURL, options)
}

func DefaultAuthClientFactory(serverURL string, options *azcontainerregistry.AuthenticationClientOptions) (AuthClient, error) {
func defaultAuthClientFactory(serverURL string, options *azcontainerregistry.AuthenticationClientOptions) (AuthClient, error) {
client, err := azcontainerregistry.NewAuthenticationClient(serverURL, options)
if err != nil {
return nil, err
Expand Down Expand Up @@ -66,10 +66,10 @@ type RegistryHostGetter interface {
GetRegistryHost(artifact string) (string, error)
}

// DefaultRegistryHostGetterImpl is the default implementation of RegistryHostGetter.
type DefaultRegistryHostGetterImpl struct{}
// defaultRegistryHostGetterImpl is the default implementation of RegistryHostGetter.
type defaultRegistryHostGetterImpl struct{}

func (g *DefaultRegistryHostGetterImpl) GetRegistryHost(artifact string) (string, error) {
func (g *defaultRegistryHostGetterImpl) GetRegistryHost(artifact string) (string, error) {
// Implement the logic to get the registry host
return provider.GetRegistryHostName(artifact)
}
6 changes: 3 additions & 3 deletions pkg/common/oras/authprovider/azure/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (m *MockRegistryHostGetter) GetRegistryHost(artifact string) (string, error
}

func TestDefaultAuthClientFactoryImpl_CreateAuthClient(t *testing.T) {
factory := &DefaultAuthClientFactoryImpl{}
factory := &defaultAuthClientFactoryImpl{}
serverURL := "https://example.com"
options := &azcontainerregistry.AuthenticationClientOptions{}

Expand All @@ -71,13 +71,13 @@ func TestDefaultAuthClientFactory(t *testing.T) {
serverURL := "https://example.com"
options := &azcontainerregistry.AuthenticationClientOptions{}

client, err := DefaultAuthClientFactory(serverURL, options)
client, err := defaultAuthClientFactory(serverURL, options)
assert.Nil(t, err)
assert.NotNil(t, client)
}

func TestDefaultRegistryHostGetterImpl_GetRegistryHost(t *testing.T) {
getter := &DefaultRegistryHostGetterImpl{}
getter := &defaultRegistryHostGetterImpl{}
artifact := "example.azurecr.io/myArtifact"

host, err := getter.GetRegistryHost(artifact)
Expand Down

0 comments on commit ac8e29e

Please sign in to comment.