Skip to content

Commit

Permalink
feat: the credential script should support both username and password (
Browse files Browse the repository at this point in the history
  • Loading branch information
cgrinds committed May 6, 2024
1 parent dc185f1 commit dc9790c
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pkg/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (c *Credentials) execScript(cmdPath string, kind string, timeout string, e
return response, nil
}

// If JSON parsing fails or the data is empty,
// If YAML parsing fails or the data is empty,
// assume the output is the data (password or certificate) in plain text for backward compatibility.
response.Data = strings.TrimSpace(stdout.String())
return response, nil
Expand Down
20 changes: 19 additions & 1 deletion pkg/auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ Pollers:
pollerName: "test",
want: PollerAuth{
Username: "username", // Fallback to the username provided in the poller configuration
Password: "script-password",
Password: "password #\"`!@#$%^&*()-=[]|:'<>/ password",
HasCredentialScript: true,
},
yaml: `
Expand Down Expand Up @@ -520,6 +520,24 @@ Pollers:
addr: a.b.c
credentials_script:
path: testdata/get_password_plain
`,
},

{
name: "credentials_script returns username and password in YAML via Heredoc",
pollerName: "test",
want: PollerAuth{
Username: "myuser",
Password: "my # password",
HasCredentialScript: true,
},
yaml: `
Pollers:
test:
addr: a.b.c
username: username
credentials_script:
path: testdata/get_credentials_yaml_heredoc
`,
},
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/auth/testdata/get_credentials_yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
# Used by pkg/auth/auth_test.go
echo "username: script-username"
echo "password: script-password"
echo 'username: script-username'
echo 'password: script-password'
6 changes: 6 additions & 0 deletions pkg/auth/testdata/get_credentials_yaml_heredoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
# Used by pkg/auth/auth_test.go
cat << EOF
username: myuser
password: "my # password"
EOF
5 changes: 4 additions & 1 deletion pkg/auth/testdata/get_credentials_yaml_password
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/bin/bash
# Used by pkg/auth/auth_test.go
echo "password: script-password"
# Single quotes are used to avoid escaping special characters
# Single quotes can not contain single quotes, so we use '\'' to close
# the single quote, add a single quote, and then open the single quote again
echo 'password: "password #\"`!@#$%^&*()-=[]|:'\''<>/ password"'
2 changes: 1 addition & 1 deletion pkg/auth/testdata/get_password_plain
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
# Used by pkg/auth/auth_test.go
echo "plain-text-password"
echo 'plain-text-password'

0 comments on commit dc9790c

Please sign in to comment.