Skip to content

Commit

Permalink
CLI user can unshare a private domain
Browse files Browse the repository at this point in the history
[finishes #162998046]

Authored-by: Eli Wrenn <ewrenn@pivotal.io>
  • Loading branch information
ewrenn8 committed Apr 29, 2019
1 parent d3f8214 commit 4305d2f
Show file tree
Hide file tree
Showing 12 changed files with 813 additions and 34 deletions.
1 change: 1 addition & 0 deletions actor/v7action/cloud_controller_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type CloudControllerClient interface {
SetApplicationDroplet(appGUID string, dropletGUID string) (ccv3.Relationship, ccv3.Warnings, error)
SharePrivateDomainToOrgs(domainGuid string, sharedOrgs ccv3.SharedOrgs) (ccv3.Warnings, error)
ShareServiceInstanceToSpaces(serviceInstanceGUID string, spaceGUIDs []string) (ccv3.RelationshipList, ccv3.Warnings, error)
UnsharePrivateDomainFromOrg(domainGUID string, sharedOrgGUID string) (ccv3.Warnings, error)
UpdateApplication(app ccv3.Application) (ccv3.Application, ccv3.Warnings, error)
UpdateApplicationApplyManifest(appGUID string, rawManifest []byte) (ccv3.JobURL, ccv3.Warnings, error)
UpdateApplicationEnvironmentVariables(appGUID string, envVars ccv3.EnvironmentVariables) (ccv3.EnvironmentVariables, ccv3.Warnings, error)
Expand Down
48 changes: 36 additions & 12 deletions actor/v7action/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,28 +76,52 @@ func (actor Actor) GetDomainByName(domainName string) (Domain, Warnings, error)
}

func (actor Actor) SharePrivateDomain(domainName string, orgName string) (Warnings, error) {
allWarnings := Warnings{}
org, warnings, err := actor.GetOrganizationByName(orgName)
allWarnings = append(allWarnings, warnings...)
orgGUID, domainGUID, warnings, err := actor.GetDomainAndOrgGUIDsByName(domainName, orgName)

if err != nil {
return allWarnings, err
return warnings, err
}

domain, warnings, err := actor.GetDomainByName(domainName)
allWarnings = append(allWarnings, warnings...)
apiWarnings, err := actor.CloudControllerClient.SharePrivateDomainToOrgs(
domainGUID,
ccv3.SharedOrgs{GUIDs: []string{orgGUID}},
)

allWarnings := append(warnings, Warnings(apiWarnings)...)

return allWarnings, err
}

func (actor Actor) UnsharePrivateDomain(domainName string, orgName string) (Warnings, error) {
orgGUID, domainGUID, warnings, err := actor.GetDomainAndOrgGUIDsByName(domainName, orgName)

if err != nil {
return allWarnings, err
return warnings, err
}

apiWarnings, err := actor.CloudControllerClient.SharePrivateDomainToOrgs(
domain.GUID,
ccv3.SharedOrgs{GUIDs: []string{org.GUID}},
apiWarnings, err := actor.CloudControllerClient.UnsharePrivateDomainFromOrg(
domainGUID,
orgGUID,
)

actorWarnings := Warnings(apiWarnings)
allWarnings = append(allWarnings, actorWarnings...)
allWarnings := append(warnings, Warnings(apiWarnings)...)

return allWarnings, err
}

func (actor Actor) GetDomainAndOrgGUIDsByName(domainName string, orgName string) (string, string, Warnings, error) {
org, getOrgWarnings, err := actor.GetOrganizationByName(orgName)

if err != nil {
return "", "", getOrgWarnings, err
}

domain, getDomainWarnings, err := actor.GetDomainByName(domainName)
allWarnings := append(getOrgWarnings, getDomainWarnings...)

if err != nil {
return "", "", allWarnings, err
}

return org.GUID, domain.GUID, allWarnings, nil
}
184 changes: 184 additions & 0 deletions actor/v7action/domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,188 @@ var _ = Describe("Domain Actions", func() {
Expect(sharedOrgs).To(Equal(ccv3.SharedOrgs{GUIDs: []string{"org-guid"}}))
})
})

