Skip to content

Commit

Permalink
og creds, small fixes
Browse files Browse the repository at this point in the history
Signed-off-by: gauron99 <fridrich.david19@gmail.com>
  • Loading branch information
gauron99 committed Apr 5, 2024
1 parent 7a8290a commit 18fc736
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
3 changes: 0 additions & 3 deletions cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,6 @@ func runBuild(cmd *cobra.Command, _ []string, newClient ClientFactory) (err erro
cfg buildConfig
f fn.Function
)
if err = config.CreatePaths(); err != nil { // for possible auth.json usage
return
}
if cfg, err = newBuildConfig().Prompt(); err != nil { // gather values into a single instruction set
return
}
Expand Down
3 changes: 0 additions & 3 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,6 @@ func runDeploy(cmd *cobra.Command, newClient ClientFactory) (err error) {
cfg deployConfig
f fn.Function
)
if err = config.CreatePaths(); err != nil { // for possible auth.json usage
return
}
if cfg, err = newDeployConfig(cmd).Prompt(); err != nil {
return
}
Expand Down
22 changes: 16 additions & 6 deletions pkg/docker/creds/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,25 @@ func NewCredentialsProvider(configPath string, opts ...Opt) docker.CredentialsPr
}
}

// default credential loaders map -- load only those that should be there.
// Dont include loaders that dont have valid config paths etc.
var defaultCredentialLoaders = []CredentialsCallback{}

c.authFilePath = filepath.Join(configPath, "auth.json")
sys := &containersTypes.SystemContext{
AuthFilePath: c.authFilePath,
}

var defaultCredentialLoaders = []CredentialsCallback{}
defaultCredentialLoaders = append(defaultCredentialLoaders,
func(registry string) (docker.Credentials, error) {
return getCredentialsByCredentialHelper(c.authFilePath, registry)
})
// if path to the config file does not exist -- dont include it.
// That is HOME/func/auth.json or XDG_CONFIG_HOME/func/auth.json (higher pref)
if _, err := os.Stat(c.authFilePath); err == nil {
defaultCredentialLoaders = append(defaultCredentialLoaders,
func(registry string) (docker.Credentials, error) {
return getCredentialsByCredentialHelper(c.authFilePath, registry)
})
}

// check that home is defined for .docker/config.json creds
home, err := os.UserHomeDir()
if err == nil {
dockerConfigPath := filepath.Join(home, ".docker", "config.json")
Expand Down Expand Up @@ -286,7 +294,9 @@ func (c *credentialsProvider) getCredentials(ctx context.Context, image string)
helper = strings.TrimPrefix(helper, "docker-credential-")
err = setCredentialHelperToConfig(c.authFilePath, helper)
if err != nil {
return docker.Credentials{}, fmt.Errorf("faild to set the helper to the config: %w", err)
// 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)
// return docker.Credentials{}, fmt.Errorf("faild to set the helper to the config: %w", err)
}
err = setCredentialsByCredentialHelper(c.authFilePath, registry, result.Username, result.Password)
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions pkg/docker/creds/credentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,11 +478,13 @@ func TestNewCredentialsSkipDockerConfigWhenNoHome(t *testing.T) {
helper := newInMemoryHelper()
setUpMockHelper("docker-credential-mock", helper)(t)

helper.Add(&credentials.Credentials{
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", "")
Expand Down
2 changes: 1 addition & 1 deletion pkg/functions/client_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func TestBuildWithoutHome(t *testing.T) {
}

// TestDeployWithoutWritableDotConfig ensures that running client.New works without
// .config being accessable (write/read)
// .config being accessible (write/read)
// TODO: change this test to for-loop of Runs with different dir permissions?
func TestDeployWithoutWritableDotConfig(t *testing.T) {
// defer Within(t, "tempdata/example.com/baddotconfig")
Expand Down

0 comments on commit 18fc736

Please sign in to comment.