2015-04-06 16:53:43 +00:00
|
|
|
package github
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-06-09 17:38:46 +00:00
|
|
|
"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) (string, error) {
|
|
|
|
mount, ok := m["mount"]
|
|
|
|
if !ok {
|
|
|
|
mount = "github"
|
|
|
|
}
|
|
|
|
|
|
|
|
token, ok := m["token"]
|
|
|
|
if !ok {
|
2016-06-09 18:00:56 +00:00
|
|
|
if token = os.Getenv("VAULT_AUTH_GITHUB_TOKEN"); token == "" {
|
|
|
|
return "", fmt.Errorf("GitHub token should be provided either as 'value' for 'token' key,\nor via an env var VAULT_AUTH_GITHUB_TOKEN")
|
2016-06-09 17:38:46 +00:00
|
|
|
}
|
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 "", err
|
|
|
|
}
|
|
|
|
if secret == nil {
|
|
|
|
return "", fmt.Errorf("empty response from credential provider")
|
|
|
|
}
|
|
|
|
|
|
|
|
return secret.Auth.ClientToken, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *CLIHandler) Help() string {
|
|
|
|
help := `
|
|
|
|
The GitHub credential provider allows you to authenticate with GitHub.
|
2015-05-08 15:45:29 +00:00
|
|
|
To use it, specify the "token" parameter. The value should be a personal access
|
|
|
|
token for your GitHub account. You can generate a personal access token on your
|
|
|
|
account settings page on GitHub.
|
2015-04-06 16:53:43 +00:00
|
|
|
|
2015-05-07 18:13:12 +00:00
|
|
|
Example: vault auth -method=github token=<token>
|
2015-04-06 16:53:43 +00:00
|
|
|
|
2015-06-16 17:05:11 +00:00
|
|
|
Key/Value Pairs:
|
|
|
|
|
|
|
|
mount=github The mountpoint for the GitHub credential provider.
|
2015-06-16 17:05:51 +00:00
|
|
|
Defaults to "github"
|
2015-06-16 17:05:11 +00:00
|
|
|
|
|
|
|
token=<token> The GitHub personal access token for authentication.
|
2015-04-06 16:53:43 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
return strings.TrimSpace(help)
|
|
|
|
}
|