open-vault/builtin/logical/nomad/backend.go

69 lines
1.2 KiB
Go
Raw Normal View History

2017-09-20 20:59:35 +00:00
package nomad
import (
"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{
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),
pathConfigLease(&b),
2017-09-20 20:59:35 +00:00
pathListRoles(&b),
2017-11-06 21:34:20 +00:00
pathRoles(&b),
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-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
}
nomadConf := new(api.Config)
if conf != nil {
if conf.Address != "" {
nomadConf.Address = conf.Address
}
if conf.Token != "" {
nomadConf.SecretID = conf.Token
}
}
2017-11-06 21:34:20 +00:00
client, err := api.NewClient(nomadConf)
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
}