logical/framework: Add delete to PathStruct
This commit is contained in:
parent
45d8c923f0
commit
896f9cd4d3
|
@ -51,6 +51,11 @@ func (p *PathStruct) Put(s logical.Storage, v map[string]interface{}) error {
|
|||
})
|
||||
}
|
||||
|
||||
// Delete removes the structure.
|
||||
func (p *PathStruct) Delete(s logical.Storage) error {
|
||||
return s.Delete(fmt.Sprintf("struct/%s", p.Name))
|
||||
}
|
||||
|
||||
// Paths are the paths to append to the Backend paths.
|
||||
func (p *PathStruct) Paths() []*Path {
|
||||
// The single path we support to read/write this config
|
||||
|
@ -59,7 +64,8 @@ func (p *PathStruct) Paths() []*Path {
|
|||
Fields: p.Schema,
|
||||
|
||||
Callbacks: map[logical.Operation]OperationFunc{
|
||||
logical.WriteOperation: p.pathWrite,
|
||||
logical.WriteOperation: p.pathWrite,
|
||||
logical.DeleteOperation: p.pathDelete,
|
||||
},
|
||||
|
||||
HelpSynopsis: p.HelpSynopsis,
|
||||
|
@ -91,3 +97,9 @@ func (p *PathStruct) pathWrite(
|
|||
err := p.Put(req.Storage, d.Raw)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (p *PathStruct) pathDelete(
|
||||
req *logical.Request, d *FieldData) (*logical.Response, error) {
|
||||
err := p.Delete(req.Storage)
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -53,4 +53,40 @@ func TestPathStruct(t *testing.T) {
|
|||
if v["value"] != "baz" {
|
||||
t.Fatalf("bad: %#v", v)
|
||||
}
|
||||
|
||||
// Delete via HTTP
|
||||
resp, err = b.HandleRequest(&logical.Request{
|
||||
Operation: logical.DeleteOperation,
|
||||
Path: "bar",
|
||||
Data: nil,
|
||||
Storage: storage,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("bad: %#v", err)
|
||||
}
|
||||
if resp != nil {
|
||||
t.Fatalf("bad: %#v", resp)
|
||||
}
|
||||
|
||||
// Re-read via HTTP
|
||||
resp, err = b.HandleRequest(&logical.Request{
|
||||
Operation: logical.ReadOperation,
|
||||
Path: "bar",
|
||||
Storage: storage,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("bad: %#v", err)
|
||||
}
|
||||
if _, ok := resp.Data["value"]; ok {
|
||||
t.Fatalf("bad: %#v", resp)
|
||||
}
|
||||
|
||||
// Re-read via API
|
||||
v, err = p.Get(storage)
|
||||
if err != nil {
|
||||
t.Fatalf("bad: %#v", err)
|
||||
}
|
||||
if v != nil {
|
||||
t.Fatalf("bad: %#v", v)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue