2017-09-20 20:59:35 +00:00
|
|
|
package nomad
|
|
|
|
|
|
|
|
import (
|
2017-11-03 07:19:49 +00:00
|
|
|
"github.com/hashicorp/nomad/api"
|
2017-09-20 20:59:35 +00:00
|
|
|
"github.com/hashicorp/vault/logical"
|
|
|
|
"github.com/hashicorp/vault/logical/framework"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Factory(conf *logical.BackendConfig) (logical.Backend, error) {
|
|
|
|
b := Backend()
|
|
|
|
if err := b.Setup(conf); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return b, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func Backend() *backend {
|
|
|
|
var b backend
|
|
|
|
b.Backend = &framework.Backend{
|
2017-11-29 21:53:21 +00:00
|
|
|
PathsSpecial: &logical.Paths{
|
|
|
|
SealWrapStorage: []string{
|
|
|
|
"config/access",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2017-09-20 20:59:35 +00:00
|
|
|
Paths: []*framework.Path{
|
2017-11-06 21:34:20 +00:00
|
|
|
pathConfigAccess(&b),
|
2017-11-06 15:09:56 +00:00
|
|
|
pathConfigLease(&b),
|
2017-09-20 20:59:35 +00:00
|
|
|
pathListRoles(&b),
|
2017-11-06 21:34:20 +00:00
|
|
|
pathRoles(&b),
|
2017-11-07 14:58:19 +00:00
|
|
|
pathCredsCreate(&b),
|
2017-09-20 20:59:35 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
Secrets: []*framework.Secret{
|
|
|
|
secretToken(&b),
|
|
|
|
},
|
|
|
|
BackendType: logical.TypeLogical,
|
|
|
|
}
|
|
|
|
|
|
|
|
return &b
|
|
|
|
}
|
|
|
|
|
|
|
|
type backend struct {
|
|
|
|
*framework.Backend
|
2017-11-03 07:19:49 +00:00
|
|
|
}
|
|
|
|
|
2017-11-06 21:34:20 +00:00
|
|
|
func (b *backend) client(s logical.Storage) (*api.Client, error) {
|
|
|
|
conf, err := b.readConfigAccess(s)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2017-11-03 07:19:49 +00:00
|
|
|
}
|
|
|
|
|
2017-12-17 14:10:56 +00:00
|
|
|
nomadConf := new(api.Config)
|
|
|
|
if conf != nil {
|
|
|
|
if conf.Address != "" {
|
|
|
|
nomadConf.Address = conf.Address
|
|
|
|
}
|
|
|
|
if conf.Token != "" {
|
|
|
|
nomadConf.SecretID = conf.Token
|
|
|
|
}
|
2017-11-29 11:01:31 +00:00
|
|
|
}
|
|
|
|
|
2017-11-06 21:34:20 +00:00
|
|
|
client, err := api.NewClient(nomadConf)
|
2017-11-03 07:19:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-11-06 21:34:20 +00:00
|
|
|
return client, nil
|
2017-09-20 20:59:35 +00:00
|
|
|
}
|