Skip to content

Commit

Permalink
remove unnecessary stuff
Browse files Browse the repository at this point in the history
Signed-off-by: gauron99 <fridrich.david19@gmail.com>
  • Loading branch information
gauron99 committed May 7, 2024
1 parent cb7a18e commit 3f43a08
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 70 deletions.
33 changes: 18 additions & 15 deletions pkg/docker/creds/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,20 +192,23 @@ func NewCredentialsProvider(configPath string, opts ...Opt) docker.CredentialsPr
return getCredentialsByCredentialHelper(dockerConfigPath, registry)
})
}
defaultCredentialLoaders = append(defaultCredentialLoaders,
func(registry string) (docker.Credentials, error) {
creds, err := dockerConfig.GetCredentials(sys, registry)
if err != nil {
return docker.Credentials{}, err
}
if creds.Username == "" || creds.Password == "" {
return docker.Credentials{}, ErrCredentialsNotFound
}
return docker.Credentials{
Username: creds.Username,
Password: creds.Password,
}, nil
})
// dont add this loader when configPath is empty
if configPath != "" {
defaultCredentialLoaders = append(defaultCredentialLoaders,
func(registry string) (docker.Credentials, error) {
creds, err := dockerConfig.GetCredentials(sys, registry)
if err != nil {
return docker.Credentials{}, err
}
if creds.Username == "" || creds.Password == "" {
return docker.Credentials{}, ErrCredentialsNotFound
}
return docker.Credentials{
Username: creds.Username,
Password: creds.Password,
}, nil
})
}
defaultCredentialLoaders = append(defaultCredentialLoaders,
func(registry string) (docker.Credentials, error) {
// Fallback onto default docker config locations
Expand Down Expand Up @@ -295,7 +298,7 @@ func (c *credentialsProvider) getCredentials(ctx context.Context, image string)
err = setCredentialHelperToConfig(c.authFilePath, helper)
if err != nil {
// TODO: gauron99 -- figure out what to do with this
fmt.Fprintf(os.Stderr, "Warning: failed to set the helper to the config with error: '%v'\n", err)
fmt.Fprintf(os.Stderr, "Warning: failed to set helper to the config with error: '%v'\n", err)
// return docker.Credentials{}, fmt.Errorf("faild to set the helper to the config: %w", err)
}
err = setCredentialsByCredentialHelper(c.authFilePath, registry, result.Username, result.Password)
Expand Down
38 changes: 0 additions & 38 deletions pkg/docker/creds/credentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ func startServer(t *testing.T, uname, pwd string) (addr, addrTLS string) {
panic(err)
}
}()

// make the testing CA trusted by default HTTP transport/client
oldDefaultTransport := http.DefaultTransport
newDefaultTransport := http.DefaultTransport.(*http.Transport).Clone()
Expand Down Expand Up @@ -465,43 +464,6 @@ func TestNewCredentialsProviderEmptyCreds(t *testing.T) {
}
}

// TestNewCredentialsSkipDockerConfigWhenNoHome ensures that docker .config
// credentials are NOT loaded when HOME is empty.
// (it would be at $HOME/.docker/config.json). Removing <t.Setenv("HOME", "")>
// should result in returned loaded credentials instead.
func TestNewCredentialsSkipDockerConfigWhenNoHome(t *testing.T) {
resetHomeDir(t)

// setup PATH, .docker/config.json (docker creds) and creds loader
withPopulatedDockerAuthConfig(t)

helper := newInMemoryHelper()
setUpMockHelper("docker-credential-mock", helper)(t)

if err := helper.Add(&credentials.Credentials{
ServerURL: "docker.io",
Username: dockerIoUser,
Secret: dockerIoUserPwd,
}); err != nil {
t.Error(err)
}

// have docker config credential loader but HOME is not defined -- should return nil
t.Setenv("HOME", "")
credentialsProvider := creds.NewCredentialsProvider(testConfigPath(t),
creds.WithVerifyCredentials(correctVerifyCbk),
)
returnedCreds, err := credentialsProvider(context.Background(), "docker.io/someorg/someimage:sometag")

// expect no credentials and error to be found here
if returnedCreds != (docker.Credentials{}) {
t.Errorf("expected no docker credentials to be found but got '%v'\n", returnedCreds)
}
if err != creds.ErrCredentialsNotFound {
t.Errorf("expected error to be '%v', but got '%v'", creds.ErrCredentialsNotFound, err)
}
}

func TestCredentialsProviderSavingFromUserInput(t *testing.T) {
resetHomeDir(t)

Expand Down
17 changes: 0 additions & 17 deletions pkg/functions/client_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,25 +292,8 @@ func TestUpdateWithAnnotationsAndLabels(t *testing.T) {
}
}

// TestBuildWithoutHome ensures that running func without HOME fails for pack builder
func TestBuildWithoutHome(t *testing.T) {
root, cleanup := Mktemp(t)
defer cleanup()
t.Setenv("HOME", "")
verbose := true

f := fn.Function{Runtime: "go", Name: "test-deploy-without-home", Root: root}
client := newClient(verbose)
if _, err := client.Build(context.Background(), f); err == nil {
t.Fatalf("expected an error for HOME not defined with pack builder, got none")
}

// dont call del() because function wasnt deployed
}

// TestDeployWithoutHomeWithS2i ensures that running client.New works without
// home
// TODO: change this test to for-loop of Runs with different dir permissions?
func TestDeployWithoutHomeWithS2i(t *testing.T) {
root, cleanup := Mktemp(t)
defer cleanup()
Expand Down

0 comments on commit 3f43a08

Please sign in to comment.