Skip to content

Commit

Permalink
Add More PassedEnvs for ECR CredHelper
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Chew <[email protected]>
  • Loading branch information
chews93319 committed Oct 7, 2024
1 parent db7b6b4 commit 59b7f97
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
36 changes: 36 additions & 0 deletions cmd/finch/nerdctl_darwin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ func TestNerdctlCommand_run_pullCommand(t *testing.T) {
ncsd.EXPECT().LookupEnv("AWS_ACCESS_KEY_ID").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_SECRET_ACCESS_KEY").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_SESSION_TOKEN").Return("", false)
ncsd.EXPECT().LookupEnv("SOURCE_DATE_EPOCH").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_ECR_DISABLE_CACHE").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_ECR_CACHE_DIR").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_ECR_IGNORE_CREDS_STORAGE").Return("", false)
ncsd.EXPECT().LookupEnv("COSIGN_PASSWORD").Return("test", true)
ncsd.EXPECT().LookupEnv("COMPOSE_FILE").Return("", false)
c := mocks.NewCommand(ctrl)
Expand Down Expand Up @@ -216,6 +220,10 @@ func TestNerdctlCommand_run_pullCommand(t *testing.T) {
ncsd.EXPECT().LookupEnv("AWS_ACCESS_KEY_ID").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_SECRET_ACCESS_KEY").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_SESSION_TOKEN").Return("", false)
ncsd.EXPECT().LookupEnv("SOURCE_DATE_EPOCH").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_ECR_DISABLE_CACHE").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_ECR_CACHE_DIR").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_ECR_IGNORE_CREDS_STORAGE").Return("", false)
ncsd.EXPECT().LookupEnv("COSIGN_PASSWORD").Return("test", true)
ncsd.EXPECT().LookupEnv("COMPOSE_FILE").Return("", false)
c := mocks.NewCommand(ctrl)
Expand Down Expand Up @@ -246,6 +254,10 @@ func TestNerdctlCommand_run_pullCommand(t *testing.T) {
ncsd.EXPECT().LookupEnv("AWS_ACCESS_KEY_ID").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_SECRET_ACCESS_KEY").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_SESSION_TOKEN").Return("", false)
ncsd.EXPECT().LookupEnv("SOURCE_DATE_EPOCH").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_ECR_DISABLE_CACHE").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_ECR_CACHE_DIR").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_ECR_IGNORE_CREDS_STORAGE").Return("", false)
ncsd.EXPECT().LookupEnv("COSIGN_PASSWORD").Return("test", true)
ncsd.EXPECT().LookupEnv("COMPOSE_FILE").Return("", false)
c := mocks.NewCommand(ctrl)
Expand Down Expand Up @@ -282,6 +294,10 @@ func TestNerdctlCommand_run_pullCommand(t *testing.T) {
ncsd.EXPECT().LookupEnv("AWS_SESSION_TOKEN").Return("TEST_SESSION_TOKEN", true)
ncsd.EXPECT().LookupEnv("COSIGN_PASSWORD").Return("", false)
ncsd.EXPECT().LookupEnv("COMPOSE_FILE").Return("", false)
ncsd.EXPECT().LookupEnv("SOURCE_DATE_EPOCH").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_ECR_DISABLE_CACHE").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_ECR_CACHE_DIR").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_ECR_IGNORE_CREDS_STORAGE").Return("", false)

