Skip to content

Commit

Permalink
Merge pull request #131 from ycliuhw/add-secret-backend
Browse files Browse the repository at this point in the history
[JUJU-3738] - Add secret backend name and ID for model config;
  • Loading branch information
ycliuhw authored Jun 1, 2023
2 parents e54d5fe + dd60988 commit ef93a61
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
19 changes: 16 additions & 3 deletions model.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ type Model interface {
StoragePools() []StoragePool
AddStoragePool(StoragePoolArgs) StoragePool

SecretBackendID() string

Secrets() []Secret
AddSecret(args SecretArgs) Secret

Expand Down Expand Up @@ -148,6 +150,7 @@ type ModelArgs struct {
Cloud string
CloudRegion string
PasswordHash string
SecretBackendID string
}

// NewModel returns a Model based on the args specified.
Expand All @@ -164,6 +167,7 @@ func NewModel(args ModelArgs) Model {
Cloud_: args.Cloud,
CloudRegion_: args.CloudRegion,
PasswordHash_: args.PasswordHash,
SecretBackendID_: args.SecretBackendID,
StatusHistory_: newStatusHistory(),
}
m.setUsers(nil)
Expand Down Expand Up @@ -297,8 +301,9 @@ type model struct {

RemoteApplications_ remoteApplications `yaml:"remote-applications"`

Secrets_ secrets `yaml:"secrets"`
RemoteSecrets_ remoteSecrets `yaml:"remote-secrets"`
SecretBackendID_ string `yaml:"secret-backend-id,omitempty"`
Secrets_ secrets `yaml:"secrets"`
RemoteSecrets_ remoteSecrets `yaml:"remote-secrets"`

SLA_ sla `yaml:"sla"`
MeterStatus_ meterStatus `yaml:"meter-status"`
Expand Down Expand Up @@ -899,6 +904,11 @@ func (m *model) setStoragePools(poolList []*storagepool) {
}
}

// SecretBackendID implements Model.
func (m *model) SecretBackendID() string {
return m.SecretBackendID_
}

// Secrets implements Model.
func (m *model) Secrets() []Secret {
var result []Secret
Expand Down Expand Up @@ -1605,6 +1615,8 @@ func modelV9Fields() (schema.Fields, schema.Defaults) {
func modelV10Fields() (schema.Fields, schema.Defaults) {
fields, defaults := modelV9Fields()
fields["remote-secrets"] = schema.StringMap(schema.Any())
fields["secret-backend-id"] = schema.String()
defaults["secret-backend-id"] = ""
return fields, defaults
}

Expand Down Expand Up @@ -1873,8 +1885,9 @@ func newModelFromValid(valid map[string]interface{}, importVersion int) (*model,
return nil, errors.Annotate(err, "remote secrets")
}
result.setRemoteSecrets(remoteSecrets)
}

result.SecretBackendID_ = valid["secret-backend-id"].(string)
}
return result, nil
}

Expand Down
15 changes: 15 additions & 0 deletions model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,21 @@ func (s *ModelSerializationSuite) TestStatus(c *gc.C) {
c.Check(model.Status(), jc.DeepEquals, expected)
}

func (s *ModelSerializationSuite) TestSecretBackend(c *gc.C) {
initial := s.newModel(ModelArgs{
Owner: names.NewUserTag("owner"),
SecretBackendID: "backend-id",
})
c.Assert(initial.SecretBackendID(), gc.Equals, "backend-id")

bytes, err := yaml.Marshal(initial)
c.Assert(err, jc.ErrorIsNil)

model, err := Deserialize(bytes)
c.Assert(err, jc.ErrorIsNil)
c.Assert(model.SecretBackendID(), jc.DeepEquals, "backend-id")
}

func (s *ModelSerializationSuite) TestSecrets(c *gc.C) {
initial := s.newModel(ModelArgs{Owner: names.NewUserTag("owner")})
secretArgs := testSecretArgs()
Expand Down

0 comments on commit ef93a61

Please sign in to comment.