mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-02 03:27:54 +00:00
Added a 'read' for github config
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"github.com/hashicorp/vault/logical"
|
||||
"github.com/hashicorp/vault/logical/framework"
|
||||
"github.com/fatih/structs"
|
||||
)
|
||||
|
||||
func pathConfig(b *backend) *framework.Path {
|
||||
@@ -36,6 +37,7 @@ API-compatible authentication server.`,
|
||||
|
||||
Callbacks: map[logical.Operation]framework.OperationFunc{
|
||||
logical.UpdateOperation: b.pathConfigWrite,
|
||||
logical.ReadOperation: b.pathConfigRead,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -92,6 +94,20 @@ func (b *backend) pathConfigWrite(
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (b *backend) pathConfigRead(req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
|
||||
config, err := b.Config(req.Storage)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
config.TTL /= time.Second
|
||||
config.MaxTTL /= time.Second
|
||||
|
||||
resp := &logical.Response{
|
||||
Data: structs.New(config).Map(),
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// Config returns the configuration for this backend.
|
||||
func (b *backend) Config(s logical.Storage) (*config, error) {
|
||||
entry, err := s.Get("config")
|
||||
@@ -110,8 +126,8 @@ func (b *backend) Config(s logical.Storage) (*config, error) {
|
||||
}
|
||||
|
||||
type config struct {
|
||||
Org string `json:"organization"`
|
||||
BaseURL string `json:"base_url"`
|
||||
TTL time.Duration `json:"ttl"`
|
||||
MaxTTL time.Duration `json:"max_ttl"`
|
||||
Org string `json:"organization" structs:"organization" mapstructure:"organization"`
|
||||
BaseURL string `json:"base_url" structs:"base_url" mapstructure:"base_url"`
|
||||
TTL time.Duration `json:"ttl" structs:"ttl" mapstructure:"ttl"`
|
||||
MaxTTL time.Duration `json:"max_ttl" structs:"max_ttl" mapstructure:"max_ttl"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user