diff --git a/model.go b/model.go index 9e400f4..ee9f663 100644 --- a/model.go +++ b/model.go @@ -944,7 +944,7 @@ func (m *model) AddRemoteApplication(args RemoteApplicationArgs) RemoteApplicati func (m *model) setRemoteApplications(appList []*remoteApplication) { m.RemoteApplications_ = remoteApplications{ - Version: 2, + Version: 3, RemoteApplications: appList, } } diff --git a/model_test.go b/model_test.go index 2274f33..eb5a9a6 100644 --- a/model_test.go +++ b/model_test.go @@ -828,6 +828,7 @@ func (s *ModelSerializationSuite) TestSerializesRemoteApplications(c *gc.C) { URL: "other.mysql", SourceModel: names.NewModelTag("some-model"), IsConsumerProxy: true, + ConsumeVersion: 666, }) rapp.AddEndpoint(RemoteEndpointArgs{ Name: "db", @@ -848,7 +849,8 @@ func (s *ModelSerializationSuite) TestSerializesRemoteApplications(c *gc.C) { expected := ` remote-applications: -- endpoints: +- consume-version: 666 + endpoints: endpoints: - interface: mysql name: db @@ -868,7 +870,7 @@ remote-applications: value: running version: 2 url: other.mysql -version: 2 +version: 3 `[1:] c.Assert(string(bytes), gc.Equals, expected) } diff --git a/remoteapplication.go b/remoteapplication.go index d4ec5bd..1c0f7b5 100644 --- a/remoteapplication.go +++ b/remoteapplication.go @@ -20,6 +20,7 @@ type RemoteApplication interface { URL() string SourceModelTag() names.ModelTag IsConsumerProxy() bool + ConsumeVersion() int Macaroon() string Endpoints() []RemoteEndpoint @@ -41,6 +42,7 @@ type remoteApplication struct { OfferUUID_ string `yaml:"offer-uuid"` URL_ string `yaml:"url"` SourceModelUUID_ string `yaml:"source-model-uuid"` + ConsumeVersion_ int `yaml:"consume-version,omitempty"` Macaroon_ string `yaml:"macaroon,omitempty"` Endpoints_ remoteEndpoints `yaml:"endpoints,omitempty"` IsConsumerProxy_ bool `yaml:"is-consumer-proxy,omitempty"` @@ -57,6 +59,7 @@ type RemoteApplicationArgs struct { URL string SourceModel names.ModelTag IsConsumerProxy bool + ConsumeVersion int Macaroon string Bindings map[string]string } @@ -68,6 +71,7 @@ func newRemoteApplication(args RemoteApplicationArgs) *remoteApplication { URL_: args.URL, SourceModelUUID_: args.SourceModel.Id(), IsConsumerProxy_: args.IsConsumerProxy, + ConsumeVersion_: args.ConsumeVersion, Macaroon_: args.Macaroon, Bindings_: args.Bindings, } @@ -106,6 +110,11 @@ func (a *remoteApplication) IsConsumerProxy() bool { return a.IsConsumerProxy_ } +// ConsumeVersion implements RemoteApplication. +func (a *remoteApplication) ConsumeVersion() int { + return a.ConsumeVersion_ +} + // Macaroon (RemoteApplication) returns the macaroon // that authorises access to the remote application. func (a *remoteApplication) Macaroon() string { @@ -218,6 +227,7 @@ func importRemoteApplicationList(sourceList []interface{}, checker schema.Checke var remoteApplicationFieldsFuncs = map[int]fieldsFunc{ 1: remoteApplicationV1Fields, 2: remoteApplicationV2Fields, + 3: remoteApplicationV3Fields, } func newRemoteApplicationFromValid(valid map[string]interface{}, version int) (*remoteApplication, error) { @@ -262,6 +272,15 @@ func newRemoteApplicationFromValid(valid map[string]interface{}, version int) (* if bindings, ok := valid["bindings"]; ok { result.Bindings_ = convertToStringMap(bindings) } + + if version < 3 { + result.ConsumeVersion_ = 1 + } else { + v, ok := valid["consume-version"].(int64) + if ok { + result.ConsumeVersion_ = int(v) + } + } return result, nil } @@ -294,3 +313,10 @@ func remoteApplicationV2Fields() (schema.Fields, schema.Defaults) { defaults["macaroon"] = schema.Omit return fields, defaults } + +func remoteApplicationV3Fields() (schema.Fields, schema.Defaults) { + fields, defaults := remoteApplicationV2Fields() + fields["consume-version"] = schema.Int() + defaults["consume-version"] = 0 + return fields, defaults +} diff --git a/remoteapplication_test.go b/remoteapplication_test.go index 78590fa..1409cc1 100644 --- a/remoteapplication_test.go +++ b/remoteapplication_test.go @@ -54,6 +54,7 @@ func minimalRemoteApplicationMapWithoutStatus() map[interface{}]interface{} { "url": "http://a.url", "source-model-uuid": "abcd-1234", "is-consumer-proxy": true, + "consume-version": 666, "endpoints": map[interface{}]interface{}{ "version": 1, "endpoints": []interface{}{map[interface{}]interface{}{ @@ -114,6 +115,7 @@ func minimalRemoteApplicationWithoutStatus() *remoteApplication { URL: "http://a.url", SourceModel: names.NewModelTag("abcd-1234"), IsConsumerProxy: true, + ConsumeVersion: 666, Bindings: map[string]string{"lana": "private"}, }) a.AddEndpoint(RemoteEndpointArgs{ @@ -241,20 +243,31 @@ func (*RemoteApplicationSerializationSuite) TestMinimalMatchesWithoutStatus(c *g func (s *RemoteApplicationSerializationSuite) TestRoundTripVersion1(c *gc.C) { rIn := minimalRemoteApplication() + rIn.ConsumeVersion_ = 0 rOut := s.exportImport(c, 1, rIn) + rIn.ConsumeVersion_ = 1 c.Assert(rOut, jc.DeepEquals, rIn) } func (s *RemoteApplicationSerializationSuite) TestRoundTripVersion2(c *gc.C) { rIn := minimalRemoteApplication() + rIn.ConsumeVersion_ = 0 rIn.Macaroon_ = "mac" rOut := s.exportImport(c, 2, rIn) + rIn.ConsumeVersion_ = 1 + c.Assert(rOut, jc.DeepEquals, rIn) +} + +func (s *RemoteApplicationSerializationSuite) TestRoundTripVersion3(c *gc.C) { + rIn := minimalRemoteApplication() + rIn.Macaroon_ = "mac" + rOut := s.exportImport(c, 3, rIn) c.Assert(rOut, jc.DeepEquals, rIn) } func (s *RemoteApplicationSerializationSuite) TestRoundTripWithoutStatus(c *gc.C) { rIn := minimalRemoteApplicationWithoutStatus() - rOut := s.exportImport(c, 1, rIn) + rOut := s.exportImport(c, 3, rIn) c.Assert(rOut, jc.DeepEquals, rIn) }