open-vault/builtin/credential/github/cli.go

66 lines
1.6 KiB
Go
Raw Normal View History

2015-04-06 16:53:43 +00:00
package github
import (
"fmt"
"os"
2015-04-06 16:53:43 +00:00
"strings"
"github.com/hashicorp/vault/api"
)
type CLIHandler struct{}
func (h *CLIHandler) Auth(c *api.Client, m map[string]string) (*api.Secret, error) {
2015-04-06 16:53:43 +00:00
mount, ok := m["mount"]
if !ok {
mount = "github"
}
token, ok := m["token"]
if !ok {
if token = os.Getenv("VAULT_AUTH_GITHUB_TOKEN"); token == "" {
return nil, fmt.Errorf("GitHub token should be provided either as 'value' for 'token' key,\nor via an env var VAULT_AUTH_GITHUB_TOKEN")
}
2015-04-06 16:53:43 +00:00
}
path := fmt.Sprintf("auth/%s/login", mount)
secret, err := c.Logical().Write(path, map[string]interface{}{
"token": token,
})
if err != nil {
return nil, err
2015-04-06 16:53:43 +00:00
}
if secret == nil {
return nil, fmt.Errorf("empty response from credential provider")
2015-04-06 16:53:43 +00:00
}
return secret, nil
2015-04-06 16:53:43 +00:00
}
func (h *CLIHandler) Help() string {
help := `
2017-09-02 22:50:03 +00:00
Usage: vault auth -method=github [CONFIG K=V...]
2015-04-06 16:53:43 +00:00
2017-09-02 22:50:03 +00:00
The GitHub authentication provider allows users to authenticate using a
GitHub personal access token. Users can generate a personal access token
from the settings page on their GitHub account.
2015-04-06 16:53:43 +00:00
2017-09-02 22:50:03 +00:00
Authenticate using a GitHub token:
2017-09-02 22:50:03 +00:00
$ vault auth -method=github token=abcd1234
2017-09-02 22:50:03 +00:00
Configuration:
mount=<string>
Path where the GitHub credential provider is mounted. This is usually
provided via the -path flag in the "vault auth" command, but it can be
specified here as well. If specified here, it takes precedence over
the value for -path. The default value is "github".
token=<string>
GitHub personal access token to use for authentication.
`
2015-04-06 16:53:43 +00:00
return strings.TrimSpace(help)
}