Skip to content

Commit

Permalink
chore: rename type
Browse files Browse the repository at this point in the history
Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com>
  • Loading branch information
blakepettersson committed Jul 12, 2024
1 parent 5112c6a commit 776bbe7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion internal/credentials/kubernetes/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func NewDatabase(
credentialHelpers := []credentials.Helper{
basic.SecretToCreds,
ecr.NewAccessKeyCredentialHelper(),
ecr.NewManagedIAMCredentialHelper(ctx),
ecr.NewManagedIdentityCredentialHelper(ctx),
gar.NewServiceAccountKeyCredentialHelper(),
gar.NewWorkloadIdentityFederationCredentialHelper(ctx),
github.NewAppCredentialHelper(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/akuity/kargo/internal/logging"
)

type managedIAMCredentialHelper struct {
type managedIdentityCredentialHelper struct {
awsAccountID string

tokenCache *cache.Cache
Expand All @@ -37,9 +37,9 @@ type managedIAMCredentialHelper struct {
) (string, error)
}

// NewManagedIAMCredentialHelper returns an implementation of
// NewManagedIdentityCredentialHelper returns an implementation of
// credentials.Helper that utilizes a cache to avoid unnecessary calls to AWS.
func NewManagedIAMCredentialHelper(ctx context.Context) credentials.Helper {
func NewManagedIdentityCredentialHelper(ctx context.Context) credentials.Helper {

Check warning on line 42 in internal/credentials/kubernetes/ecr/managed_identity_credential.go

View check run for this annotation

Codecov / codecov/patch

internal/credentials/kubernetes/ecr/managed_identity_credential.go#L42

Added line #L42 was not covered by tests
logger := logging.LoggerFromContext(ctx)
var awsAccountID string
if os.Getenv("AWS_CONTAINER_CREDENTIALS_FULL_URI") != "" {
Expand Down Expand Up @@ -71,7 +71,7 @@ func NewManagedIAMCredentialHelper(ctx context.Context) credentials.Helper {
awsAccountID = *res.Account
}
}
p := &managedIAMCredentialHelper{
p := &managedIdentityCredentialHelper{

Check warning on line 74 in internal/credentials/kubernetes/ecr/managed_identity_credential.go

View check run for this annotation

Codecov / codecov/patch

internal/credentials/kubernetes/ecr/managed_identity_credential.go#L74

Added line #L74 was not covered by tests
awsAccountID: awsAccountID,
tokenCache: cache.New(
// Tokens live for 12 hours. We'll hang on to them for 10.
Expand All @@ -83,7 +83,7 @@ func NewManagedIAMCredentialHelper(ctx context.Context) credentials.Helper {
return p.getCredentials
}

func (p *managedIAMCredentialHelper) getCredentials(
func (p *managedIdentityCredentialHelper) getCredentials(
ctx context.Context,
project string,
credType credentials.Type,
Expand Down Expand Up @@ -133,7 +133,7 @@ func (p *managedIAMCredentialHelper) getCredentials(
return decodeAuthToken(encodedToken)
}

func (p *managedIAMCredentialHelper) tokenCacheKey(region, project string) string {
func (p *managedIdentityCredentialHelper) tokenCacheKey(region, project string) string {
return fmt.Sprintf(
"%x",
sha256.Sum256([]byte(
Expand All @@ -145,7 +145,7 @@ func (p *managedIAMCredentialHelper) tokenCacheKey(region, project string) strin
// getAuthToken returns an ECR authorization token obtained by assuming a
// project-specific IAM role and using that to obtain a short-lived ECR access
// token.
func (p *managedIAMCredentialHelper) getAuthToken(
func (p *managedIdentityCredentialHelper) getAuthToken(
ctx context.Context,
region string,
project string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestPodIdentityCredentialHelper(t *testing.T) {

warmTokenCache := cache.New(0, 0)
warmTokenCache.Set(
(&managedIAMCredentialHelper{}).tokenCacheKey(testRegion, testProject),
(&managedIdentityCredentialHelper{}).tokenCacheKey(testRegion, testProject),
testEncodedToken,
cache.DefaultExpiration,
)
Expand All @@ -35,13 +35,13 @@ func TestPodIdentityCredentialHelper(t *testing.T) {
name string
credType credentials.Type
repoURL string
helper *managedIAMCredentialHelper
helper *managedIdentityCredentialHelper
assertions func(*testing.T, *credentials.Credentials, *cache.Cache, error)
}{
{
name: "cred type is not image",
credType: credentials.TypeGit,
helper: &managedIAMCredentialHelper{
helper: &managedIdentityCredentialHelper{
awsAccountID: testAWSAccountID,
},
assertions: func(t *testing.T, creds *credentials.Credentials, _ *cache.Cache, err error) {
Expand All @@ -53,7 +53,7 @@ func TestPodIdentityCredentialHelper(t *testing.T) {
name: "EKS Pod Identity not in use",
credType: credentials.TypeImage,
repoURL: testRepoURL,
helper: &managedIAMCredentialHelper{},
helper: &managedIdentityCredentialHelper{},
assertions: func(t *testing.T, creds *credentials.Credentials, _ *cache.Cache, err error) {
require.NoError(t, err)
require.Nil(t, creds)
Expand All @@ -63,7 +63,7 @@ func TestPodIdentityCredentialHelper(t *testing.T) {
name: "repo URL does not match ECR URL regex",
credType: credentials.TypeImage,
repoURL: "ghcr.io/fake-org/fake-repo",
helper: &managedIAMCredentialHelper{
helper: &managedIdentityCredentialHelper{
awsAccountID: testAWSAccountID,
},
assertions: func(t *testing.T, creds *credentials.Credentials, _ *cache.Cache, err error) {
Expand All @@ -75,7 +75,7 @@ func TestPodIdentityCredentialHelper(t *testing.T) {
name: "helm repo URL does not match ECR URL regex",
credType: credentials.TypeHelm,
repoURL: testRepoURL,
helper: &managedIAMCredentialHelper{
helper: &managedIdentityCredentialHelper{
awsAccountID: testAWSAccountID,
},
assertions: func(t *testing.T, creds *credentials.Credentials, _ *cache.Cache, err error) {
Expand All @@ -87,7 +87,7 @@ func TestPodIdentityCredentialHelper(t *testing.T) {
name: "cache hit",
credType: credentials.TypeImage,
repoURL: testRepoURL,
helper: &managedIAMCredentialHelper{
helper: &managedIdentityCredentialHelper{
awsAccountID: testAWSAccountID,
tokenCache: warmTokenCache,
},
Expand All @@ -102,7 +102,7 @@ func TestPodIdentityCredentialHelper(t *testing.T) {
name: "cache miss; error getting auth token",
credType: credentials.TypeImage,
repoURL: testRepoURL,
helper: &managedIAMCredentialHelper{
helper: &managedIdentityCredentialHelper{
awsAccountID: testAWSAccountID,
tokenCache: cache.New(0, 0),
getAuthTokenFn: func(context.Context, string, string) (string, error) {
Expand All @@ -118,7 +118,7 @@ func TestPodIdentityCredentialHelper(t *testing.T) {
name: "cache miss; success",
credType: credentials.TypeImage,
repoURL: testRepoURL,
helper: &managedIAMCredentialHelper{
helper: &managedIdentityCredentialHelper{
awsAccountID: testAWSAccountID,
tokenCache: cache.New(0, 0),
getAuthTokenFn: func(context.Context, string, string) (string, error) {
Expand All @@ -131,7 +131,7 @@ func TestPodIdentityCredentialHelper(t *testing.T) {
require.Equal(t, testUsername, creds.Username)
require.Equal(t, testPassword, creds.Password)
_, found := c.Get(
(&managedIAMCredentialHelper{}).tokenCacheKey(testRegion, testProject),
(&managedIdentityCredentialHelper{}).tokenCacheKey(testRegion, testProject),
)
require.True(t, found)
},
Expand All @@ -140,7 +140,7 @@ func TestPodIdentityCredentialHelper(t *testing.T) {
name: "cache miss; success (helm)",
credType: credentials.TypeHelm,
repoURL: fmt.Sprintf("oci://%s", testRepoURL),
helper: &managedIAMCredentialHelper{
helper: &managedIdentityCredentialHelper{
awsAccountID: testAWSAccountID,
tokenCache: cache.New(0, 0),
getAuthTokenFn: func(context.Context, string, string) (string, error) {
Expand All @@ -153,7 +153,7 @@ func TestPodIdentityCredentialHelper(t *testing.T) {
require.Equal(t, testUsername, creds.Username)
require.Equal(t, testPassword, creds.Password)
_, found := c.Get(
(&managedIAMCredentialHelper{}).tokenCacheKey(testRegion, testProject),
(&managedIdentityCredentialHelper{}).tokenCacheKey(testRegion, testProject),
)
require.True(t, found)
},
Expand Down

0 comments on commit 776bbe7

Please sign in to comment.