awsCmd := mocks.NewCommand(ctrl)
ecc.EXPECT().Create(
Expand Down Expand Up @@ -344,6 +360,10 @@ func TestNerdctlCommand_run_pullCommand(t *testing.T) {
ncsd.EXPECT().LookupEnv("AWS_SESSION_TOKEN").Return("TEST_SESSION_TOKEN", false)
ncsd.EXPECT().LookupEnv("COSIGN_PASSWORD").Return("", false)
ncsd.EXPECT().LookupEnv("COMPOSE_FILE").Return("", false)
ncsd.EXPECT().LookupEnv("SOURCE_DATE_EPOCH").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_ECR_DISABLE_CACHE").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_ECR_CACHE_DIR").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_ECR_IGNORE_CREDS_STORAGE").Return("", false)

awsCmd := mocks.NewCommand(ctrl)
ecc.EXPECT().Create(
Expand Down Expand Up @@ -403,6 +423,10 @@ func TestNerdctlCommand_run_pullCommand(t *testing.T) {
ncsd.EXPECT().LookupEnv("AWS_SESSION_TOKEN").Return("TEST_SESSION_TOKEN", true)
ncsd.EXPECT().LookupEnv("COSIGN_PASSWORD").Return("", false)
ncsd.EXPECT().LookupEnv("COMPOSE_FILE").Return("", false)
ncsd.EXPECT().LookupEnv("SOURCE_DATE_EPOCH").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_ECR_DISABLE_CACHE").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_ECR_CACHE_DIR").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_ECR_IGNORE_CREDS_STORAGE").Return("", false)

awsCmd := mocks.NewCommand(ctrl)
ecc.EXPECT().Create(
Expand Down Expand Up @@ -458,6 +482,10 @@ func TestNerdctlCommand_run_pullCommand(t *testing.T) {
ncsd.EXPECT().LookupEnv("AWS_SESSION_TOKEN").Return("TEST_SESSION_TOKEN", true)
ncsd.EXPECT().LookupEnv("COSIGN_PASSWORD").Return("", false)
ncsd.EXPECT().LookupEnv("COMPOSE_FILE").Return("", false)
ncsd.EXPECT().LookupEnv("SOURCE_DATE_EPOCH").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_ECR_DISABLE_CACHE").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_ECR_CACHE_DIR").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_ECR_IGNORE_CREDS_STORAGE").Return("", false)

awsCmd := mocks.NewCommand(ctrl)
ecc.EXPECT().Create(
Expand Down Expand Up @@ -1522,6 +1550,10 @@ func TestNerdctlCommand_run_miscCommand(t *testing.T) {
ncsd.EXPECT().LookupEnv("AWS_ACCESS_KEY_ID").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_SECRET_ACCESS_KEY").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_SESSION_TOKEN").Return("", false)
ncsd.EXPECT().LookupEnv("SOURCE_DATE_EPOCH").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_ECR_DISABLE_CACHE").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_ECR_CACHE_DIR").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_ECR_IGNORE_CREDS_STORAGE").Return("", false)
ncsd.EXPECT().LookupEnv("COSIGN_PASSWORD").Return("test", true)
ncsd.EXPECT().LookupEnv("COMPOSE_FILE").Return("", false)
c := mocks.NewCommand(ctrl)
Expand Down Expand Up @@ -1583,6 +1615,10 @@ func AddEmptyEnvLookUps(ncsd *mocks.NerdctlCommandSystemDeps) {
ncsd.EXPECT().LookupEnv("AWS_SESSION_TOKEN").Return("", false)
ncsd.EXPECT().LookupEnv("COSIGN_PASSWORD").Return("", false)
ncsd.EXPECT().LookupEnv("COMPOSE_FILE").Return("", false)
ncsd.EXPECT().LookupEnv("SOURCE_DATE_EPOCH").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_ECR_DISABLE_CACHE").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_ECR_CACHE_DIR").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_ECR_IGNORE_CREDS_STORAGE").Return("", false)
}

type ContainsSubstring struct {
Expand Down
3 changes: 2 additions & 1 deletion cmd/finch/nerdctl_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ func (nc *nerdctlCommand) run(cmdName string, args []string) error {

passedEnvs := []string{
"COSIGN_PASSWORD", "AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY",
"AWS_SESSION_TOKEN", "COMPOSE_FILE",
"AWS_SESSION_TOKEN", "COMPOSE_FILE", "SOURCE_DATE_EPOCH",
"AWS_ECR_DISABLE_CACHE", "AWS_ECR_CACHE_DIR", "AWS_ECR_IGNORE_CREDS_STORAGE",
}

var passedEnvArgs []string
Expand Down
16 changes: 16 additions & 0 deletions cmd/finch/nerdctl_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,10 @@ func TestNerdctlCommand_run(t *testing.T) {
ncsd.EXPECT().LookupEnv("AWS_SESSION_TOKEN").Return("", false)
ncsd.EXPECT().LookupEnv("COSIGN_PASSWORD").Return("test", true)
ncsd.EXPECT().LookupEnv("COMPOSE_FILE").Return("", false)
ncsd.EXPECT().LookupEnv("SOURCE_DATE_EPOCH").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_ECR_DISABLE_CACHE").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_ECR_CACHE_DIR").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_ECR_IGNORE_CREDS_STORAGE").Return("", false)
ncsd.EXPECT().GetWd().Return("C:\\workdir", nil)
ncsd.EXPECT().FilePathAbs("C:\\workdir").Return("C:\\workdir", nil)
ncsd.EXPECT().FilePathJoin(string(filepath.Separator), "mnt", "c", "workdir").Return(augmentedPath)
Expand Down Expand Up @@ -712,6 +716,10 @@ func TestNerdctlCommand_run(t *testing.T) {
ncsd.EXPECT().LookupEnv("AWS_SESSION_TOKEN").Return("", false)
ncsd.EXPECT().LookupEnv("COSIGN_PASSWORD").Return("test", true)
ncsd.EXPECT().LookupEnv("COMPOSE_FILE").Return("", false)
ncsd.EXPECT().LookupEnv("SOURCE_DATE_EPOCH").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_ECR_DISABLE_CACHE").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_ECR_CACHE_DIR").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_ECR_IGNORE_CREDS_STORAGE").Return("", false)
ncsd.EXPECT().GetWd().Return("C:\\workdir", nil)
ncsd.EXPECT().FilePathAbs("C:\\workdir").Return("C:\\workdir", nil)
ncsd.EXPECT().FilePathJoin(string(filepath.Separator), "mnt", "c", "workdir").Return(augmentedPath)
Expand Down Expand Up @@ -747,6 +755,10 @@ func TestNerdctlCommand_run(t *testing.T) {
ncsd.EXPECT().LookupEnv("AWS_SESSION_TOKEN").Return("", false)
ncsd.EXPECT().LookupEnv("COSIGN_PASSWORD").Return("test", true)
ncsd.EXPECT().LookupEnv("COMPOSE_FILE").Return("", false)
ncsd.EXPECT().LookupEnv("SOURCE_DATE_EPOCH").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_ECR_DISABLE_CACHE").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_ECR_CACHE_DIR").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_ECR_IGNORE_CREDS_STORAGE").Return("", false)
ncsd.EXPECT().GetWd().Return("C:\\workdir", nil)
ncsd.EXPECT().FilePathAbs("C:\\workdir").Return("C:\\workdir", nil)
ncsd.EXPECT().FilePathJoin(string(filepath.Separator), "mnt", "c", "workdir").Return(augmentedPath)
Expand Down Expand Up @@ -1217,4 +1229,8 @@ func AddEmptyEnvLookUps(ncsd *mocks.NerdctlCommandSystemDeps) {
ncsd.EXPECT().LookupEnv("AWS_SESSION_TOKEN").Return("", false)
ncsd.EXPECT().LookupEnv("COSIGN_PASSWORD").Return("", false)
ncsd.EXPECT().LookupEnv("COMPOSE_FILE").Return("", false)
ncsd.EXPECT().LookupEnv("SOURCE_DATE_EPOCH").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_ECR_DISABLE_CACHE").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_ECR_CACHE_DIR").Return("", false)
ncsd.EXPECT().LookupEnv("AWS_ECR_IGNORE_CREDS_STORAGE").Return("", false)
}

0 comments on commit 59b7f97

Please sign in to comment.