Skip to content

Commit 529a3e1

Browse files
Samzegururajsh
andauthored
Add /v3/info endpoint (#3445) (#3469)
Also rename old info code to root since it hits "/". Co-authored-by: Shwetha Gururaj <[email protected]>
1 parent 1fa4cf9 commit 529a3e1

File tree

20 files changed

+571
-234
lines changed

20 files changed

+571
-234
lines changed

actor/v7action/cloud_controller_client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ type CloudControllerClient interface {
8888
GetEvents(query ...ccv3.Query) ([]ccv3.Event, ccv3.Warnings, error)
8989
GetFeatureFlag(featureFlagName string) (resources.FeatureFlag, ccv3.Warnings, error)
9090
GetFeatureFlags() ([]resources.FeatureFlag, ccv3.Warnings, error)
91+
GetRoot() (ccv3.Root, ccv3.Warnings, error)
9192
GetInfo() (ccv3.Info, ccv3.Warnings, error)
9293
GetIsolationSegment(guid string) (resources.IsolationSegment, ccv3.Warnings, error)
9394
GetIsolationSegmentOrganizations(isolationSegmentGUID string) ([]resources.Organization, ccv3.Warnings, error)
@@ -148,7 +149,7 @@ type CloudControllerClient interface {
148149
PollJobToEventStream(jobURL ccv3.JobURL) chan ccv3.PollJobEvent
149150
PurgeServiceOffering(serviceOfferingGUID string) (ccv3.Warnings, error)
150151
ResourceMatch(resources []ccv3.Resource) ([]ccv3.Resource, ccv3.Warnings, error)
151-
RootResponse() (ccv3.Info, ccv3.Warnings, error)
152+
RootResponse() (ccv3.Root, ccv3.Warnings, error)
152153
SetApplicationDroplet(appGUID string, dropletGUID string) (resources.Relationship, ccv3.Warnings, error)
153154
SharePrivateDomainToOrgs(domainGuid string, sharedOrgs ccv3.SharedOrgs) (ccv3.Warnings, error)
154155
ShareServiceInstanceToSpaces(serviceInstanceGUID string, spaceGUIDs []string) (resources.RelationshipList, ccv3.Warnings, error)

actor/v7action/info.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,18 @@ package v7action
22

33
import "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
44

5+
type Root ccv3.Root
56
type Info ccv3.Info
67

7-
func (actor Actor) GetRootResponse() (Info, Warnings, error) {
8+
func (actor Actor) GetRootResponse() (Root, Warnings, error) {
9+
root, warnings, err := actor.CloudControllerClient.GetRoot()
10+
if err != nil {
11+
return Root{}, Warnings(warnings), err
12+
}
13+
return Root(root), Warnings(warnings), nil
14+
}
15+
16+
func (actor Actor) GetInfoResponse() (Info, Warnings, error) {
817
info, warnings, err := actor.CloudControllerClient.GetInfo()
918
if err != nil {
1019
return Info{}, Warnings(warnings), err

actor/v7action/info_test.go

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ var _ = Describe("Info Actions", func() {
2323
})
2424

2525
Describe("GetRootResponse", func() {
26-
When("getting info is successful", func() {
26+
When("getting root is successful", func() {
2727
BeforeEach(func() {
28-
fakeCloudControllerClient.GetInfoReturns(
29-
ccv3.Info{
30-
Links: ccv3.InfoLinks{
28+
fakeCloudControllerClient.GetRootReturns(
29+
ccv3.Root{
30+
Links: ccv3.RootLinks{
3131
LogCache: resources.APILink{HREF: "some-log-cache-url"},
3232
},
3333
},
@@ -42,11 +42,58 @@ var _ = Describe("Info Actions", func() {
4242

4343
Expect(warnings).To(ConsistOf("warning-1", "warning-2"))
4444

45-
Expect(fakeCloudControllerClient.GetInfoCallCount()).To(Equal(1))
45+
Expect(fakeCloudControllerClient.GetRootCallCount()).To(Equal(1))
4646
Expect(rootInfo.Links.LogCache.HREF).To(Equal("some-log-cache-url"))
4747
})
4848
})
4949

50+
When("the cloud controller client returns an error", func() {
51+
var expectedErr error
52+
53+
BeforeEach(func() {
54+
expectedErr = errors.New("I am a CloudControllerClient Error")
55+
fakeCloudControllerClient.GetRootReturns(
56+
ccv3.Root{},
57+
ccv3.Warnings{"warning-1", "warning-2"},
58+
expectedErr,
59+
)
60+
})
61+
62+
It("returns the same error and all warnings", func() {
63+
_, warnings, err := actor.GetRootResponse()
64+
Expect(err).To(MatchError(expectedErr))
65+
Expect(warnings).To(ConsistOf("warning-1", "warning-2"))
66+
})
67+
})
68+
})
69+
70+
Describe("GetInfoResponse", func() {
71+
When("getting info is successful", func() {
72+
BeforeEach(func() {
73+
fakeCloudControllerClient.GetInfoReturns(
74+
ccv3.Info{
75+
Name: "test-name",
76+
Build: "test-build",
77+
OSBAPIVersion: "1.0",
78+
},
79+
ccv3.Warnings{"warning-1", "warning-2"},
80+
nil,
81+
)
82+
})
83+
84+
It("returns all warnings and info", func() {
85+
info, warnings, err := actor.GetInfoResponse()
86+
Expect(err).ToNot(HaveOccurred())
87+
88+
Expect(warnings).To(ConsistOf("warning-1", "warning-2"))
89+
90+
Expect(fakeCloudControllerClient.GetInfoCallCount()).To(Equal(1))
91+
Expect(info.Name).To(Equal("test-name"))
92+
Expect(info.Build).To(Equal("test-build"))
93+
Expect(info.OSBAPIVersion).To(Equal("1.0"))
94+
})
95+
})
96+
5097
When("the cloud controller client returns an error", func() {
5198
var expectedErr error
5299

@@ -60,7 +107,7 @@ var _ = Describe("Info Actions", func() {
60107
})
61108

62109
It("returns the same error and all warnings", func() {
63-
_, warnings, err := actor.GetRootResponse()
110+
_, warnings, err := actor.GetInfoResponse()
64111
Expect(err).To(MatchError(expectedErr))
65112
Expect(warnings).To(ConsistOf("warning-1", "warning-2"))
66113
})

actor/v7action/ssh.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func (actor Actor) GetSecureShellConfigurationByApplicationNameSpaceProcessTypeA
2525
) (SSHAuthentication, Warnings, error) {
2626
var allWarnings Warnings
2727

28-
rootInfo, warnings, err := actor.CloudControllerClient.GetInfo()
28+
rootInfo, warnings, err := actor.CloudControllerClient.GetRoot()
2929
allWarnings = append(allWarnings, warnings...)
3030
if err != nil {
3131
return SSHAuthentication{}, allWarnings, err

actor/v7action/ssh_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ var _ = Describe("SSH Actions", func() {
9292

9393
When("the app ssh endpoint is empty", func() {
9494
BeforeEach(func() {
95-
fakeCloudControllerClient.GetInfoReturns(ccv3.Info{
96-
Links: ccv3.InfoLinks{
95+
fakeCloudControllerClient.GetRootReturns(ccv3.Root{
96+
Links: ccv3.RootLinks{
9797
AppSSH: resources.APILink{HREF: ""},
9898
},
9999
}, nil, nil)
@@ -106,8 +106,8 @@ var _ = Describe("SSH Actions", func() {
106106

107107
When("the app ssh hostkey fingerprint is empty", func() {
108108
BeforeEach(func() {
109-
fakeCloudControllerClient.GetInfoReturns(ccv3.Info{
110-
Links: ccv3.InfoLinks{
109+
fakeCloudControllerClient.GetRootReturns(ccv3.Root{
110+
Links: ccv3.RootLinks{
111111
AppSSH: resources.APILink{HREF: "some-app-ssh-endpoint"},
112112
},
113113
}, nil, nil)
@@ -120,8 +120,8 @@ var _ = Describe("SSH Actions", func() {
120120

121121
When("ssh endpoint and fingerprint are set", func() {
122122
BeforeEach(func() {
123-
fakeCloudControllerClient.GetInfoReturns(ccv3.Info{
124-
Links: ccv3.InfoLinks{
123+
fakeCloudControllerClient.GetRootReturns(ccv3.Root{
124+
Links: ccv3.RootLinks{
125125
AppSSH: resources.APILink{
126126
HREF: "some-app-ssh-endpoint",
127127
Meta: resources.APILinkMeta{HostKeyFingerprint: "some-app-ssh-fingerprint"},

actor/v7action/target.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func (actor Actor) SetTarget(settings TargetSettings) (Warnings, error) {
1414

1515
actor.CloudControllerClient.TargetCF(ccv3.TargetSettings(settings))
1616

17-
rootInfo, warnings, err := actor.CloudControllerClient.GetInfo()
17+
rootInfo, warnings, err := actor.CloudControllerClient.GetRoot()
1818
allWarnings = append(allWarnings, warnings...)
1919
if err != nil {
2020
return allWarnings, err

actor/v7action/target_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ var _ = Describe("Targeting", func() {
5757
}
5858
meta.Version = expectedAPIVersion
5959

60-
rootResponse := ccv3.Info{
61-
Links: ccv3.InfoLinks{
60+
rootResponse := ccv3.Root{
61+
Links: ccv3.RootLinks{
6262
CCV3: resources.APILink{
6363
Meta: meta,
6464
},
@@ -76,7 +76,7 @@ var _ = Describe("Targeting", func() {
7676
},
7777
},
7878
}
79-
fakeCloudControllerClient.GetInfoReturns(rootResponse, ccv3.Warnings{"info-warning"}, nil)
79+
fakeCloudControllerClient.GetRootReturns(rootResponse, ccv3.Warnings{"info-warning"}, nil)
8080
})
8181

8282
JustBeforeEach(func() {
@@ -96,7 +96,7 @@ var _ = Describe("Targeting", func() {
9696

9797
When("getting root info fails", func() {
9898
BeforeEach(func() {
99-
fakeCloudControllerClient.GetInfoReturns(ccv3.Info{}, ccv3.Warnings{"info-warning"}, errors.New("info-error"))
99+
fakeCloudControllerClient.GetRootReturns(ccv3.Root{}, ccv3.Warnings{"info-warning"}, errors.New("info-error"))
100100
})
101101

102102
It("returns an error and all warnings", func() {
@@ -145,7 +145,7 @@ var _ = Describe("Targeting", func() {
145145

146146
When("deployed on Kubernetes", func() {
147147
BeforeEach(func() {
148-
fakeCloudControllerClient.GetInfoReturns(ccv3.Info{CFOnK8s: true}, nil, nil)
148+
fakeCloudControllerClient.GetRootReturns(ccv3.Root{CFOnK8s: true}, nil, nil)
149149
})
150150

151151
It("sets the CFOnK8s target information", func() {

actor/v7action/v7actionfakes/fake_cloud_controller_client.go

Lines changed: 85 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/cloudcontroller/ccv3/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ type Warnings []string
8686

8787
// Client can be used to talk to a Cloud Controller's V3 Endpoints.
8888
type Client struct {
89-
Info
89+
Root
9090
CloudControllerURL string
9191

9292
Requester

api/cloudcontroller/ccv3/client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ var _ = Describe("Cloud Controller Client", func() {
6363
})
6464

6565
It("adds a user agent header", func() {
66-
_, _, err := client.GetInfo()
66+
_, _, err := client.GetRoot()
6767
Expect(err).ToNot(HaveOccurred())
6868
Expect(server.ReceivedRequests()).To(HaveLen(1))
6969
})

0 commit comments

Comments
 (0)