mirror of
https://github.com/fluxcd/flux2.git
synced 2026-02-21 15:11:47 +00:00
Merge a6cb5930f8 into d13dec297a
This commit is contained in:
commit
95b7d32ba7
4 changed files with 20 additions and 4 deletions
|
|
@ -153,13 +153,13 @@ func createSecretGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||
opts.ECDSACurve = secretGitArgs.ecdsaCurve.Curve
|
||||
opts.Password = secretGitArgs.password
|
||||
case "http", "https":
|
||||
if (secretGitArgs.username == "" || secretGitArgs.password == "") && secretGitArgs.bearerToken == "" {
|
||||
if secretGitArgs.password == "" && secretGitArgs.bearerToken == "" {
|
||||
return fmt.Errorf("for Git over HTTP/S the username and password, or a bearer token is required")
|
||||
}
|
||||
opts.Username = secretGitArgs.username
|
||||
opts.Password = secretGitArgs.password
|
||||
opts.BearerToken = secretGitArgs.bearerToken
|
||||
if secretGitArgs.username != "" && secretGitArgs.password != "" && secretGitArgs.bearerToken != "" {
|
||||
if secretGitArgs.password != "" && secretGitArgs.bearerToken != "" {
|
||||
return fmt.Errorf("user credentials and bearer token cannot be used together")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,6 +56,11 @@ func TestCreateGitSecret(t *testing.T) {
|
|||
args: "create secret git podinfo-auth --url=https://github.com/stefanprodan/podinfo --username=aaa --password=zzzz --bearer-token=aaaa --namespace=my-namespace --export",
|
||||
assert: assertError("user credentials and bearer token cannot be used together"),
|
||||
},
|
||||
{
|
||||
name: "git authentication with basic auth consisting of only one password without a username",
|
||||
args: "create secret git podinfo-auth --url=https://github.com/stefanprodan/podinfo --password=my-password --namespace=my-namespace --export",
|
||||
assert: assertGoldenFile("./testdata/create_secret/git/secret-git-only-pwd.yaml"),
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
|
|
|||
9
cmd/flux/testdata/create_secret/git/secret-git-only-pwd.yaml
vendored
Normal file
9
cmd/flux/testdata/create_secret/git/secret-git-only-pwd.yaml
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: podinfo-auth
|
||||
namespace: my-namespace
|
||||
stringData:
|
||||
password: my-password
|
||||
|
||||
|
|
@ -148,8 +148,10 @@ func buildSecret(keypair *ssh.KeyPair, hostKey, dockerCfg []byte, options Option
|
|||
return
|
||||
}
|
||||
|
||||
if options.Username != "" && options.Password != "" {
|
||||
secret.StringData[UsernameSecretKey] = options.Username
|
||||
if options.Password != "" {
|
||||
if options.Username != "" {
|
||||
secret.StringData[UsernameSecretKey] = options.Username
|
||||
}
|
||||
secret.StringData[PasswordSecretKey] = options.Password
|
||||
}
|
||||
if options.BearerToken != "" {
|
||||
|
|
|
|||
Loading…
Reference in a new issue