2015-06-30 03:29:41 +00:00
|
|
|
package cert
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/hashicorp/vault/api"
|
|
|
|
"github.com/mitchellh/mapstructure"
|
|
|
|
)
|
|
|
|
|
|
|
|
type CLIHandler struct{}
|
|
|
|
|
|
|
|
func (h *CLIHandler) Auth(c *api.Client, m map[string]string) (string, error) {
|
|
|
|
var data struct {
|
2015-12-08 04:32:49 +00:00
|
|
|
Mount string `mapstructure:"mount"`
|
2015-06-30 03:29:41 +00:00
|
|
|
}
|
|
|
|
if err := mapstructure.WeakDecode(m, &data); err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
if data.Mount == "" {
|
|
|
|
data.Mount = "cert"
|
|
|
|
}
|
|
|
|
|
|
|
|
path := fmt.Sprintf("auth/%s/login", data.Mount)
|
|
|
|
secret, err := c.Logical().Write(path, nil)
|
|
|
|
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 "cert" credential provider allows you to authenticate with a
|
|
|
|
client certificate. No other authentication materials are needed.
|
|
|
|
|
2015-08-07 22:15:53 +00:00
|
|
|
Example: vault auth -method=cert \
|
|
|
|
-client-cert=/path/to/cert.pem \
|
|
|
|
-client-key=/path/to/key.pem
|
2015-06-30 03:29:41 +00:00
|
|
|
|
|
|
|
`
|
|
|
|
|
|
|
|
return strings.TrimSpace(help)
|
|
|
|
}
|