2016-02-24 21:42:20 +00:00
|
|
|
package cert
|
|
|
|
|
|
|
|
import (
|
2018-01-08 18:31:38 +00:00
|
|
|
"context"
|
2016-02-24 21:42:20 +00:00
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/hashicorp/vault/logical"
|
|
|
|
"github.com/hashicorp/vault/logical/framework"
|
|
|
|
)
|
|
|
|
|
|
|
|
func pathConfig(b *backend) *framework.Path {
|
|
|
|
return &framework.Path{
|
|
|
|
Pattern: "config",
|
|
|
|
Fields: map[string]*framework.FieldSchema{
|
2016-02-25 01:34:07 +00:00
|
|
|
"disable_binding": &framework.FieldSchema{
|
2016-02-24 21:42:20 +00:00
|
|
|
Type: framework.TypeBool,
|
2016-02-25 01:34:07 +00:00
|
|
|
Default: false,
|
|
|
|
Description: `If set, during renewal, skips the matching of presented client identity with the client identity used during login. Defaults to false.`,
|
2016-02-24 21:42:20 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Callbacks: map[logical.Operation]framework.OperationFunc{
|
|
|
|
logical.UpdateOperation: b.pathConfigWrite,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-08 18:31:38 +00:00
|
|
|
func (b *backend) pathConfigWrite(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
|
2016-02-25 01:34:07 +00:00
|
|
|
disableBinding := data.Get("disable_binding").(bool)
|
2016-02-24 21:42:20 +00:00
|
|
|
|
|
|
|
entry, err := logical.StorageEntryJSON("config", config{
|
2016-02-25 01:34:07 +00:00
|
|
|
DisableBinding: disableBinding,
|
2016-02-24 21:42:20 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2018-01-19 06:44:44 +00:00
|
|
|
if err := req.Storage.Put(ctx, entry); err != nil {
|
2016-02-24 21:42:20 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Config returns the configuration for this backend.
|
2018-01-19 06:44:44 +00:00
|
|
|
func (b *backend) Config(ctx context.Context, s logical.Storage) (*config, error) {
|
|
|
|
entry, err := s.Get(ctx, "config")
|
2016-02-24 21:42:20 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2016-02-25 01:34:07 +00:00
|
|
|
// Returning a default configuration if an entry is not found
|
2016-02-24 21:42:20 +00:00
|
|
|
var result config
|
2016-02-25 01:34:07 +00:00
|
|
|
if entry != nil {
|
|
|
|
if err := entry.DecodeJSON(&result); err != nil {
|
|
|
|
return nil, fmt.Errorf("error reading configuration: %s", err)
|
|
|
|
}
|
2016-02-24 21:42:20 +00:00
|
|
|
}
|
|
|
|
return &result, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type config struct {
|
2016-02-25 01:34:07 +00:00
|
|
|
DisableBinding bool `json:"disable_binding"`
|
2016-02-24 21:42:20 +00:00
|
|
|
}
|