Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support disable expand env param for auth #158

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions pkg/client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,11 @@ func NewSyncConfig(configFile, authFilePath, imageFilePath string,
return nil, fmt.Errorf("decode auth file %v error: %v", authFilePath, err)
}
}
config.AuthList = expandEnv(config.AuthList)

if err := openAndDecode(imageFilePath, &config.ImageList); err != nil {
return nil, fmt.Errorf("decode image file %v error: %v", imageFilePath, err)
}
}

config.AuthList = expandEnv(config.AuthList)
config.osFilterList = osFilterList
config.archFilterList = archFilterList

Expand Down Expand Up @@ -120,12 +118,16 @@ func expandEnv(authMap map[string]types.Auth) map[string]types.Auth {
result := make(map[string]types.Auth)

for registry, auth := range authMap {
pwd := os.ExpandEnv(auth.Password)
name := os.ExpandEnv(auth.Username)
newAuth := types.Auth{
Username: name,
Password: pwd,
Insecure: auth.Insecure,
newAuth := auth
if !auth.DisableExpandEnv {
pwd := os.ExpandEnv(auth.Password)
name := os.ExpandEnv(auth.Username)
newAuth = types.Auth{
Username: name,
Password: pwd,
Insecure: auth.Insecure,
DisableExpandEnv: auth.DisableExpandEnv,
}
}
result[registry] = newAuth
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/utils/types/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package types

// Auth describes the authentication information of a registry or a repository
type Auth struct {
Username string `json:"username" yaml:"username"`
Password string `json:"password" yaml:"password"`
Insecure bool `json:"insecure" yaml:"insecure"`
Username string `json:"username" yaml:"username"`
Password string `json:"password" yaml:"password"`
Insecure bool `json:"insecure" yaml:"insecure"`
DisableExpandEnv bool `json:"disableexpandenv" yaml:"disableexpandenv"`
}