Skip to content

Commit

Permalink
v8(services): delete-service-key use V3 API (#2129)
Browse files Browse the repository at this point in the history
  • Loading branch information
blgm authored Jan 22, 2021
1 parent 4cf0e1e commit c746aa4
Showing 10 changed files with 1,000 additions and 28 deletions.
8 changes: 4 additions & 4 deletions actor/v7action/service_app_binding_test.go
Original file line number Diff line number Diff line change
@@ -448,15 +448,15 @@ var _ = Describe("Service App Binding Action", func() {

When("fails", func() {
BeforeEach(func() {
fakeCloudControllerClient.GetApplicationByNameAndSpaceReturns(
resources.Application{},
ccv3.Warnings{"get app warning"},
fakeCloudControllerClient.GetServiceCredentialBindingsReturns(
[]resources.ServiceCredentialBinding{},
ccv3.Warnings{"get binding warning"},
errors.New("boom"),
)
})

It("returns the error and warning", func() {
Expect(warnings).To(ContainElement("get app warning"))
Expect(warnings).To(ContainElement("get binding warning"))
Expect(executionError).To(MatchError("boom"))
})
})
25 changes: 25 additions & 0 deletions actor/v7action/service_key.go
Original file line number Diff line number Diff line change
@@ -56,6 +56,31 @@ func (actor Actor) GetServiceKeyDetailsByServiceInstanceAndName(serviceInstanceN
return details, Warnings(warnings), err
}

func (actor Actor) DeleteServiceKeyByServiceInstanceAndName(serviceInstanceName, serviceKeyName, spaceGUID string) (chan PollJobEvent, Warnings, error) {
var (
key resources.ServiceCredentialBinding
jobURL ccv3.JobURL
stream chan PollJobEvent
)

warnings, err := railway.Sequentially(
func() (warnings ccv3.Warnings, err error) {
key, warnings, err = actor.getServiceKeyByServiceInstanceAndName(serviceInstanceName, serviceKeyName, spaceGUID)
return
},
func() (warnings ccv3.Warnings, err error) {
jobURL, warnings, err = actor.CloudControllerClient.DeleteServiceCredentialBinding(key.GUID)
return
},
func() (warnings ccv3.Warnings, err error) {
stream = actor.PollJobToEventStream(jobURL)
return
},
)

return stream, Warnings(warnings), err
}

func (actor Actor) getServiceKeyByServiceInstanceAndName(serviceInstanceName, serviceKeyName, spaceGUID string) (resources.ServiceCredentialBinding, ccv3.Warnings, error) {
var (
serviceInstance resources.ServiceInstance
189 changes: 189 additions & 0 deletions actor/v7action/service_key_test.go
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ import (
"code.cloudfoundry.org/cli/actor/v7action/v7actionfakes"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
"code.cloudfoundry.org/cli/cf/errors"
"code.cloudfoundry.org/cli/resources"
"code.cloudfoundry.org/cli/types"
@@ -496,4 +497,192 @@ var _ = Describe("Service Key Action", func() {
})
})
})

Describe("DeleteServiceKeyByServiceInstanceAndName", func() {
const (
serviceInstanceName = "fake-service-instance-name"
serviceInstanceGUID = "fake-service-instance-guid"
spaceGUID = "fake-space-guid"
serviceKeyName = "fake-key-name"
serviceKeyGUID = "fake-key-guid"
fakeJobURL = ccv3.JobURL("fake-job-url")
)

var (
warnings Warnings
executionError error
stream chan PollJobEvent
)

BeforeEach(func() {
fakeCloudControllerClient.GetServiceInstanceByNameAndSpaceReturns(
resources.ServiceInstance{
Name: serviceInstanceName,
GUID: serviceInstanceGUID,
Type: resources.ManagedServiceInstance,
},
ccv3.IncludedResources{},
ccv3.Warnings{"get instance warning"},
nil,
)

fakeCloudControllerClient.GetServiceCredentialBindingsReturns(
[]resources.ServiceCredentialBinding{
{GUID: serviceKeyGUID},
},
ccv3.Warnings{"get bindings warning"},
nil,
)

fakeCloudControllerClient.DeleteServiceCredentialBindingReturns(
fakeJobURL,
ccv3.Warnings{"delete binding warning"},
nil,
)

fakeStream := make(chan ccv3.PollJobEvent)
fakeCloudControllerClient.PollJobToEventStreamReturns(fakeStream)
go func() {
fakeStream <- ccv3.PollJobEvent{
State: constant.JobPolling,
Warnings: ccv3.Warnings{"poll warning"},
}
}()
})

JustBeforeEach(func() {
stream, warnings, executionError = actor.DeleteServiceKeyByServiceInstanceAndName(serviceInstanceName, serviceKeyName, spaceGUID)
})

It("returns an event stream, warnings, and no errors", func() {
Expect(executionError).NotTo(HaveOccurred())

Expect(warnings).To(ConsistOf(Warnings{
"get instance warning",
"get bindings warning",
"delete binding warning",
}))

Eventually(stream).Should(Receive(Equal(PollJobEvent{
State: JobPolling,
Warnings: Warnings{"poll warning"},
Err: nil,
})))
})

Describe("service instance lookup", func() {
It("makes the correct call", func() {
Expect(fakeCloudControllerClient.GetServiceInstanceByNameAndSpaceCallCount()).To(Equal(1))
actualServiceInstanceName, actualSpaceGUID, actualQuery := fakeCloudControllerClient.GetServiceInstanceByNameAndSpaceArgsForCall(0)
Expect(actualServiceInstanceName).To(Equal(serviceInstanceName))
Expect(actualSpaceGUID).To(Equal(spaceGUID))
Expect(actualQuery).To(BeEmpty())
})

When("not found", func() {
BeforeEach(func() {
fakeCloudControllerClient.GetServiceInstanceByNameAndSpaceReturns(
resources.ServiceInstance{},
ccv3.IncludedResources{},
ccv3.Warnings{"get instance warning"},
ccerror.ServiceInstanceNotFoundError{Name: serviceInstanceName},
)
})

It("returns the error and warning", func() {
Expect(warnings).To(ContainElement("get instance warning"))
Expect(executionError).To(MatchError(actionerror.ServiceInstanceNotFoundError{Name: serviceInstanceName}))
})
})

When("fails", func() {
BeforeEach(func() {
fakeCloudControllerClient.GetServiceInstanceByNameAndSpaceReturns(
resources.ServiceInstance{},
ccv3.IncludedResources{},
ccv3.Warnings{"get instance warning"},
errors.New("boof"),
)
})

It("returns the error and warning", func() {
Expect(warnings).To(ContainElement("get instance warning"))
Expect(executionError).To(MatchError("boof"))
})
})
})

Describe("key lookup", func() {
It("makes the correct call", func() {
Expect(fakeCloudControllerClient.GetServiceCredentialBindingsCallCount()).To(Equal(1))
Expect(fakeCloudControllerClient.GetServiceCredentialBindingsArgsForCall(0)).To(ConsistOf(
ccv3.Query{Key: ccv3.TypeFilter, Values: []string{"key"}},
ccv3.Query{Key: ccv3.NameFilter, Values: []string{serviceKeyName}},
ccv3.Query{Key: ccv3.ServiceInstanceGUIDFilter, Values: []string{serviceInstanceGUID}},
))
})

When("not found", func() {
BeforeEach(func() {
fakeCloudControllerClient.GetServiceCredentialBindingsReturns(
[]resources.ServiceCredentialBinding{},
ccv3.Warnings{"get keys warning"},
nil,
)
})

It("returns the error and warning", func() {
Expect(warnings).To(ContainElement("get keys warning"))
Expect(executionError).To(MatchError(actionerror.ServiceKeyNotFoundError{
KeyName: serviceKeyName,
ServiceInstanceName: serviceInstanceName,
}))
})
})

When("fails", func() {
BeforeEach(func() {
fakeCloudControllerClient.GetServiceCredentialBindingsReturns(
[]resources.ServiceCredentialBinding{},
ccv3.Warnings{"get key warning"},
errors.New("boom"),
)
})

It("returns the error and warning", func() {
Expect(warnings).To(ContainElement("get key warning"))
Expect(executionError).To(MatchError("boom"))
})
})
})

Describe("initiating the delete", func() {
It("makes the correct call", func() {
Expect(fakeCloudControllerClient.DeleteServiceCredentialBindingCallCount()).To(Equal(1))
Expect(fakeCloudControllerClient.DeleteServiceCredentialBindingArgsForCall(0)).To(Equal(serviceKeyGUID))
})

When("fails", func() {
BeforeEach(func() {
fakeCloudControllerClient.DeleteServiceCredentialBindingReturns(
"",
ccv3.Warnings{"delete binding warning"},
errors.New("boop"),
)
})

It("returns the error and warnings", func() {
Expect(warnings).To(ContainElement("delete binding warning"))
Expect(executionError).To(MatchError("boop"))
})
})
})

Describe("polling the job", func() {
It("polls the job", func() {
Expect(fakeCloudControllerClient.PollJobToEventStreamCallCount()).To(Equal(1))
Expect(fakeCloudControllerClient.PollJobToEventStreamArgsForCall(0)).To(Equal(fakeJobURL))
})
})
})
})
2 changes: 1 addition & 1 deletion command/common/command_list_v7.go
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@ type commandList struct {
DeleteSecurityGroup v7.DeleteSecurityGroupCommand `command:"delete-security-group" description:"Deletes a security group"`
DeleteService v7.DeleteServiceCommand `command:"delete-service" alias:"ds" description:"Delete a service instance"`
DeleteServiceBroker v7.DeleteServiceBrokerCommand `command:"delete-service-broker" description:"Delete a service broker"`
DeleteServiceKey v6.DeleteServiceKeyCommand `command:"delete-service-key" alias:"dsk" description:"Delete a service key"`
DeleteServiceKey v7.DeleteServiceKeyCommand `command:"delete-service-key" alias:"dsk" description:"Delete a service key"`
DeleteSharedDomain v7.DeleteSharedDomainCommand `command:"delete-shared-domain" description:"Delete a shared domain"`
DeleteSpace v7.DeleteSpaceCommand `command:"delete-space" description:"Delete a space"`
DeleteSpaceQuota v7.DeleteSpaceQuotaCommand `command:"delete-space-quota" description:"Delete a space quota"`
22 changes: 0 additions & 22 deletions command/v6/delete_service_key_command.go

This file was deleted.

3 changes: 2 additions & 1 deletion command/v7/actor.go
Original file line number Diff line number Diff line change
@@ -67,8 +67,9 @@ type Actor interface {
DeleteRouteBinding(params v7action.DeleteRouteBindingParams) (chan v7action.PollJobEvent, v7action.Warnings, error)
DeleteSecurityGroup(securityGroupName string) (v7action.Warnings, error)
DeleteServiceAppBinding(params v7action.DeleteServiceAppBindingParams) (chan v7action.PollJobEvent, v7action.Warnings, error)
DeleteServiceInstance(serviceInstanceName, spaceGUID string) (chan v7action.PollJobEvent, v7action.Warnings, error)
DeleteServiceBroker(serviceBrokerGUID string) (v7action.Warnings, error)
DeleteServiceInstance(serviceInstanceName, spaceGUID string) (chan v7action.PollJobEvent, v7action.Warnings, error)
DeleteServiceKeyByServiceInstanceAndName(serviceInstanceName, serviceKeyName, spaceGUID string) (chan v7action.PollJobEvent, v7action.Warnings, error)
DeleteSpaceByNameAndOrganizationName(spaceName string, orgName string) (v7action.Warnings, error)
DeleteSpaceQuotaByName(quotaName string, orgGUID string) (v7action.Warnings, error)
DeleteSpaceRole(roleType constant.RoleType, spaceGUID string, userNameOrGUID string, userOrigin string, isClient bool) (v7action.Warnings, error)
Loading

0 comments on commit c746aa4

Please sign in to comment.