I'm writing a custom plugin for Hashicorp vault in golang. I created a backend server to handle the plugin requests
err := plugin.Serve(&plugin.ServeOpts{
BackendFactoryFunc: backend.Factory,
TLSProviderFunc: tlsProviderFunc,
})
if err != nil {
log.Println(err)
os.Exit(1)
}
In the backend server I registered two paths:
func Backend() (*backend, error) {
var b backend
b.Backend = &framework.Backend{
Help: "",
Paths: framework.PathAppend(
registerFoo1(&b),
registerFoo2(&b),
),
PathsSpecial: &logical.Paths{
SealWrapStorage: []string{
"foo1/",
"foo2/",
},
},
Secrets: []*framework.Secret{},
BackendType: logical.TypeLogical,
}
return &b, nil
}
The requests to foo1 are received and handled, but the plugin ignored requests to foo2.
The error message is: {"errors":["1 error occurred:\n\t* unsupported path\n\n"]}
. The error message raises in different HTTP verbs.
Both paths have their own module inside the package(foo1.go
and foo2.go
)
foo1.go
func registerFoo1(b *backend) []*framework.Path {
var paths = []*framework.Path{
foo1(b),
}
return paths
}
func (b *backend) foo1(ctx context.Context, req *logical.Request,
data *framework.FieldData) (*logical.Response, error) {
...
name := data.Get("name").(string)
...
}
foo2.go
func registerFoo2(b *backend) []*framework.Path {
var paths = []*framework.Path{
foo2(b),
}
return paths
}
func (b *backend) foo2(ctx context.Context, req *logical.Request,
data *framework.FieldData) (*logical.Response, error) {
...
var1 := data.Get("name").(string)
anothervar, err := b.getsomedata(ctx, req, address)
if err != nil {
b.Logger().Error("cannot get data: ", err.Error())
return nil, err
}
...
}