mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 11:08:10 +00:00
This commit is contained in:
@@ -24,6 +24,7 @@ func pathConfigLease(b *backend) *framework.Path {
|
|||||||
},
|
},
|
||||||
|
|
||||||
Callbacks: map[logical.Operation]framework.OperationFunc{
|
Callbacks: map[logical.Operation]framework.OperationFunc{
|
||||||
|
logical.ReadOperation: b.pathLeaseRead,
|
||||||
logical.WriteOperation: b.pathLeaseWrite,
|
logical.WriteOperation: b.pathLeaseWrite,
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -53,7 +54,7 @@ func (b *backend) Lease(s logical.Storage) (*configLease, error) {
|
|||||||
func (b *backend) pathLeaseWrite(
|
func (b *backend) pathLeaseWrite(
|
||||||
req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
|
req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
|
||||||
leaseRaw := d.Get("lease").(string)
|
leaseRaw := d.Get("lease").(string)
|
||||||
leaseMaxRaw := d.Get("lease").(string)
|
leaseMaxRaw := d.Get("lease_max").(string)
|
||||||
|
|
||||||
lease, err := time.ParseDuration(leaseRaw)
|
lease, err := time.ParseDuration(leaseRaw)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -81,6 +82,25 @@ func (b *backend) pathLeaseWrite(
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *backend) pathLeaseRead(
|
||||||
|
req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
|
||||||
|
lease, err := b.Lease(req.Storage)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if lease == nil {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return &logical.Response{
|
||||||
|
Data: map[string]interface{}{
|
||||||
|
"lease": lease.Lease.String(),
|
||||||
|
"lease_max": lease.LeaseMax.String(),
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
type configLease struct {
|
type configLease struct {
|
||||||
Lease time.Duration
|
Lease time.Duration
|
||||||
LeaseMax time.Duration
|
LeaseMax time.Duration
|
||||||
|
|||||||
@@ -41,6 +41,21 @@ func TestBackend_roleCrud(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBackend_leaseWriteRead(t *testing.T) {
|
||||||
|
b := Backend()
|
||||||
|
|
||||||
|
logicaltest.Test(t, logicaltest.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Backend: b,
|
||||||
|
Steps: []logicaltest.TestStep{
|
||||||
|
testAccStepConfig(t),
|
||||||
|
testAccStepWriteLease(t),
|
||||||
|
testAccStepReadLease(t),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func testAccPreCheck(t *testing.T) {
|
func testAccPreCheck(t *testing.T) {
|
||||||
if v := os.Getenv("MYSQL_DSN"); v == "" {
|
if v := os.Getenv("MYSQL_DSN"); v == "" {
|
||||||
t.Fatal("MYSQL_DSN must be set for acceptance tests")
|
t.Fatal("MYSQL_DSN must be set for acceptance tests")
|
||||||
@@ -122,6 +137,31 @@ func testAccStepReadRole(t *testing.T, name string, sql string) logicaltest.Test
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccStepWriteLease(t *testing.T) logicaltest.TestStep {
|
||||||
|
return logicaltest.TestStep{
|
||||||
|
Operation: logical.WriteOperation,
|
||||||
|
Path: "config/lease",
|
||||||
|
Data: map[string]interface{}{
|
||||||
|
"lease": "1h5m",
|
||||||
|
"lease_max": "24h",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func testAccStepReadLease(t *testing.T) logicaltest.TestStep {
|
||||||
|
return logicaltest.TestStep{
|
||||||
|
Operation: logical.ReadOperation,
|
||||||
|
Path: "config/lease",
|
||||||
|
Check: func(resp *logical.Response) error {
|
||||||
|
if resp.Data["lease"] != "1h5m0s" || resp.Data["lease_max"] != "24h0m0s" {
|
||||||
|
return fmt.Errorf("bad: %#v", resp)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const testRole = `
|
const testRole = `
|
||||||
CREATE USER '{{name}}'@'%' IDENTIFIED BY '{{password}}';
|
CREATE USER '{{name}}'@'%' IDENTIFIED BY '{{password}}';
|
||||||
GRANT SELECT ON *.* TO '{{name}}'@'%';
|
GRANT SELECT ON *.* TO '{{name}}'@'%';
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ func pathConfigLease(b *backend) *framework.Path {
|
|||||||
},
|
},
|
||||||
|
|
||||||
Callbacks: map[logical.Operation]framework.OperationFunc{
|
Callbacks: map[logical.Operation]framework.OperationFunc{
|
||||||
|
logical.ReadOperation: b.pathLeaseRead,
|
||||||
logical.WriteOperation: b.pathLeaseWrite,
|
logical.WriteOperation: b.pathLeaseWrite,
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -35,7 +36,7 @@ func pathConfigLease(b *backend) *framework.Path {
|
|||||||
func (b *backend) pathLeaseWrite(
|
func (b *backend) pathLeaseWrite(
|
||||||
req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
|
req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
|
||||||
leaseRaw := d.Get("lease").(string)
|
leaseRaw := d.Get("lease").(string)
|
||||||
leaseMaxRaw := d.Get("lease").(string)
|
leaseMaxRaw := d.Get("lease_max").(string)
|
||||||
|
|
||||||
lease, err := time.ParseDuration(leaseRaw)
|
lease, err := time.ParseDuration(leaseRaw)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -63,6 +64,25 @@ func (b *backend) pathLeaseWrite(
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *backend) pathLeaseRead(
|
||||||
|
req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
|
||||||
|
lease, err := b.Lease(req.Storage)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if lease == nil {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return &logical.Response{
|
||||||
|
Data: map[string]interface{}{
|
||||||
|
"lease": lease.Lease.String(),
|
||||||
|
"lease_max": lease.LeaseMax.String(),
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
type configLease struct {
|
type configLease struct {
|
||||||
Lease time.Duration
|
Lease time.Duration
|
||||||
LeaseMax time.Duration
|
LeaseMax time.Duration
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ func pathConfigLease(b *backend) *framework.Path {
|
|||||||
},
|
},
|
||||||
|
|
||||||
Callbacks: map[logical.Operation]framework.OperationFunc{
|
Callbacks: map[logical.Operation]framework.OperationFunc{
|
||||||
|
logical.ReadOperation: b.pathLeaseRead,
|
||||||
logical.WriteOperation: b.pathLeaseWrite,
|
logical.WriteOperation: b.pathLeaseWrite,
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -35,7 +36,7 @@ func pathConfigLease(b *backend) *framework.Path {
|
|||||||
func (b *backend) pathLeaseWrite(
|
func (b *backend) pathLeaseWrite(
|
||||||
req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
|
req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
|
||||||
leaseRaw := d.Get("lease").(string)
|
leaseRaw := d.Get("lease").(string)
|
||||||
leaseMaxRaw := d.Get("lease").(string)
|
leaseMaxRaw := d.Get("lease_max").(string)
|
||||||
|
|
||||||
lease, err := time.ParseDuration(leaseRaw)
|
lease, err := time.ParseDuration(leaseRaw)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -63,6 +64,25 @@ func (b *backend) pathLeaseWrite(
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *backend) pathLeaseRead(
|
||||||
|
req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
|
||||||
|
lease, err := b.Lease(req.Storage)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if lease == nil {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return &logical.Response{
|
||||||
|
Data: map[string]interface{}{
|
||||||
|
"lease": lease.Lease.String(),
|
||||||
|
"lease_max": lease.LeaseMax.String(),
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
type configLease struct {
|
type configLease struct {
|
||||||
Lease time.Duration
|
Lease time.Duration
|
||||||
LeaseMax time.Duration
|
LeaseMax time.Duration
|
||||||
|
|||||||
Reference in New Issue
Block a user