Add listing of roles to ssh backend
This commit is contained in:
parent
dcf844027b
commit
dd57a3f55d
|
@ -47,6 +47,7 @@ func Backend(conf *logical.BackendConfig) (*framework.Backend, error) {
|
|||
Paths: []*framework.Path{
|
||||
pathConfigZeroAddress(&b),
|
||||
pathKeys(&b),
|
||||
pathListRoles(&b),
|
||||
pathRoles(&b),
|
||||
pathCredsCreate(&b),
|
||||
pathLookup(&b),
|
||||
|
|
|
@ -30,6 +30,19 @@ type sshRole struct {
|
|||
KeyOptionSpecs string `mapstructure:"key_option_specs" json:"key_option_specs"`
|
||||
}
|
||||
|
||||
func pathListRoles(b *backend) *framework.Path {
|
||||
return &framework.Path{
|
||||
Pattern: "roles/?$",
|
||||
|
||||
Callbacks: map[logical.Operation]framework.OperationFunc{
|
||||
logical.ListOperation: b.pathRoleList,
|
||||
},
|
||||
|
||||
HelpSynopsis: pathRoleHelpSyn,
|
||||
HelpDescription: pathRoleHelpDesc,
|
||||
}
|
||||
}
|
||||
|
||||
func pathRoles(b *backend) *framework.Path {
|
||||
return &framework.Path{
|
||||
Pattern: "roles/" + framework.GenericNameRegex("role"),
|
||||
|
@ -134,7 +147,7 @@ func pathRoles(b *backend) *framework.Path {
|
|||
|
||||
Callbacks: map[logical.Operation]framework.OperationFunc{
|
||||
logical.ReadOperation: b.pathRoleRead,
|
||||
logical.UpdateOperation: b.pathRoleWrite,
|
||||
logical.UpdateOperation: b.pathRoleWrite,
|
||||
logical.DeleteOperation: b.pathRoleDelete,
|
||||
},
|
||||
|
||||
|
@ -292,6 +305,15 @@ func (b *backend) getRole(s logical.Storage, n string) (*sshRole, error) {
|
|||
return &result, nil
|
||||
}
|
||||
|
||||
func (b *backend) pathRoleList(req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
|
||||
entries, err := req.Storage.List("roles/")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return logical.ListResponse(entries), nil
|
||||
}
|
||||
|
||||
func (b *backend) pathRoleRead(req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
|
||||
role, err := b.getRole(req.Storage, d.Get("role").(string))
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue