Skip to content

Commit

Permalink
Merge pull request #133 from ycliuhw/user-secrets
Browse files Browse the repository at this point in the history
Add auto-prune support;
  • Loading branch information
ycliuhw authored Oct 9, 2023
2 parents ef93a61 + a1c3955 commit 75c6e47
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1500,6 +1500,7 @@ func (s *ModelSerializationSuite) TestSecrets(c *gc.C) {
c.Assert(secret.Description(), gc.Equals, secretArgs.Description)
c.Assert(secret.Label(), gc.Equals, secretArgs.Label)
c.Assert(secret.RotatePolicy(), gc.Equals, secretArgs.RotatePolicy)
c.Assert(secret.AutoPrune(), gc.Equals, secretArgs.AutoPrune)
owner, err := secret.Owner()
c.Assert(err, jc.ErrorIsNil)
c.Assert(owner.String(), gc.Equals, secretArgs.Owner.String())
Expand Down
12 changes: 12 additions & 0 deletions secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Secret interface {
Description() string
Label() string
RotatePolicy() string
AutoPrune() bool
Owner() (names.Tag, error)
Created() time.Time
Updated() time.Time
Expand Down Expand Up @@ -49,6 +50,7 @@ type secret struct {
Label_ string `yaml:"label"`
RotatePolicy_ string `yaml:"rotate-policy,omitempty"`
Owner_ string `yaml:"owner"`
AutoPrune_ bool `yaml:"auto-prune"`
Created_ time.Time `yaml:"create-time"`
Updated_ time.Time `yaml:"update-time"`
Revisions_ []*secretRevision `yaml:"revisions"`
Expand Down Expand Up @@ -136,6 +138,11 @@ func (i *secret) RotatePolicy() string {
return i.RotatePolicy_
}

// AutoPrune implements Secret.
func (i *secret) AutoPrune() bool {
return i.AutoPrune_
}

// Owner implements Secret.
func (i *secret) Owner() (names.Tag, error) {
if i.Owner_ == "" {
Expand Down Expand Up @@ -227,6 +234,7 @@ type SecretArgs struct {
RemoteConsumers []SecretRemoteConsumerArgs

NextRotateTime *time.Time
AutoPrune bool
}

func newSecret(args SecretArgs) *secret {
Expand All @@ -236,6 +244,7 @@ func newSecret(args SecretArgs) *secret {
Description_: args.Description,
Label_: args.Label,
RotatePolicy_: args.RotatePolicy,
AutoPrune_: args.AutoPrune,
Created_: args.Created.UTC(),
Updated_: args.Updated.UTC(),
ACL_: newSecretAccess(args.ACL),
Expand Down Expand Up @@ -328,6 +337,7 @@ func secretV1Fields() (schema.Fields, schema.Defaults) {
"description": schema.String(),
"label": schema.String(),
"rotate-policy": schema.String(),
"auto-prune": schema.Bool(),
"owner": schema.String(),
"create-time": schema.Time(),
"update-time": schema.Time(),
Expand All @@ -340,6 +350,7 @@ func secretV1Fields() (schema.Fields, schema.Defaults) {
// Some values don't have to be there.
defaults := schema.Defaults{
"rotate-policy": schema.Omit,
"auto-prune": schema.Omit,
"next-rotate-time": schema.Omit,
"consumers": schema.Omit,
"remote-consumers": schema.Omit,
Expand All @@ -362,6 +373,7 @@ func importSecret(source map[string]interface{}, importVersion int, fieldFunc fu
Description_: valid["description"].(string),
Label_: valid["label"].(string),
RotatePolicy_: valid["rotate-policy"].(string),
AutoPrune_: valid["auto-prune"].(bool),
Owner_: valid["owner"].(string),
Created_: valid["create-time"].(time.Time).UTC(),
Updated_: valid["update-time"].(time.Time).UTC(),
Expand Down
10 changes: 10 additions & 0 deletions secrets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func testSecretArgs() SecretArgs {
Description: "a secret",
Label: "secret label",
RotatePolicy: "hourly",
AutoPrune: true,
Owner: names.NewApplicationTag("postgresql"),
Created: created,
Updated: updated,
Expand Down Expand Up @@ -120,6 +121,7 @@ func (s *SecretsSerializationSuite) TestNewSecret(c *gc.C) {
c.Check(secret.Description(), gc.Equals, "a secret")
c.Check(secret.Label(), gc.Equals, "secret label")
c.Check(secret.RotatePolicy(), gc.Equals, "hourly")
c.Check(secret.AutoPrune(), jc.IsTrue)
c.Check(secret.Created(), jc.DeepEquals, args.Created)
c.Check(secret.Updated(), jc.DeepEquals, args.Updated)
c.Check(secret.NextRotateTime(), jc.DeepEquals, args.NextRotateTime)
Expand Down Expand Up @@ -168,6 +170,14 @@ func (s *SecretsSerializationSuite) TestNewSecretNoRotatePolicy(c *gc.C) {
c.Assert(secret.RotatePolicy(), gc.Equals, "")
}

func (s *SecretsSerializationSuite) TestNewSecretNoAutoPrune(c *gc.C) {
args := testSecretArgs()
args.AutoPrune = false
secret := newSecret(args)

c.Assert(secret.AutoPrune(), jc.IsFalse)
}

func (s *SecretsSerializationSuite) TestNewSecretNoNextRotateTime(c *gc.C) {
args := testSecretArgs()
args.NextRotateTime = nil
Expand Down

0 comments on commit 75c6e47

Please sign in to comment.