Describe("unshare private domain from org", func() {
var (
domainName string
orgName string
executeErr error
warnings Warnings
)

JustBeforeEach(func() {
warnings, executeErr = actor.UnsharePrivateDomain(domainName, orgName)
})

When("getting the org or domain errors", func() {
BeforeEach(func() {
fakeCloudControllerClient.GetOrganizationsReturns(
nil,
ccv3.Warnings{"get-orgs-warning"},
errors.New("get-orgs-error"),
)
})
It("returns an error and the warnings", func() {
Expect(fakeCloudControllerClient.UnsharePrivateDomainFromOrgCallCount()).To(Equal(0))

Expect(executeErr).To(MatchError(errors.New("get-orgs-error")))
Expect(warnings).To(ConsistOf("get-orgs-warning"))
})
})

When("getting the guids succeeds", func() {
BeforeEach(func() {
fakeCloudControllerClient.GetDomainsReturns(
[]ccv3.Domain{
{Name: domainName, GUID: "private-domain-guid"},
},
ccv3.Warnings{"get-domains-warning"},
nil,
)

fakeCloudControllerClient.GetOrganizationsReturns(
[]ccv3.Organization{
{Name: orgName, GUID: "org-guid"},
},
ccv3.Warnings{"get-orgs-warning"},
nil,
)
})

When("Unsharing the domain errors", func() {
BeforeEach(func() {
fakeCloudControllerClient.UnsharePrivateDomainFromOrgReturns(
ccv3.Warnings{"unshare-domain-warning"},
errors.New("unsahre-domain-error"),
)
})

It("returns any warnings and errors", func() {
Expect(fakeCloudControllerClient.UnsharePrivateDomainFromOrgCallCount()).To(Equal(1))
actualDomainGUID, actualOrgGUID := fakeCloudControllerClient.UnsharePrivateDomainFromOrgArgsForCall(0)
Expect(actualDomainGUID).To(Equal("private-domain-guid"))
Expect(actualOrgGUID).To(Equal("org-guid"))

Expect(executeErr).To(MatchError(errors.New("unsahre-domain-error")))
Expect(warnings).To(ConsistOf("get-orgs-warning", "get-domains-warning", "unshare-domain-warning"))
})
})

When("everything succeeds", func() {
BeforeEach(func() {
fakeCloudControllerClient.UnsharePrivateDomainFromOrgReturns(
ccv3.Warnings{"unshare-domain-warning"},
nil,
)
})

It("returns any warnings and no error", func() {
Expect(fakeCloudControllerClient.UnsharePrivateDomainFromOrgCallCount()).To(Equal(1))
actualDomainGUID, actualOrgGUID := fakeCloudControllerClient.UnsharePrivateDomainFromOrgArgsForCall(0)
Expect(actualDomainGUID).To(Equal("private-domain-guid"))
Expect(actualOrgGUID).To(Equal("org-guid"))

Expect(executeErr).ToNot(HaveOccurred())
Expect(warnings).To(ConsistOf("get-orgs-warning", "get-domains-warning", "unshare-domain-warning"))
})
})
})
})

