Skip to content

Commit

Permalink
KSM-505 Added uid as path parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
idimov-keeper committed Apr 3, 2024
1 parent d262b7f commit 5739897
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions integration/vault-plugin-secrets-ksm/ksm/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func Factory(ctx context.Context, conf *logical.BackendConfig) (logical.Backend,
b.pathConfig(),
b.pathUidgen(),
b.pathTotp(),
b.pathRecord(),
b.pathRecords(),
b.pathRecordsCreate(),
b.pathRecordsList(),
Expand Down
31 changes: 31 additions & 0 deletions integration/vault-plugin-secrets-ksm/ksm/path_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import (
// pathPatternRecord is the string used to define the base path of the record endpoint.
const pathPatternRecord = "record/?$"

// pathPatternRecordAsPathParam is the string used to define the base path of the record endpoint.
const pathPatternRecordAsPathParam = "^record/(?P<uid>[A-Za-z0-9_-]{22})$"

// pathPatternRecordCreate is the string used to define the base path of the record create endpoint.
const pathPatternRecordCreate = "record/create/?$"

Expand Down Expand Up @@ -62,6 +65,30 @@ func (b *backend) pathRecordsList() *framework.Path {
}
}

func (b *backend) pathRecord() *framework.Path {
return &framework.Path{
Pattern: pathPatternRecordAsPathParam,
Fields: map[string]*framework.FieldSchema{
keyRecordUid: {
Type: framework.TypeString,
Description: descRecordUid,
Required: true,
},
},
Operations: map[logical.Operation]framework.OperationHandler{
logical.ReadOperation: &framework.PathOperation{
Callback: withFieldValidator(b.pathRecordRead),
},
logical.DeleteOperation: &framework.PathOperation{
Callback: withFieldValidator(b.pathRecordDelete),
},
},
ExistenceCheck: b.recordExistenceCheck,
HelpSynopsis: pathRecordHelpSyn,
HelpDescription: pathRecordHelpDesc,
}
}

func (b *backend) pathRecords() *framework.Path {
return &framework.Path{
Pattern: pathPatternRecord,
Expand Down Expand Up @@ -408,6 +435,10 @@ func (b *backend) pathRecordCreate(ctx context.Context, req *logical.Request, d
}

func folderExists(sm *core.SecretsManager, uid string) (bool, error) {
if uid == "" {
return false, nil
}

records, err := sm.GetSecrets([]string{})
if err != nil {
return false, err
Expand Down

0 comments on commit 5739897

Please sign in to comment.