From 271069d63e9cceef2fd3d95e3bbdc58f9f39f848 Mon Sep 17 00:00:00 2001 From: "Mark St.Godard" Date: Thu, 18 Jun 2015 17:57:48 -0700 Subject: [PATCH] Backwards compatibility for getCurrentOrg and getCurrentSpace getCurrentOrg returns Organization getOrg returns OrganizationDetails getOrgs returns OrganizationSummary getCurrentSpace returns Space getSpace returns SpaceDetails getSpaces returns SpaceSummary [#97159474] Signed-off-by: Andrew Edgar --- cf/command_registry/dependency.go | 4 +-- cf/commands/organization/org.go | 2 +- cf/commands/organization/org_test.go | 4 +-- cf/commands/space/space.go | 2 +- cf/commands/space/space_test.go | 4 +-- plugin/cli_connection.go | 24 ++++++++-------- plugin/fakes/fake_cli_connection.go | 40 +++++++++++++-------------- plugin/models/organization.go | 9 +++--- plugin/models/organization_details.go | 10 +++++++ plugin/models/space.go | 6 ---- plugin/models/space_details.go | 11 ++++++++ plugin/plugin.go | 8 +++--- plugin/rpc/cli_rpc_server.go | 13 +++++++-- plugin/rpc/cli_rpc_server_test.go | 13 +++++++-- 14 files changed, 90 insertions(+), 60 deletions(-) create mode 100644 plugin/models/organization_details.go create mode 100644 plugin/models/space_details.go diff --git a/cf/command_registry/dependency.go b/cf/command_registry/dependency.go index 8a75a108b32..f41a66d58d7 100644 --- a/cf/command_registry/dependency.go +++ b/cf/command_registry/dependency.go @@ -33,9 +33,9 @@ type pluginModels struct { Application *plugin_models.Application AppsSummary *[]plugin_models.ApplicationSummary Organizations *[]plugin_models.OrganizationSummary - Organization *plugin_models.Organization + Organization *plugin_models.OrganizationDetails Spaces *[]plugin_models.SpaceSummary - Space *plugin_models.Space + Space *plugin_models.SpaceDetails Users *[]plugin_models.User ServiceInstances *[]plugin_models.ServiceInstance } diff --git a/cf/commands/organization/org.go b/cf/commands/organization/org.go index 5249dce65c1..96fc9097dd4 100644 --- a/cf/commands/organization/org.go +++ b/cf/commands/organization/org.go @@ -20,7 +20,7 @@ type ShowOrg struct { ui terminal.UI config core_config.Reader orgReq requirements.OrganizationRequirement - pluginModel *plugin_models.Organization + pluginModel *plugin_models.OrganizationDetails pluginCall bool } diff --git a/cf/commands/organization/org_test.go b/cf/commands/organization/org_test.go index f9bf243c8e8..446b7cf5780 100644 --- a/cf/commands/organization/org_test.go +++ b/cf/commands/organization/org_test.go @@ -140,10 +140,10 @@ var _ = Describe("org command", func() { Context("when invoked by a plugin", func() { var ( - pluginModel plugin_models.Organization + pluginModel plugin_models.OrganizationDetails ) BeforeEach(func() { - pluginModel = plugin_models.Organization{} + pluginModel = plugin_models.OrganizationDetails{} deps.PluginModels.Organization = &pluginModel updateCommandDependency(true) }) diff --git a/cf/commands/space/space.go b/cf/commands/space/space.go index bd8fe0595ec..c465b58820f 100644 --- a/cf/commands/space/space.go +++ b/cf/commands/space/space.go @@ -23,7 +23,7 @@ type ShowSpace struct { config core_config.Reader spaceReq requirements.SpaceRequirement quotaRepo space_quotas.SpaceQuotaRepository - pluginModel *plugin_models.Space + pluginModel *plugin_models.SpaceDetails pluginCall bool } diff --git a/cf/commands/space/space_test.go b/cf/commands/space/space_test.go index 3ea6f2de87a..dd4c0a37212 100644 --- a/cf/commands/space/space_test.go +++ b/cf/commands/space/space_test.go @@ -194,10 +194,10 @@ var _ = Describe("space command", func() { Context("When called as a plugin", func() { var ( - pluginModel plugin_models.Space + pluginModel plugin_models.SpaceDetails ) BeforeEach(func() { - pluginModel = plugin_models.Space{} + pluginModel = plugin_models.SpaceDetails{} deps.PluginModels.Space = &pluginModel updateCommandDependency(true) }) diff --git a/plugin/cli_connection.go b/plugin/cli_connection.go index d7c1db37a27..82c464066b6 100644 --- a/plugin/cli_connection.go +++ b/plugin/cli_connection.go @@ -98,25 +98,25 @@ func (cliConnection *cliConnection) pingCLI() { } } -func (cliConnection *cliConnection) GetCurrentOrg() (plugin_models.OrganizationSummary, error) { +func (cliConnection *cliConnection) GetCurrentOrg() (plugin_models.Organization, error) { client, err := rpc.Dial("tcp", "127.0.0.1:"+cliConnection.cliServerPort) if err != nil { - return plugin_models.OrganizationSummary{}, err + return plugin_models.Organization{}, err } - var result plugin_models.OrganizationSummary + var result plugin_models.Organization err = client.Call("CliRpcCmd.GetCurrentOrg", "", &result) return result, err } -func (cliConnection *cliConnection) GetCurrentSpace() (plugin_models.SpaceSummary, error) { +func (cliConnection *cliConnection) GetCurrentSpace() (plugin_models.Space, error) { client, err := rpc.Dial("tcp", "127.0.0.1:"+cliConnection.cliServerPort) if err != nil { - return plugin_models.SpaceSummary{}, err + return plugin_models.Space{}, err } - var result plugin_models.SpaceSummary + var result plugin_models.Space err = client.Call("CliRpcCmd.GetCurrentSpace", "", &result) return result, err @@ -314,13 +314,13 @@ func (cliConnection *cliConnection) GetOrgs() ([]plugin_models.OrganizationSumma return result, err } -func (cliConnection *cliConnection) GetSpaces() ([]plugin_models.Space, error) { +func (cliConnection *cliConnection) GetSpaces() ([]plugin_models.SpaceSummary, error) { client, err := rpc.Dial("tcp", "127.0.0.1:"+cliConnection.cliServerPort) if err != nil { - return []plugin_models.Space{}, err + return []plugin_models.SpaceSummary{}, err } - var result []plugin_models.Space + var result []plugin_models.SpaceSummary err = client.Call("CliRpcCmd.GetSpaces", "", &result) return result, err @@ -366,13 +366,13 @@ func (cliConnection *cliConnection) GetSpaceUsers(orgName string, spaceName stri return result, err } -func (cliConnection *cliConnection) GetOrg(orgName string) (plugin_models.Organization, error) { +func (cliConnection *cliConnection) GetOrg(orgName string) (plugin_models.OrganizationDetails, error) { client, err := rpc.Dial("tcp", "127.0.0.1:"+cliConnection.cliServerPort) if err != nil { - return plugin_models.Organization{}, err + return plugin_models.OrganizationDetails{}, err } - var result plugin_models.Organization + var result plugin_models.OrganizationDetails err = client.Call("CliRpcCmd.GetOrg", orgName, &result) return result, err diff --git a/plugin/fakes/fake_cli_connection.go b/plugin/fakes/fake_cli_connection.go index 6f03650ae3d..43670e8e7e6 100644 --- a/plugin/fakes/fake_cli_connection.go +++ b/plugin/fakes/fake_cli_connection.go @@ -27,18 +27,18 @@ type FakeCliConnection struct { result1 []string result2 error } - GetCurrentOrgStub func() (plugin_models.OrganizationSummary, error) + GetCurrentOrgStub func() (plugin_models.Organization, error) getCurrentOrgMutex sync.RWMutex getCurrentOrgArgsForCall []struct{} getCurrentOrgReturns struct { - result1 plugin_models.OrganizationSummary + result1 plugin_models.Organization result2 error } - GetCurrentSpaceStub func() (plugin_models.SpaceSummary, error) + GetCurrentSpaceStub func() (plugin_models.Space, error) getCurrentSpaceMutex sync.RWMutex getCurrentSpaceArgsForCall []struct{} getCurrentSpaceReturns struct { - result1 plugin_models.SpaceSummary + result1 plugin_models.Space result2 error } UsernameStub func() (string, error) @@ -155,11 +155,11 @@ type FakeCliConnection struct { result1 []plugin_models.OrganizationSummary result2 error } - GetSpacesStub func() ([]plugin_models.Space, error) + GetSpacesStub func() ([]plugin_models.SpaceSummary, error) getSpacesMutex sync.RWMutex getSpacesArgsForCall []struct{} getSpacesReturns struct { - result1 []plugin_models.Space + result1 []plugin_models.SpaceSummary result2 error } GetOrgUsersStub func(string, ...string) ([]plugin_models.User, error) @@ -189,13 +189,13 @@ type FakeCliConnection struct { result1 []plugin_models.ServiceInstance result2 error } - GetOrgStub func(string) (plugin_models.Organization, error) + GetOrgStub func(string) (plugin_models.OrganizationDetails, error) getOrgMutex sync.RWMutex getOrgArgsForCall []struct { arg1 string } getOrgReturns struct { - result1 plugin_models.Organization + result1 plugin_models.OrganizationDetails result2 error } } @@ -266,7 +266,7 @@ func (fake *FakeCliConnection) CliCommandReturns(result1 []string, result2 error }{result1, result2} } -func (fake *FakeCliConnection) GetCurrentOrg() (plugin_models.OrganizationSummary, error) { +func (fake *FakeCliConnection) GetCurrentOrg() (plugin_models.Organization, error) { fake.getCurrentOrgMutex.Lock() fake.getCurrentOrgArgsForCall = append(fake.getCurrentOrgArgsForCall, struct{}{}) fake.getCurrentOrgMutex.Unlock() @@ -283,15 +283,15 @@ func (fake *FakeCliConnection) GetCurrentOrgCallCount() int { return len(fake.getCurrentOrgArgsForCall) } -func (fake *FakeCliConnection) GetCurrentOrgReturns(result1 plugin_models.OrganizationSummary, result2 error) { +func (fake *FakeCliConnection) GetCurrentOrgReturns(result1 plugin_models.Organization, result2 error) { fake.GetCurrentOrgStub = nil fake.getCurrentOrgReturns = struct { - result1 plugin_models.OrganizationSummary + result1 plugin_models.Organization result2 error }{result1, result2} } -func (fake *FakeCliConnection) GetCurrentSpace() (plugin_models.SpaceSummary, error) { +func (fake *FakeCliConnection) GetCurrentSpace() (plugin_models.Space, error) { fake.getCurrentSpaceMutex.Lock() fake.getCurrentSpaceArgsForCall = append(fake.getCurrentSpaceArgsForCall, struct{}{}) fake.getCurrentSpaceMutex.Unlock() @@ -308,10 +308,10 @@ func (fake *FakeCliConnection) GetCurrentSpaceCallCount() int { return len(fake.getCurrentSpaceArgsForCall) } -func (fake *FakeCliConnection) GetCurrentSpaceReturns(result1 plugin_models.SpaceSummary, result2 error) { +func (fake *FakeCliConnection) GetCurrentSpaceReturns(result1 plugin_models.Space, result2 error) { fake.GetCurrentSpaceStub = nil fake.getCurrentSpaceReturns = struct { - result1 plugin_models.SpaceSummary + result1 plugin_models.Space result2 error }{result1, result2} } @@ -724,7 +724,7 @@ func (fake *FakeCliConnection) GetOrgsReturns(result1 []plugin_models.Organizati }{result1, result2} } -func (fake *FakeCliConnection) GetSpaces() ([]plugin_models.Space, error) { +func (fake *FakeCliConnection) GetSpaces() ([]plugin_models.SpaceSummary, error) { fake.getSpacesMutex.Lock() fake.getSpacesArgsForCall = append(fake.getSpacesArgsForCall, struct{}{}) fake.getSpacesMutex.Unlock() @@ -741,10 +741,10 @@ func (fake *FakeCliConnection) GetSpacesCallCount() int { return len(fake.getSpacesArgsForCall) } -func (fake *FakeCliConnection) GetSpacesReturns(result1 []plugin_models.Space, result2 error) { +func (fake *FakeCliConnection) GetSpacesReturns(result1 []plugin_models.SpaceSummary, result2 error) { fake.GetSpacesStub = nil fake.getSpacesReturns = struct { - result1 []plugin_models.Space + result1 []plugin_models.SpaceSummary result2 error }{result1, result2} } @@ -842,7 +842,7 @@ func (fake *FakeCliConnection) GetServicesReturns(result1 []plugin_models.Servic }{result1, result2} } -func (fake *FakeCliConnection) GetOrg(arg1 string) (plugin_models.Organization, error) { +func (fake *FakeCliConnection) GetOrg(arg1 string) (plugin_models.OrganizationDetails, error) { fake.getOrgMutex.Lock() fake.getOrgArgsForCall = append(fake.getOrgArgsForCall, struct { arg1 string @@ -867,10 +867,10 @@ func (fake *FakeCliConnection) GetOrgArgsForCall(i int) string { return fake.getOrgArgsForCall[i].arg1 } -func (fake *FakeCliConnection) GetOrgReturns(result1 plugin_models.Organization, result2 error) { +func (fake *FakeCliConnection) GetOrgReturns(result1 plugin_models.OrganizationDetails, result2 error) { fake.GetOrgStub = nil fake.getOrgReturns = struct { - result1 plugin_models.Organization + result1 plugin_models.OrganizationDetails result2 error }{result1, result2} } diff --git a/plugin/models/organization.go b/plugin/models/organization.go index 2c8d61ac996..1b109e80e3f 100644 --- a/plugin/models/organization.go +++ b/plugin/models/organization.go @@ -1,10 +1,11 @@ package plugin_models -type Organization struct { +type OrganizationFields struct { Guid string Name string QuotaDefinition QuotaFields - Spaces []SpaceFields - Domains []DomainFields - SpaceQuotas []SpaceQuotaFields +} + +type Organization struct { + OrganizationFields } diff --git a/plugin/models/organization_details.go b/plugin/models/organization_details.go new file mode 100644 index 00000000000..f31ad00f85b --- /dev/null +++ b/plugin/models/organization_details.go @@ -0,0 +1,10 @@ +package plugin_models + +type OrganizationDetails struct { + Guid string + Name string + QuotaDefinition QuotaFields + Spaces []SpaceFields + Domains []DomainFields + SpaceQuotas []SpaceQuotaFields +} diff --git a/plugin/models/space.go b/plugin/models/space.go index c74dafd3f26..87968f15473 100644 --- a/plugin/models/space.go +++ b/plugin/models/space.go @@ -7,10 +7,4 @@ type SpaceFields struct { type Space struct { SpaceFields - Organization OrganizationSummary - Applications []ApplicationSummary - //ServiceInstances []ServiceInstances - Domains []DomainFields - SecurityGroups []SecurityGroupFields - SpaceQuotaGuid string } diff --git a/plugin/models/space_details.go b/plugin/models/space_details.go new file mode 100644 index 00000000000..bc47b853fd4 --- /dev/null +++ b/plugin/models/space_details.go @@ -0,0 +1,11 @@ +package plugin_models + +type SpaceDetails struct { + SpaceFields + Organization OrganizationSummary + Applications []ApplicationSummary + //ServiceInstances []ServiceInstances + Domains []DomainFields + SecurityGroups []SecurityGroupFields + SpaceQuotaGuid string +} diff --git a/plugin/plugin.go b/plugin/plugin.go index fbc6dde6d90..9a19c6d91be 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -16,8 +16,8 @@ type Plugin interface { type CliConnection interface { CliCommandWithoutTerminalOutput(args ...string) ([]string, error) CliCommand(args ...string) ([]string, error) - GetCurrentOrg() (plugin_models.OrganizationSummary, error) - GetCurrentSpace() (plugin_models.SpaceSummary, error) + GetCurrentOrg() (plugin_models.Organization, error) + GetCurrentSpace() (plugin_models.Space, error) Username() (string, error) UserGuid() (string, error) UserEmail() (string, error) @@ -34,11 +34,11 @@ type CliConnection interface { GetApp(string) (plugin_models.Application, error) GetApps() ([]plugin_models.ApplicationSummary, error) GetOrgs() ([]plugin_models.OrganizationSummary, error) - GetSpaces() ([]plugin_models.Space, error) + GetSpaces() ([]plugin_models.SpaceSummary, error) GetOrgUsers(string, ...string) ([]plugin_models.User, error) GetSpaceUsers(string, string) ([]plugin_models.User, error) GetServices() ([]plugin_models.ServiceInstance, error) - GetOrg(string) (plugin_models.Organization, error) + GetOrg(string) (plugin_models.OrganizationDetails, error) } type VersionType struct { diff --git a/plugin/rpc/cli_rpc_server.go b/plugin/rpc/cli_rpc_server.go index 8f7bfe42102..3386c1aea3d 100644 --- a/plugin/rpc/cli_rpc_server.go +++ b/plugin/rpc/cli_rpc_server.go @@ -150,14 +150,21 @@ func (cmd *CliRpcCmd) GetOutputAndReset(args bool, retVal *[]string) error { return nil } -func (cmd *CliRpcCmd) GetCurrentOrg(args string, retVal *plugin_models.OrganizationSummary) error { +func (cmd *CliRpcCmd) GetCurrentOrg(args string, retVal *plugin_models.Organization) error { retVal.Name = cmd.cliConfig.OrganizationFields().Name retVal.Guid = cmd.cliConfig.OrganizationFields().Guid + retVal.QuotaDefinition.Guid = cmd.cliConfig.OrganizationFields().QuotaDefinition.Guid + retVal.QuotaDefinition.Name = cmd.cliConfig.OrganizationFields().QuotaDefinition.Name + retVal.QuotaDefinition.MemoryLimit = cmd.cliConfig.OrganizationFields().QuotaDefinition.MemoryLimit + retVal.QuotaDefinition.InstanceMemoryLimit = cmd.cliConfig.OrganizationFields().QuotaDefinition.InstanceMemoryLimit + retVal.QuotaDefinition.RoutesLimit = cmd.cliConfig.OrganizationFields().QuotaDefinition.RoutesLimit + retVal.QuotaDefinition.ServicesLimit = cmd.cliConfig.OrganizationFields().QuotaDefinition.ServicesLimit + retVal.QuotaDefinition.NonBasicServicesAllowed = cmd.cliConfig.OrganizationFields().QuotaDefinition.NonBasicServicesAllowed return nil } -func (cmd *CliRpcCmd) GetCurrentSpace(args string, retVal *plugin_models.SpaceSummary) error { +func (cmd *CliRpcCmd) GetCurrentSpace(args string, retVal *plugin_models.Space) error { retVal.Name = cmd.cliConfig.SpaceFields().Name retVal.Guid = cmd.cliConfig.SpaceFields().Guid @@ -368,7 +375,7 @@ func (cmd *CliRpcCmd) GetSpaceUsers(args []string, retVal *[]plugin_models.User) return cmd.newCmdRunner.Command(append([]string{"space-users"}, args...), deps, true) } -func (cmd *CliRpcCmd) GetOrg(orgName string, retVal *plugin_models.Organization) error { +func (cmd *CliRpcCmd) GetOrg(orgName string, retVal *plugin_models.OrganizationDetails) error { defer func() { recover() }() diff --git a/plugin/rpc/cli_rpc_server_test.go b/plugin/rpc/cli_rpc_server_test.go index 4702055c7cc..7b26b13b16b 100644 --- a/plugin/rpc/cli_rpc_server_test.go +++ b/plugin/rpc/cli_rpc_server_test.go @@ -254,7 +254,7 @@ var _ = Describe("Server", func() { }) It("calls GetOrg() with 'my-org' as argument", func() { - result := plugin_models.Organization{} + result := plugin_models.OrganizationDetails{} err = client.Call("CliRpcCmd.GetOrg", "my-org", &result) Expect(err).ToNot(HaveOccurred()) @@ -288,7 +288,7 @@ var _ = Describe("Server", func() { }) It("calls GetServices() ", func() { - result := []plugin_models.Space{} + result := []plugin_models.ServiceInstance{} err = client.Call("CliRpcCmd.GetServices", "", &result) Expect(err).ToNot(HaveOccurred()) @@ -447,6 +447,13 @@ var _ = Describe("Server", func() { Expect(err).ToNot(HaveOccurred()) Expect(org.Name).To(Equal("test-org")) Expect(org.Guid).To(Equal("test-guid")) + Expect(org.QuotaDefinition.Guid).To(Equal("guid123")) + Expect(org.QuotaDefinition.Name).To(Equal("quota123")) + Expect(org.QuotaDefinition.MemoryLimit).To(Equal(int64(128))) + Expect(org.QuotaDefinition.InstanceMemoryLimit).To(Equal(int64(16))) + Expect(org.QuotaDefinition.RoutesLimit).To(Equal(5)) + Expect(org.QuotaDefinition.ServicesLimit).To(Equal(6)) + Expect(org.QuotaDefinition.NonBasicServicesAllowed).To(BeTrue()) }) }) @@ -468,7 +475,7 @@ var _ = Describe("Server", func() { client, err = rpc.Dial("tcp", "127.0.0.1:"+rpcService.Port()) Expect(err).ToNot(HaveOccurred()) - var space plugin_models.SpaceSummary + var space plugin_models.Space err = client.Call("CliRpcCmd.GetCurrentSpace", "", &space) Expect(err).ToNot(HaveOccurred())