Describe("GetDomainAndOrgByNames", func() {
var (
orgName = "my-org"
domainName = "domain.com"

orgGUID string
domainGUID string
warnings Warnings
executeErr error
)
JustBeforeEach(func() {
orgGUID, domainGUID, warnings, executeErr = actor.GetDomainAndOrgGUIDsByName(domainName, orgName)
})

When("Getting the organization is not successful", func() {
BeforeEach(func() {
fakeCloudControllerClient.GetOrganizationsReturns(
nil,
ccv3.Warnings{"get-orgs-warning"},
errors.New("get-orgs-error"),
)
})

It("returns the error and doesnt get the domain", func() {
Expect(fakeCloudControllerClient.GetOrganizationsCallCount()).To(Equal(1))
actualQuery := fakeCloudControllerClient.GetOrganizationsArgsForCall(0)
Expect(actualQuery).To(Equal([]ccv3.Query{{Key: ccv3.NameFilter, Values: []string{orgName}}}))

Expect(fakeCloudControllerClient.GetDomainsCallCount()).To(Equal(0))

Expect(executeErr).To(MatchError(errors.New("get-orgs-error")))
Expect(warnings).To(ConsistOf("get-orgs-warning"))
})
})

When("getting the orgs succeeds", func() {
BeforeEach(func() {
fakeCloudControllerClient.GetOrganizationsReturns(
[]ccv3.Organization{
{Name: orgName, GUID: "org-guid"},
},
ccv3.Warnings{"get-orgs-warning"},
nil,
)
})
When("Getting the domain is not successful", func() {
BeforeEach(func() {
fakeCloudControllerClient.GetDomainsReturns(
nil,
ccv3.Warnings{"get-domains-warning"},
errors.New("get-domains-error"),
)
})

It("returns the error and doesnt get the domain", func() {
Expect(fakeCloudControllerClient.GetOrganizationsCallCount()).To(Equal(1))
actualQuery := fakeCloudControllerClient.GetOrganizationsArgsForCall(0)
Expect(actualQuery).To(Equal([]ccv3.Query{{Key: ccv3.NameFilter, Values: []string{orgName}}}))

Expect(fakeCloudControllerClient.GetDomainsCallCount()).To(Equal(1))
actualQuery = fakeCloudControllerClient.GetDomainsArgsForCall(0)
Expect(actualQuery).To(Equal([]ccv3.Query{{Key: ccv3.NameFilter, Values: []string{domainName}}}))

Expect(executeErr).To(MatchError(errors.New("get-domains-error")))
Expect(warnings).To(ConsistOf("get-orgs-warning", "get-domains-warning"))
})
})

When("the api call are successful", func() {
BeforeEach(func() {
fakeCloudControllerClient.GetDomainsReturns(
[]ccv3.Domain{
{Name: domainName, GUID: "private-domain-guid"},
},
ccv3.Warnings{"get-domains-warning"},
nil,
)
})

It("returns the GUIDs", func() {
Expect(fakeCloudControllerClient.GetOrganizationsCallCount()).To(Equal(1))
actualQuery := fakeCloudControllerClient.GetOrganizationsArgsForCall(0)
Expect(actualQuery).To(Equal([]ccv3.Query{{Key: ccv3.NameFilter, Values: []string{orgName}}}))

Expect(fakeCloudControllerClient.GetDomainsCallCount()).To(Equal(1))
actualQuery = fakeCloudControllerClient.GetDomainsArgsForCall(0)
Expect(actualQuery).To(Equal([]ccv3.Query{{Key: ccv3.NameFilter, Values: []string{domainName}}}))

Expect(executeErr).ToNot(HaveOccurred())
Expect(warnings).To(ConsistOf("get-orgs-warning", "get-domains-warning"))
Expect(orgGUID).To(Equal("org-guid"))
Expect(domainGUID).To(Equal("private-domain-guid"))
})
})
})
})
})
80 changes: 80 additions & 0 deletions actor/v7action/v7actionfakes/fake_cloud_controller_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions api/cloudcontroller/ccv3/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,19 @@ func (client Client) SharePrivateDomainToOrgs(domainGuid string, sharedOrgs Shar

return response.Warnings, err
}

func (client Client) UnsharePrivateDomainFromOrg(domainGuid string, orgGUID string) (Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
URIParams: internal.Params{"domain_guid": domainGuid, "org_guid": orgGUID},
RequestName: internal.DeleteSharedOrgFromDomainRequest,
})

if err != nil {
return nil, err
}

var response cloudcontroller.Response

err = client.connection.Make(request, &response)
return response.Warnings, err
}
Loading

0 comments on commit 4305d2f

Please sign in to comment.