From 74f3baf2b05f8d5bf4570e9167318a397a01e486 Mon Sep 17 00:00:00 2001 From: harrywu <1248120122@qq.com> Date: Sat, 10 Aug 2024 16:25:25 +0800 Subject: [PATCH] feat: support disable expand env param for auth --- pkg/client/config.go | 20 +++++++++++--------- pkg/utils/types/auth.go | 7 ++++--- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/pkg/client/config.go b/pkg/client/config.go index 2330cb9..6fcd73f 100644 --- a/pkg/client/config.go +++ b/pkg/client/config.go @@ -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 @@ -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 } diff --git a/pkg/utils/types/auth.go b/pkg/utils/types/auth.go index a283e9f..54e9f95 100644 --- a/pkg/utils/types/auth.go +++ b/pkg/utils/types/auth.go @@ -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"` }