From a42c14e6404eadbb14a76923a3404950f8b6e391 Mon Sep 17 00:00:00 2001 From: mugioka Date: Mon, 3 Oct 2022 14:21:44 +0900 Subject: [PATCH] imprv: convert hyphen included in repo name to underbar with gatherOCIUsernamePassword. Most shells do not support hyphens in environment variables. However, there are cases where you may want to include hyphens in the repository name. Therefore, I have included a process in `gatherOCIUsernamePassword` to replace hyphens with underbar. Signed-off-by: mugioka --- docs/index.md | 14 ++++++++++++++ pkg/state/state.go | 5 +++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/docs/index.md b/docs/index.md index 887cd839..4fba3cf2 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1498,6 +1498,20 @@ export MYOCIREGISTRY_USERNAME=spongebob export MYOCIREGISTRY_PASSWORD=squarepants ``` +If `` contains hyphens, the environment variable to be read is the hyphen replaced by an underscore., e.g. + +```yaml +repositories: + - name: my-oci-registry + url: myregistry.azurecr.io + oci: true +``` + +```shell +export MY_OCI_REGISTRY_USERNAME=spongebob +export MY_OCI_REGISTRY_PASSWORD=squarepants +``` + ## Attribution We use: diff --git a/pkg/state/state.go b/pkg/state/state.go index 97d921ae..69ffd0dc 100644 --- a/pkg/state/state.go +++ b/pkg/state/state.go @@ -455,15 +455,16 @@ func (st *HelmState) SyncRepos(helm RepoUpdater, shouldSkip map[string]bool) ([] func gatherOCIUsernamePassword(repoName string, username string, password string) (string, string) { var user, pass string + replacedRepoName := strings.ToUpper(strings.Replace(repoName, "-", "_", -1)) if username != "" { user = username - } else if u := os.Getenv(fmt.Sprintf("%s_USERNAME", strings.ToUpper(repoName))); u != "" { + } else if u := os.Getenv(fmt.Sprintf("%s_USERNAME", replacedRepoName)); u != "" { user = u } if password != "" { pass = password - } else if p := os.Getenv(fmt.Sprintf("%s_PASSWORD", strings.ToUpper(repoName))); p != "" { + } else if p := os.Getenv(fmt.Sprintf("%s_PASSWORD", replacedRepoName)); p != "" { pass = p }