Skip to content

Commit

Permalink
Activation flag tests
Browse files Browse the repository at this point in the history
  • Loading branch information
biazmoreira committed Jan 6, 2025
1 parent d3f55ba commit 48485ad
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 426 deletions.
6 changes: 6 additions & 0 deletions helper/activationflags/activation_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ type FeatureActivationFlags struct {
activationFlags map[string]bool
}

func NewFeatureActivationFlags() *FeatureActivationFlags {
return &FeatureActivationFlags{
activationFlags: map[string]bool{},
}
}

func (f *FeatureActivationFlags) Initialize(ctx context.Context, storage logical.Storage) error {
f.activationFlagsLock.Lock()
defer f.activationFlagsLock.Unlock()
Expand Down
6 changes: 1 addition & 5 deletions vault/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -1453,14 +1453,10 @@ func (c *Core) configureLogicalBackends(backends map[string]logical.Factory, log
c.AddLogger(sysBackendLogger)
b := NewSystemBackend(c, sysBackendLogger, config)

err := c.FeatureActivationFlags.Initialize(ctx, b.Core.systemBarrierView)
if err != nil {
return nil, fmt.Errorf("failed to initialize activation flags: %w", err)
}

if err := b.Setup(ctx, config); err != nil {
return nil, err
}

return b, nil
}

Expand Down
3 changes: 3 additions & 0 deletions vault/core_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"

"github.com/hashicorp/go-hclog"
"github.com/hashicorp/vault/helper/activationflags"
"github.com/hashicorp/vault/helper/namespace"
"github.com/hashicorp/vault/limits"
"github.com/hashicorp/vault/sdk/helper/license"
Expand Down Expand Up @@ -59,6 +60,8 @@ func coreInit(c *Core, conf *CoreConfig) error {
c.physical = physical.NewStorageEncoding(c.physical)
}

c.FeatureActivationFlags = activationflags.NewFeatureActivationFlags()

return nil
}

Expand Down
19 changes: 17 additions & 2 deletions vault/logical_system_activation_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (
)

const (
EnvHVDTierSecretsSync = "VAULT_HVD_ADMIN_SECRETS_SYNC"

paramFeatureName = "feature_name"
descFeatureName = "The name of the feature to be activated."
summaryList = "Returns the available and activated activation-flagged features."
Expand Down Expand Up @@ -66,6 +64,23 @@ func (b *SystemBackend) activationFlagsPaths() []*framework.Path {
HelpSynopsis: helpSynopsis,
HelpDescription: helpDescription,
},
{
Pattern: fmt.Sprintf("%s/%s/%s", prefixActivationFlags, "activation-test", verbActivationFlagsActivate),
DisplayAttrs: &framework.DisplayAttributes{
OperationPrefix: prefixActivationFlags,
OperationVerb: verbActivationFlagsActivate,
},
Operations: map[logical.Operation]framework.OperationHandler{
logical.UpdateOperation: &framework.PathOperation{
Callback: b.handleActivationFlagsActivate,
ForwardPerformanceSecondary: true,
ForwardPerformanceStandby: true,
Summary: summaryUpdate,
},
},
HelpSynopsis: helpSynopsis,
HelpDescription: helpDescription,
},
}
}

Expand Down
Loading

0 comments on commit 48485ad

Please sign in to comment.