diff --git a/model_test.go b/model_test.go index d468468..82d16f6 100644 --- a/model_test.go +++ b/model_test.go @@ -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()) diff --git a/secrets.go b/secrets.go index 6b9fb77..32f5904 100644 --- a/secrets.go +++ b/secrets.go @@ -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 @@ -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"` @@ -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_ == "" { @@ -227,6 +234,7 @@ type SecretArgs struct { RemoteConsumers []SecretRemoteConsumerArgs NextRotateTime *time.Time + AutoPrune bool } func newSecret(args SecretArgs) *secret { @@ -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), @@ -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(), @@ -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, @@ -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(), diff --git a/secrets_test.go b/secrets_test.go index 902e54a..1aac554 100644 --- a/secrets_test.go +++ b/secrets_test.go @@ -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, @@ -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) @@ -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