feat: set RepositorySpec.PassCredentials var type to bool (#878)
* feat: set RepositorySpec.PassCredentials var type to bool Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
		
							parent
							
								
									e8f9bbbf9d
								
							
						
					
					
						commit
						12a984d70f
					
				|  | @ -2469,7 +2469,7 @@ func (helm *mockHelmExec) SetEnableLiveOutput(enableLiveOutput bool) { | |||
| func (helm *mockHelmExec) SetDisableForceUpdate(forceUpdate bool) { | ||||
| } | ||||
| 
 | ||||
| func (helm *mockHelmExec) AddRepo(name, repository, cafile, certfile, keyfile, username, password string, managed string, passCredentials string, skipTLSVerify bool) error { | ||||
| func (helm *mockHelmExec) AddRepo(name, repository, cafile, certfile, keyfile, username, password string, managed string, passCredentials, skipTLSVerify bool) error { | ||||
| 	helm.repos = append(helm.repos, mockRepo{Name: name}) | ||||
| 	return nil | ||||
| } | ||||
|  |  | |||
|  | @ -94,8 +94,8 @@ func (helm *Helm) SetEnableLiveOutput(enableLiveOutput bool) { | |||
| } | ||||
| func (helm *Helm) SetDisableForceUpdate(forceUpdate bool) { | ||||
| } | ||||
| func (helm *Helm) AddRepo(name, repository, cafile, certfile, keyfile, username, password string, managed string, passCredentials string, skipTLSVerify bool) error { | ||||
| 	helm.Repo = []string{name, repository, cafile, certfile, keyfile, username, password, managed, passCredentials, fmt.Sprintf("%v", skipTLSVerify)} | ||||
| func (helm *Helm) AddRepo(name, repository, cafile, certfile, keyfile, username, password string, managed string, passCredentials, skipTLSVerify bool) error { | ||||
| 	helm.Repo = []string{name, repository, cafile, certfile, keyfile, username, password, managed, fmt.Sprintf("%v", passCredentials), fmt.Sprintf("%v", skipTLSVerify)} | ||||
| 	return nil | ||||
| } | ||||
| func (helm *Helm) UpdateRepo() error { | ||||
|  |  | |||
|  | @ -148,7 +148,7 @@ func (helm *execer) SetDisableForceUpdate(forceUpdate bool) { | |||
| 	helm.options.DisableForceUpdate = forceUpdate | ||||
| } | ||||
| 
 | ||||
| func (helm *execer) AddRepo(name, repository, cafile, certfile, keyfile, username, password string, managed string, passCredentials string, skipTLSVerify bool) error { | ||||
| func (helm *execer) AddRepo(name, repository, cafile, certfile, keyfile, username, password string, managed string, passCredentials, skipTLSVerify bool) error { | ||||
| 	var args []string | ||||
| 	var out []byte | ||||
| 	var err error | ||||
|  | @ -181,7 +181,7 @@ func (helm *execer) AddRepo(name, repository, cafile, certfile, keyfile, usernam | |||
| 		if username != "" && password != "" { | ||||
| 			args = append(args, "--username", username, "--password", password) | ||||
| 		} | ||||
| 		if passCredentials == "true" { | ||||
| 		if passCredentials { | ||||
| 			args = append(args, "--pass-credentials") | ||||
| 		} | ||||
| 		if skipTLSVerify { | ||||
|  |  | |||
|  | @ -114,7 +114,7 @@ func Test_AddRepo_Helm_3_3_2(t *testing.T) { | |||
| 		kubeContext: "dev", | ||||
| 		runner:      &mockRunner{}, | ||||
| 	} | ||||
| 	err := helm.AddRepo("myRepo", "https://repo.example.com/", "", "cert.pem", "key.pem", "", "", "", "", false) | ||||
| 	err := helm.AddRepo("myRepo", "https://repo.example.com/", "", "cert.pem", "key.pem", "", "", "", false, false) | ||||
| 	expected := `Adding repo myRepo https://repo.example.com/
 | ||||
| exec: helm --kube-context dev repo add myRepo https://repo.example.com/ --force-update --cert-file cert.pem --key-file key.pem
 | ||||
| ` | ||||
|  | @ -138,7 +138,7 @@ func Test_AddRepo_Helm_3_3_2_NoForceUpdate(t *testing.T) { | |||
| 		kubeContext: "dev", | ||||
| 		runner:      &mockRunner{}, | ||||
| 	} | ||||
| 	err := helm.AddRepo("myRepo", "https://repo.example.com/", "", "cert.pem", "key.pem", "", "", "", "", false) | ||||
| 	err := helm.AddRepo("myRepo", "https://repo.example.com/", "", "cert.pem", "key.pem", "", "", "", false, false) | ||||
| 	expected := `Adding repo myRepo https://repo.example.com/
 | ||||
| exec: helm --kube-context dev repo add myRepo https://repo.example.com/ --cert-file cert.pem --key-file key.pem
 | ||||
| ` | ||||
|  | @ -155,7 +155,7 @@ func Test_AddRepo(t *testing.T) { | |||
| 	var buffer bytes.Buffer | ||||
| 	logger := NewLogger(&buffer, "debug") | ||||
| 	helm := MockExecer(logger, "dev") | ||||
| 	err := helm.AddRepo("myRepo", "https://repo.example.com/", "", "cert.pem", "key.pem", "", "", "", "", false) | ||||
| 	err := helm.AddRepo("myRepo", "https://repo.example.com/", "", "cert.pem", "key.pem", "", "", "", false, false) | ||||
| 	expected := `Adding repo myRepo https://repo.example.com/
 | ||||
| exec: helm --kube-context dev repo add myRepo https://repo.example.com/ --cert-file cert.pem --key-file key.pem
 | ||||
| ` | ||||
|  | @ -168,7 +168,7 @@ exec: helm --kube-context dev repo add myRepo https://repo.example.com/ --cert-f | |||
| 	} | ||||
| 
 | ||||
| 	buffer.Reset() | ||||
| 	err = helm.AddRepo("myRepo", "https://repo.example.com/", "ca.crt", "", "", "", "", "", "", false) | ||||
| 	err = helm.AddRepo("myRepo", "https://repo.example.com/", "ca.crt", "", "", "", "", "", false, false) | ||||
| 	expected = `Adding repo myRepo https://repo.example.com/
 | ||||
| exec: helm --kube-context dev repo add myRepo https://repo.example.com/ --ca-file ca.crt
 | ||||
| ` | ||||
|  | @ -181,7 +181,7 @@ exec: helm --kube-context dev repo add myRepo https://repo.example.com/ --ca-fil | |||
| 	} | ||||
| 
 | ||||
| 	buffer.Reset() | ||||
| 	err = helm.AddRepo("myRepo", "https://repo.example.com/", "", "", "", "", "", "", "", false) | ||||
| 	err = helm.AddRepo("myRepo", "https://repo.example.com/", "", "", "", "", "", "", false, false) | ||||
| 	expected = `Adding repo myRepo https://repo.example.com/
 | ||||
| exec: helm --kube-context dev repo add myRepo https://repo.example.com/
 | ||||
| ` | ||||
|  | @ -194,7 +194,7 @@ exec: helm --kube-context dev repo add myRepo https://repo.example.com/ | |||
| 	} | ||||
| 
 | ||||
| 	buffer.Reset() | ||||
| 	err = helm.AddRepo("acrRepo", "", "", "", "", "", "", "acr", "", false) | ||||
| 	err = helm.AddRepo("acrRepo", "", "", "", "", "", "", "acr", false, false) | ||||
| 	expected = `Adding repo acrRepo (acr) | ||||
| exec: az acr helm repo add --name acrRepo | ||||
| exec: az acr helm repo add --name acrRepo:  | ||||
|  | @ -208,7 +208,7 @@ exec: az acr helm repo add --name acrRepo: | |||
| 	} | ||||
| 
 | ||||
| 	buffer.Reset() | ||||
| 	err = helm.AddRepo("otherRepo", "", "", "", "", "", "", "unknown", "", false) | ||||
| 	err = helm.AddRepo("otherRepo", "", "", "", "", "", "", "unknown", false, false) | ||||
| 	expected = `ERROR: unknown type 'unknown' for repository otherRepo | ||||
| ` | ||||
| 	if err != nil { | ||||
|  | @ -219,7 +219,7 @@ exec: az acr helm repo add --name acrRepo: | |||
| 	} | ||||
| 
 | ||||
| 	buffer.Reset() | ||||
| 	err = helm.AddRepo("myRepo", "https://repo.example.com/", "", "", "", "example_user", "example_password", "", "", false) | ||||
| 	err = helm.AddRepo("myRepo", "https://repo.example.com/", "", "", "", "example_user", "example_password", "", false, false) | ||||
| 	expected = `Adding repo myRepo https://repo.example.com/
 | ||||
| exec: helm --kube-context dev repo add myRepo https://repo.example.com/ --username example_user --password example_password
 | ||||
| ` | ||||
|  | @ -231,7 +231,7 @@ exec: helm --kube-context dev repo add myRepo https://repo.example.com/ --userna | |||
| 	} | ||||
| 
 | ||||
| 	buffer.Reset() | ||||
| 	err = helm.AddRepo("", "https://repo.example.com/", "", "", "", "", "", "", "", false) | ||||
| 	err = helm.AddRepo("", "https://repo.example.com/", "", "", "", "", "", "", false, false) | ||||
| 	expected = `empty field name | ||||
| 
 | ||||
| ` | ||||
|  | @ -243,7 +243,7 @@ exec: helm --kube-context dev repo add myRepo https://repo.example.com/ --userna | |||
| 	} | ||||
| 
 | ||||
| 	buffer.Reset() | ||||
| 	err = helm.AddRepo("myRepo", "https://repo.example.com/", "", "", "", "example_user", "example_password", "", "true", false) | ||||
| 	err = helm.AddRepo("myRepo", "https://repo.example.com/", "", "", "", "example_user", "example_password", "", true, false) | ||||
| 	expected = `Adding repo myRepo https://repo.example.com/
 | ||||
| exec: helm --kube-context dev repo add myRepo https://repo.example.com/ --username example_user --password example_password --pass-credentials
 | ||||
| ` | ||||
|  | @ -255,7 +255,7 @@ exec: helm --kube-context dev repo add myRepo https://repo.example.com/ --userna | |||
| 	} | ||||
| 
 | ||||
| 	buffer.Reset() | ||||
| 	err = helm.AddRepo("myRepo", "https://repo.example.com/", "", "", "", "", "", "", "", true) | ||||
| 	err = helm.AddRepo("myRepo", "https://repo.example.com/", "", "", "", "", "", "", false, true) | ||||
| 	expected = `Adding repo myRepo https://repo.example.com/
 | ||||
| exec: helm --kube-context dev repo add myRepo https://repo.example.com/ --insecure-skip-tls-verify
 | ||||
| ` | ||||
|  | @ -856,7 +856,7 @@ func Test_LogLevels(t *testing.T) { | |||
| 		buffer.Reset() | ||||
| 		logger := NewLogger(&buffer, logLevel) | ||||
| 		helm := MockExecer(logger, "") | ||||
| 		err := helm.AddRepo("myRepo", "https://repo.example.com/", "", "", "", "example_user", "example_password", "", "", false) | ||||
| 		err := helm.AddRepo("myRepo", "https://repo.example.com/", "", "", "", "example_user", "example_password", "", false, false) | ||||
| 		if err != nil { | ||||
| 			t.Errorf("unexpected error: %v", err) | ||||
| 		} | ||||
|  |  | |||
|  | @ -16,7 +16,7 @@ type Interface interface { | |||
| 	SetEnableLiveOutput(enableLiveOutput bool) | ||||
| 	SetDisableForceUpdate(forceUpdate bool) | ||||
| 
 | ||||
| 	AddRepo(name, repository, cafile, certfile, keyfile, username, password string, managed string, passCredentials string, skipTLSVerify bool) error | ||||
| 	AddRepo(name, repository, cafile, certfile, keyfile, username, password string, managed string, passCredentials, skipTLSVerify bool) error | ||||
| 	UpdateRepo() error | ||||
| 	RegistryLogin(name string, username string, password string) error | ||||
| 	BuildDeps(name, chart string, flags ...string) error | ||||
|  |  | |||
|  | @ -209,7 +209,7 @@ type RepositorySpec struct { | |||
| 	Password        string `yaml:"password,omitempty"` | ||||
| 	Managed         string `yaml:"managed,omitempty"` | ||||
| 	OCI             bool   `yaml:"oci,omitempty"` | ||||
| 	PassCredentials string `yaml:"passCredentials,omitempty"` | ||||
| 	PassCredentials bool   `yaml:"passCredentials,omitempty"` | ||||
| 	SkipTLSVerify   bool   `yaml:"skipTLSVerify,omitempty"` | ||||
| } | ||||
| 
 | ||||
|  | @ -499,7 +499,7 @@ func (st *HelmState) ApplyOverrides(spec *ReleaseSpec) { | |||
| 
 | ||||
| type RepoUpdater interface { | ||||
| 	IsHelm3() bool | ||||
| 	AddRepo(name, repository, cafile, certfile, keyfile, username, password string, managed string, passCredentials string, skipTLSVerify bool) error | ||||
| 	AddRepo(name, repository, cafile, certfile, keyfile, username, password string, managed string, passCredentials, skipTLSVerify bool) error | ||||
| 	UpdateRepo() error | ||||
| 	RegistryLogin(name string, username string, password string) error | ||||
| } | ||||
|  |  | |||
|  | @ -1073,7 +1073,6 @@ func Test_normalizeChart(t *testing.T) { | |||
| } | ||||
| 
 | ||||
| // mocking helmexec.Interface
 | ||||
| 
 | ||||
| func TestHelmState_SyncRepos(t *testing.T) { | ||||
| 	tests := []struct { | ||||
| 		name  string | ||||
|  | @ -1092,11 +1091,10 @@ func TestHelmState_SyncRepos(t *testing.T) { | |||
| 					KeyFile:  "", | ||||
| 					Username: "", | ||||
| 					Password: "", | ||||
| 					PassCredentials: "", | ||||
| 				}, | ||||
| 			}, | ||||
| 			helm: &exectest.Helm{}, | ||||
| 			want: []string{"name", "http://example.com/", "", "", "", "", "", "", "", "false"}, | ||||
| 			want: []string{"name", "http://example.com/", "", "", "", "", "", "", "false", "false"}, | ||||
| 		}, | ||||
| 		{ | ||||
| 			name: "ACR hosted repository", | ||||
|  | @ -1107,7 +1105,7 @@ func TestHelmState_SyncRepos(t *testing.T) { | |||
| 				}, | ||||
| 			}, | ||||
| 			helm: &exectest.Helm{}, | ||||
| 			want: []string{"name", "", "", "", "", "", "", "acr", "", "false"}, | ||||
| 			want: []string{"name", "", "", "", "", "", "", "acr", "false", "false"}, | ||||
| 		}, | ||||
| 		{ | ||||
| 			name: "repository with cert and key", | ||||
|  | @ -1119,11 +1117,10 @@ func TestHelmState_SyncRepos(t *testing.T) { | |||
| 					KeyFile:  "keyfile", | ||||
| 					Username: "", | ||||
| 					Password: "", | ||||
| 					PassCredentials: "", | ||||
| 				}, | ||||
| 			}, | ||||
| 			helm: &exectest.Helm{}, | ||||
| 			want: []string{"name", "http://example.com/", "", "certfile", "keyfile", "", "", "", "", "false"}, | ||||
| 			want: []string{"name", "http://example.com/", "", "certfile", "keyfile", "", "", "", "false", "false"}, | ||||
| 		}, | ||||
| 		{ | ||||
| 			name: "repository with ca file", | ||||
|  | @ -1134,11 +1131,10 @@ func TestHelmState_SyncRepos(t *testing.T) { | |||
| 					CaFile:   "cafile", | ||||
| 					Username: "", | ||||
| 					Password: "", | ||||
| 					PassCredentials: "", | ||||
| 				}, | ||||
| 			}, | ||||
| 			helm: &exectest.Helm{}, | ||||
| 			want: []string{"name", "http://example.com/", "cafile", "", "", "", "", "", "", "false"}, | ||||
| 			want: []string{"name", "http://example.com/", "cafile", "", "", "", "", "", "false", "false"}, | ||||
| 		}, | ||||
| 		{ | ||||
| 			name: "repository with username and password", | ||||
|  | @ -1150,11 +1146,10 @@ func TestHelmState_SyncRepos(t *testing.T) { | |||
| 					KeyFile:  "", | ||||
| 					Username: "example_user", | ||||
| 					Password: "example_password", | ||||
| 					PassCredentials: "", | ||||
| 				}, | ||||
| 			}, | ||||
| 			helm: &exectest.Helm{}, | ||||
| 			want: []string{"name", "http://example.com/", "", "", "", "example_user", "example_password", "", "", "false"}, | ||||
| 			want: []string{"name", "http://example.com/", "", "", "", "example_user", "example_password", "", "false", "false"}, | ||||
| 		}, | ||||
| 		{ | ||||
| 			name: "repository with username and password and pass-credentials", | ||||
|  | @ -1166,7 +1161,7 @@ func TestHelmState_SyncRepos(t *testing.T) { | |||
| 					KeyFile:         "", | ||||
| 					Username:        "example_user", | ||||
| 					Password:        "example_password", | ||||
| 					PassCredentials: "true", | ||||
| 					PassCredentials: true, | ||||
| 				}, | ||||
| 			}, | ||||
| 			helm: &exectest.Helm{}, | ||||
|  | @ -1182,7 +1177,6 @@ func TestHelmState_SyncRepos(t *testing.T) { | |||
| 					KeyFile:  "", | ||||
| 					Username: "", | ||||
| 					Password: "", | ||||
| 					PassCredentials: "", | ||||
| 				}, | ||||
| 			}, | ||||
| 			envs: map[string]string{ | ||||
|  | @ -1190,7 +1184,7 @@ func TestHelmState_SyncRepos(t *testing.T) { | |||
| 				"NAME_PASSWORD": "example_password", | ||||
| 			}, | ||||
| 			helm: &exectest.Helm{}, | ||||
| 			want: []string{"name", "http://example.com/", "", "", "", "example_user", "example_password", "", "", "false"}, | ||||
| 			want: []string{"name", "http://example.com/", "", "", "", "example_user", "example_password", "", "false", "false"}, | ||||
| 		}, | ||||
| 		{ | ||||
| 			name: "repository with username and password and environment with username and password", | ||||
|  | @ -1202,7 +1196,6 @@ func TestHelmState_SyncRepos(t *testing.T) { | |||
| 					KeyFile:  "", | ||||
| 					Username: "example_user1", | ||||
| 					Password: "example_password1", | ||||
| 					PassCredentials: "", | ||||
| 				}, | ||||
| 			}, | ||||
| 			envs: map[string]string{ | ||||
|  | @ -1210,7 +1203,7 @@ func TestHelmState_SyncRepos(t *testing.T) { | |||
| 				"NAME_PASSWORD": "example_password2", | ||||
| 			}, | ||||
| 			helm: &exectest.Helm{}, | ||||
| 			want: []string{"name", "http://example.com/", "", "", "", "example_user1", "example_password1", "", "", "false"}, | ||||
| 			want: []string{"name", "http://example.com/", "", "", "", "example_user1", "example_password1", "", "false", "false"}, | ||||
| 		}, | ||||
| 		{ | ||||
| 			name: "repository with skip-tls-verify", | ||||
|  | @ -1222,12 +1215,11 @@ func TestHelmState_SyncRepos(t *testing.T) { | |||
| 					KeyFile:       "", | ||||
| 					Username:      "", | ||||
| 					Password:      "", | ||||
| 					PassCredentials: "", | ||||
| 					SkipTLSVerify: true, | ||||
| 				}, | ||||
| 			}, | ||||
| 			helm: &exectest.Helm{}, | ||||
| 			want: []string{"name", "http://example.com/", "", "", "", "", "", "", "", "true"}, | ||||
| 			want: []string{"name", "http://example.com/", "", "", "", "", "", "", "false", "true"}, | ||||
| 		}, | ||||
| 	} | ||||
| 	for i := range tests { | ||||
|  |  | |||
|  | @ -77,7 +77,7 @@ func (helm *noCallHelmExec) SetDisableForceUpdate(forceUpdate bool) { | |||
| 	helm.doPanic() | ||||
| } | ||||
| 
 | ||||
| func (helm *noCallHelmExec) AddRepo(name, repository, cafile, certfile, keyfile, username, password string, managed string, passCredentials string, skipTLSVerify bool) error { | ||||
| func (helm *noCallHelmExec) AddRepo(name, repository, cafile, certfile, keyfile, username, password string, managed string, passCredentials, skipTLSVerify bool) error { | ||||
| 	helm.doPanic() | ||||
| 	return nil | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue