Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable hierarchical path for library sets #105

Merged
merged 17 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,26 @@ func Backend(client ldapClient) *backend {
},
},
Paths: framework.PathAppend(
b.pathListStaticRoles(),
// These paths must be at the top of the list since their regex
// Patterns are the most specific. Otherwise, a more generic regex
// will swallow the request because role and set names can contain
// arbitrary numbers of slashes.
// For example, a request to `library/:set_name/check-in` could be
// swallowed by the regex for `library/:set_name`.
b.pathSetManageCheckIn(),
b.pathSetCheckIn(),
b.pathSetCheckOut(),
b.pathSetStatus(),

// These paths are more generic than the above. They must be
// appended last.
b.pathConfig(),
b.pathDynamicRoles(),
b.pathDynamicCredsCreate(),
b.pathStaticRoles(),
b.pathStaticCredsCreate(),
b.pathListStaticRoles(),
b.pathRotateCredentials(),
b.pathSetCheckIn(),
b.pathSetManageCheckIn(),
b.pathSetCheckOut(),
b.pathSetStatus(),
b.pathSets(),
b.pathListSets(),
),
Expand Down
21 changes: 16 additions & 5 deletions path_checkout_sets.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package openldap
import (
"context"
"fmt"
"strings"
"time"

"github.com/hashicorp/go-secure-stdlib/strutil"
Expand All @@ -14,7 +15,10 @@ import (
"github.com/hashicorp/vault/sdk/logical"
)

const libraryPrefix = "library/"
const (
libraryPrefix = "library/"
libraryManagePrefix = "library/manage/"
)

type librarySet struct {
ServiceAccountNames []string `json:"service_account_names"`
Expand Down Expand Up @@ -45,7 +49,7 @@ func (l *librarySet) Validate() error {
func (b *backend) pathListSets() []*framework.Path {
return []*framework.Path{
{
Pattern: libraryPrefix + "?$",
Pattern: strings.TrimSuffix(libraryPrefix, "/") + optionalGenericNameWithForwardSlashListRegex("path"),
DisplayAttrs: &framework.DisplayAttributes{
OperationPrefix: operationPrefixLDAPLibrary,
OperationVerb: "list",
Expand All @@ -55,14 +59,21 @@ func (b *backend) pathListSets() []*framework.Path {
Callback: b.listSetsOperation,
},
},
Fields: map[string]*framework.FieldSchema{
"path": {
Type: framework.TypeLowerCaseString,
Description: "Path of sets to list",
},
},
HelpSynopsis: pathListSetsHelpSyn,
HelpDescription: pathListSetsHelpDesc,
},
}
}

func (b *backend) listSetsOperation(ctx context.Context, req *logical.Request, _ *framework.FieldData) (*logical.Response, error) {
keys, err := req.Storage.List(ctx, libraryPrefix)
func (b *backend) listSetsOperation(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
setPath := data.Get("path").(string)
keys, err := req.Storage.List(ctx, libraryPrefix+setPath)
if err != nil {
return nil, err
}
Expand All @@ -72,7 +83,7 @@ func (b *backend) listSetsOperation(ctx context.Context, req *logical.Request, _
func (b *backend) pathSets() []*framework.Path {
return []*framework.Path{
{
Pattern: libraryPrefix + framework.GenericNameRegex("name"),
Pattern: strings.TrimSuffix(libraryPrefix, "/") + genericNameWithForwardSlashRegex("name"),
DisplayAttrs: &framework.DisplayAttributes{
OperationPrefix: operationPrefixLDAPLibrary,
},
Expand Down
Loading