Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cf revision command implementation [main] #3337

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions actor/v7action/annotation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package v7action

import (
"code.cloudfoundry.org/cli/resources"
"code.cloudfoundry.org/cli/types"
)

func (actor *Actor) GetRevisionAnnotations(revisionGUID string) (map[string]types.NullString, Warnings, error) {
resource, warnings, err := actor.GetRevisionByGUID(revisionGUID)
return actor.extractAnnotations(resource.Metadata, warnings, err)
}

func (actor *Actor) extractAnnotations(metadata *resources.Metadata, warnings Warnings, err error) (map[string]types.NullString, Warnings, error) {
var annotations map[string]types.NullString

if err != nil {
return annotations, warnings, err
}
if metadata != nil {
annotations = metadata.Annotations
}
return annotations, warnings, nil
}
101 changes: 101 additions & 0 deletions actor/v7action/annotations_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package v7action_test

import (
"errors"

. "code.cloudfoundry.org/cli/actor/v7action"
"code.cloudfoundry.org/cli/actor/v7action/v7actionfakes"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
"code.cloudfoundry.org/cli/resources"
"code.cloudfoundry.org/cli/types"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var _ = Describe("annotations", func() {
var (
actor *Actor
fakeCloudControllerClient *v7actionfakes.FakeCloudControllerClient
fakeSharedActor *v7actionfakes.FakeSharedActor
fakeConfig *v7actionfakes.FakeConfig
warnings Warnings
executeErr error
annotations map[string]types.NullString
)

BeforeEach(func() {
fakeCloudControllerClient = new(v7actionfakes.FakeCloudControllerClient)
fakeSharedActor = new(v7actionfakes.FakeSharedActor)
fakeConfig = new(v7actionfakes.FakeConfig)
actor = NewActor(fakeCloudControllerClient, fakeConfig, fakeSharedActor, nil, nil, nil)
})

Describe("GetRevisionAnnotations", func() {
JustBeforeEach(func() {
annotations, warnings, executeErr = actor.GetRevisionAnnotations("some-guid")
})

When("there are no client errors", func() {
BeforeEach(func() {
fakeCloudControllerClient.GetRevisionReturns(
resources.Revision{GUID: "some-guid"},
ccv3.Warnings([]string{"warning-1", "warning-2"}),
nil,
)
})

It("gets the revision", func() {
Expect(fakeCloudControllerClient.GetRevisionCallCount()).To(Equal(1))
Expect(fakeCloudControllerClient.GetRevisionArgsForCall(0)).To(Equal("some-guid"))
})

When("there are no annotations on a revision", func() {
It("returns an empty map", func() {
Expect(executeErr).NotTo(HaveOccurred())
Expect(warnings).To(ConsistOf("warning-1", "warning-2"))
Expect(annotations).To(BeEmpty())
})
})

When("there are annotations", func() {
var expectedAnnotations map[string]types.NullString

BeforeEach(func() {
expectedAnnotations = map[string]types.NullString{"key1": types.NewNullString("value1"), "key2": types.NewNullString("value2")}
fakeCloudControllerClient.GetRevisionReturns(
resources.Revision{
GUID: "some-guid",
Metadata: &resources.Metadata{
Annotations: expectedAnnotations,
},
},
ccv3.Warnings([]string{"warning-1", "warning-2"}),
nil,
)
})
It("returns the annotations", func() {
Expect(executeErr).NotTo(HaveOccurred())
Expect(warnings).To(ConsistOf("warning-1", "warning-2"))
Expect(annotations).To(Equal(expectedAnnotations))
})
})
})

When("there is a client error", func() {
BeforeEach(func() {
fakeCloudControllerClient.GetRevisionReturns(
resources.Revision{GUID: "some-guid"},
ccv3.Warnings([]string{"warning-1", "warning-2"}),
errors.New("get-revision-error"),
)
})
When("GetRevision fails", func() {
It("returns the error and all warnings", func() {
Expect(executeErr).To(HaveOccurred())
Expect(warnings).To(ConsistOf("warning-1", "warning-2"))
Expect(executeErr).To(MatchError("get-revision-error"))
})
})
})
})
})
28 changes: 16 additions & 12 deletions actor/v7action/cloud_controller_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (

// CloudControllerClient is the interface to the cloud controller V3 API.
type CloudControllerClient interface {
AppSSHEndpoint() string
AppSSHHostKeyFingerprint() string
ApplyOrganizationQuota(quotaGUID string, orgGUID string) (resources.RelationshipList, ccv3.Warnings, error)
ApplySpaceQuota(quotaGUID string, spaceGUID string) (resources.RelationshipList, ccv3.Warnings, error)
CheckRoute(domainGUID string, hostname string, path string, port int) (bool, ccv3.Warnings, error)
Expand All @@ -35,10 +37,10 @@ type CloudControllerClient interface {
CreateRole(role resources.Role) (resources.Role, ccv3.Warnings, error)
CreateRoute(route resources.Route) (resources.Route, ccv3.Warnings, error)
CreateRouteBinding(binding resources.RouteBinding) (ccv3.JobURL, ccv3.Warnings, error)
CreateServiceBroker(serviceBroker resources.ServiceBroker) (ccv3.JobURL, ccv3.Warnings, error)
CreateServiceCredentialBinding(binding resources.ServiceCredentialBinding) (ccv3.JobURL, ccv3.Warnings, error)
CreateServiceInstance(serviceInstance resources.ServiceInstance) (ccv3.JobURL, ccv3.Warnings, error)
CreateSecurityGroup(securityGroup resources.SecurityGroup) (resources.SecurityGroup, ccv3.Warnings, error)
CreateServiceBroker(serviceBroker resources.ServiceBroker) (ccv3.JobURL, ccv3.Warnings, error)
CreateSpace(space resources.Space) (resources.Space, ccv3.Warnings, error)
CreateSpaceQuota(spaceQuota resources.SpaceQuota) (resources.SpaceQuota, ccv3.Warnings, error)
CreateUser(userGUID string) (resources.User, ccv3.Warnings, error)
Expand All @@ -58,11 +60,12 @@ type CloudControllerClient interface {
DeleteServiceCredentialBinding(guid string) (ccv3.JobURL, ccv3.Warnings, error)
DeleteServiceBroker(serviceBrokerGUID string) (ccv3.JobURL, ccv3.Warnings, error)
DeleteServiceInstance(serviceInstanceGUID string, query ...ccv3.Query) (ccv3.JobURL, ccv3.Warnings, error)
DeleteSpaceQuota(spaceQuotaGUID string) (ccv3.JobURL, ccv3.Warnings, error)
DeleteSpace(guid string) (ccv3.JobURL, ccv3.Warnings, error)
DeleteSpaceQuota(spaceQuotaGUID string) (ccv3.JobURL, ccv3.Warnings, error)
DeleteUser(userGUID string) (ccv3.JobURL, ccv3.Warnings, error)
DownloadDroplet(dropletGUID string) ([]byte, ccv3.Warnings, error)
EntitleIsolationSegmentToOrganizations(isoGUID string, orgGUIDs []string) (resources.RelationshipList, ccv3.Warnings, error)
GetAppFeature(appGUID string, featureName string) (resources.ApplicationFeature, ccv3.Warnings, error)
GetApplicationByNameAndSpace(appName string, spaceGUID string) (resources.Application, ccv3.Warnings, error)
GetApplicationDropletCurrent(appGUID string) (resources.Droplet, ccv3.Warnings, error)
GetApplicationEnvironment(appGUID string) (ccv3.Environment, ccv3.Warnings, error)
Expand All @@ -84,6 +87,7 @@ type CloudControllerClient interface {
GetDroplet(guid string) (resources.Droplet, ccv3.Warnings, error)
GetDroplets(query ...ccv3.Query) ([]resources.Droplet, ccv3.Warnings, error)
GetEnvironmentVariableGroup(group constant.EnvironmentVariableGroupName) (resources.EnvironmentVariables, ccv3.Warnings, error)
GetEnvironmentVariablesByURL(url string) (resources.EnvironmentVariables, ccv3.Warnings, error)
GetEvents(query ...ccv3.Query) ([]ccv3.Event, ccv3.Warnings, error)
GetFeatureFlag(featureFlagName string) (resources.FeatureFlag, ccv3.Warnings, error)
GetFeatureFlags() ([]resources.FeatureFlag, ccv3.Warnings, error)
Expand All @@ -99,17 +103,19 @@ type CloudControllerClient interface {
GetOrganizationQuotas(query ...ccv3.Query) ([]resources.OrganizationQuota, ccv3.Warnings, error)
GetOrganizations(query ...ccv3.Query) ([]resources.Organization, ccv3.Warnings, error)
GetPackage(guid string) (resources.Package, ccv3.Warnings, error)
GetPackages(query ...ccv3.Query) ([]resources.Package, ccv3.Warnings, error)
GetPackageDroplets(packageGUID string, query ...ccv3.Query) ([]resources.Droplet, ccv3.Warnings, error)
GetPackages(query ...ccv3.Query) ([]resources.Package, ccv3.Warnings, error)
GetProcess(processGUID string) (resources.Process, ccv3.Warnings, error)
GetProcesses(query ...ccv3.Query) ([]resources.Process, ccv3.Warnings, error)
GetProcessInstances(processGUID string) ([]ccv3.ProcessInstance, ccv3.Warnings, error)
GetProcessSidecars(processGUID string) ([]resources.Sidecar, ccv3.Warnings, error)
GetProcesses(query ...ccv3.Query) ([]resources.Process, ccv3.Warnings, error)
GetRevision(revisionGUID string) (resources.Revision, ccv3.Warnings, error)
GetRoles(query ...ccv3.Query) ([]resources.Role, ccv3.IncludedResources, ccv3.Warnings, error)
GetRouteBindings(query ...ccv3.Query) ([]resources.RouteBinding, ccv3.IncludedResources, ccv3.Warnings, error)
GetRouteDestinations(routeGUID string) ([]resources.RouteDestination, ccv3.Warnings, error)
GetRoutes(query ...ccv3.Query) ([]resources.Route, ccv3.Warnings, error)
GetRunningSecurityGroups(spaceGUID string, queries ...ccv3.Query) ([]resources.SecurityGroup, ccv3.Warnings, error)
GetSSHEnabled(appGUID string) (ccv3.SSHEnabled, ccv3.Warnings, error)
GetSecurityGroups(query ...ccv3.Query) ([]resources.SecurityGroup, ccv3.Warnings, error)
GetServiceBrokers(query ...ccv3.Query) ([]resources.ServiceBroker, ccv3.Warnings, error)
GetServiceCredentialBindings(query ...ccv3.Query) ([]resources.ServiceCredentialBinding, ccv3.Warnings, error)
Expand All @@ -120,20 +126,18 @@ type CloudControllerClient interface {
GetServiceInstanceUsageSummary(serviceInstanceGUID string) ([]resources.ServiceInstanceUsageSummary, ccv3.Warnings, error)
GetServiceInstances(query ...ccv3.Query) ([]resources.ServiceInstance, ccv3.IncludedResources, ccv3.Warnings, error)
GetServiceOfferingByGUID(guid string) (resources.ServiceOffering, ccv3.Warnings, error)
GetServiceOfferings(query ...ccv3.Query) ([]resources.ServiceOffering, ccv3.Warnings, error)
GetServiceOfferingByNameAndBroker(serviceOfferingName, serviceBrokerName string) (resources.ServiceOffering, ccv3.Warnings, error)
GetServicePlanByGUID(guid string) (resources.ServicePlan, ccv3.Warnings, error)
GetServiceOfferings(query ...ccv3.Query) ([]resources.ServiceOffering, ccv3.Warnings, error)
GetServicePlans(query ...ccv3.Query) ([]resources.ServicePlan, ccv3.Warnings, error)
GetServicePlansWithOfferings(query ...ccv3.Query) ([]ccv3.ServiceOfferingWithPlans, ccv3.Warnings, error)
GetServicePlansWithSpaceAndOrganization(query ...ccv3.Query) ([]ccv3.ServicePlanWithSpaceAndOrganization, ccv3.Warnings, error)
GetSpaceFeature(spaceGUID string, featureName string) (bool, ccv3.Warnings, error)
GetSpaceIsolationSegment(spaceGUID string) (resources.Relationship, ccv3.Warnings, error)
GetSpaceManifestDiff(spaceGUID string, rawManifest []byte) (resources.ManifestDiff, ccv3.Warnings, error)
GetSpaceQuota(spaceQuotaGUID string) (resources.SpaceQuota, ccv3.Warnings, error)
GetSpaces(query ...ccv3.Query) ([]resources.Space, ccv3.IncludedResources, ccv3.Warnings, error)
GetSpaceQuotas(query ...ccv3.Query) ([]resources.SpaceQuota, ccv3.Warnings, error)
GetSSHEnabled(appGUID string) (ccv3.SSHEnabled, ccv3.Warnings, error)
GetAppFeature(appGUID string, featureName string) (resources.ApplicationFeature, ccv3.Warnings, error)
GetSpaces(query ...ccv3.Query) ([]resources.Space, ccv3.IncludedResources, ccv3.Warnings, error)
GetStacks(query ...ccv3.Query) ([]resources.Stack, ccv3.Warnings, error)
GetStagingSecurityGroups(spaceGUID string, queries ...ccv3.Query) ([]resources.SecurityGroup, ccv3.Warnings, error)
GetTask(guid string) (resources.Task, ccv3.Warnings, error)
Expand All @@ -157,6 +161,7 @@ type CloudControllerClient interface {
UnbindSecurityGroupStagingSpace(securityGroupGUID string, spaceGUID string) (ccv3.Warnings, error)
UnmapRoute(routeGUID string, destinationGUID string) (ccv3.Warnings, error)
UnshareRoute(routeGUID string, spaceGUID string) (ccv3.Warnings, error)
UnsetSpaceQuota(spaceQuotaGUID, spaceGUID string) (ccv3.Warnings, error)
UnsharePrivateDomainFromOrg(domainGUID string, sharedOrgGUID string) (ccv3.Warnings, error)
UnshareServiceInstanceFromSpace(serviceInstanceGUID string, sharedToSpaceGUID string) (ccv3.Warnings, error)
UpdateAppFeature(appGUID string, enabled bool, featureName string) (ccv3.Warnings, error)
Expand All @@ -176,17 +181,16 @@ type CloudControllerClient interface {
UpdateOrganizationQuota(orgQuota resources.OrganizationQuota) (resources.OrganizationQuota, ccv3.Warnings, error)
UpdateProcess(process resources.Process) (resources.Process, ccv3.Warnings, error)
UpdateResourceMetadata(resource string, resourceGUID string, metadata resources.Metadata) (ccv3.JobURL, ccv3.Warnings, error)
UpdateSecurityGroup(securityGroup resources.SecurityGroup) (resources.SecurityGroup, ccv3.Warnings, error)
UpdateSecurityGroupRunningSpace(securityGroupGUID string, spaceGUIDs []string) (ccv3.Warnings, error)
UpdateSecurityGroupStagingSpace(securityGroupGUID string, spaceGUIDs []string) (ccv3.Warnings, error)
UpdateSecurityGroup(securityGroup resources.SecurityGroup) (resources.SecurityGroup, ccv3.Warnings, error)
UpdateServiceBroker(serviceBrokerGUID string, serviceBroker resources.ServiceBroker) (ccv3.JobURL, ccv3.Warnings, error)
UpdateServiceInstance(serviceInstanceGUID string, serviceInstanceUpdates resources.ServiceInstance) (ccv3.JobURL, ccv3.Warnings, error)
UpdateSpace(space resources.Space) (resources.Space, ccv3.Warnings, error)
UpdateSpaceApplyManifest(spaceGUID string, rawManifest []byte) (ccv3.JobURL, ccv3.Warnings, error)
UpdateSpaceFeature(spaceGUID string, enabled bool, featureName string) (ccv3.Warnings, error)
UpdateSpaceIsolationSegmentRelationship(spaceGUID string, isolationSegmentGUID string) (resources.Relationship, ccv3.Warnings, error)
UpdateSpaceQuota(spaceQuota resources.SpaceQuota) (resources.SpaceQuota, ccv3.Warnings, error)
UnsetSpaceQuota(spaceQuotaGUID, spaceGUID string) (ccv3.Warnings, error)
UpdateServiceBroker(serviceBrokerGUID string, serviceBroker resources.ServiceBroker) (ccv3.JobURL, ccv3.Warnings, error)
UpdateTaskCancel(taskGUID string) (resources.Task, ccv3.Warnings, error)
UploadBitsPackage(pkg resources.Package, matchedResources []ccv3.Resource, newResources io.Reader, newResourcesLength int64) (resources.Package, ccv3.Warnings, error)
UploadBuildpack(buildpackGUID string, buildpackPath string, buildpack io.Reader, buildpackLength int64) (ccv3.JobURL, ccv3.Warnings, error)
Expand All @@ -198,9 +202,9 @@ type CloudControllerClient interface {
}

type servicePlanVisibilityClient interface {
DeleteServicePlanVisibility(servicePlanGUID, organizationGUID string) (ccv3.Warnings, error)
GetServicePlanVisibility(servicePlanGUID string) (resources.ServicePlanVisibility, ccv3.Warnings, error)
UpdateServicePlanVisibility(servicePlanGUID string, visibility resources.ServicePlanVisibility) (resources.ServicePlanVisibility, ccv3.Warnings, error)
DeleteServicePlanVisibility(servicePlanGUID, organizationGUID string) (ccv3.Warnings, error)
}

// TODO: Split this enormous interface
5 changes: 5 additions & 0 deletions actor/v7action/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ func (actor *Actor) GetBuildpackLabels(buildpackName string, buildpackStack stri
return actor.extractLabels(resource.Metadata, warnings, err)
}

func (actor *Actor) GetRevisionLabels(revisionGUID string) (map[string]types.NullString, Warnings, error) {
resource, warnings, err := actor.GetRevisionByGUID(revisionGUID)
return actor.extractLabels(resource.Metadata, warnings, err)
}

func (actor *Actor) extractLabels(metadata *resources.Metadata, warnings Warnings, err error) (map[string]types.NullString, Warnings, error) {
var labels map[string]types.NullString

Expand Down
69 changes: 69 additions & 0 deletions actor/v7action/label_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1470,4 +1470,73 @@ var _ = Describe("labels", func() {
})
})
})

Describe("GetRevisionLabels", func() {
JustBeforeEach(func() {
labels, warnings, executeErr = actor.GetRevisionLabels("some-guid")
})

When("there are no client errors", func() {
BeforeEach(func() {
fakeCloudControllerClient.GetRevisionReturns(
resources.Revision{GUID: "some-guid"},
ccv3.Warnings([]string{"warning-1", "warning-2"}),
nil,
)
})

It("gets the revision", func() {
Expect(fakeCloudControllerClient.GetRevisionCallCount()).To(Equal(1))
Expect(fakeCloudControllerClient.GetRevisionArgsForCall(0)).To(Equal("some-guid"))
})

When("there are no labels on a revision", func() {
It("returns an empty map", func() {
Expect(executeErr).NotTo(HaveOccurred())
Expect(warnings).To(ConsistOf("warning-1", "warning-2"))
Expect(labels).To(BeEmpty())
})
})

When("there are labels", func() {
var expectedLabels map[string]types.NullString

BeforeEach(func() {
expectedLabels = map[string]types.NullString{"key1": types.NewNullString("value1"), "key2": types.NewNullString("value2")}
fakeCloudControllerClient.GetRevisionReturns(
resources.Revision{
GUID: "some-guid",
Metadata: &resources.Metadata{
Labels: expectedLabels,
},
},
ccv3.Warnings([]string{"warning-1", "warning-2"}),
nil,
)
})
It("returns the labels", func() {
Expect(executeErr).NotTo(HaveOccurred())
Expect(warnings).To(ConsistOf("warning-1", "warning-2"))
Expect(labels).To(Equal(expectedLabels))
})
})
})

When("there is a client error", func() {
BeforeEach(func() {
fakeCloudControllerClient.GetRevisionReturns(
resources.Revision{GUID: "some-guid"},
ccv3.Warnings([]string{"warning-1", "warning-2"}),
errors.New("get-revision-error"),
)
})
When("GetRevision fails", func() {
It("returns the error and all warnings", func() {
Expect(executeErr).To(HaveOccurred())
Expect(warnings).To(ConsistOf("warning-1", "warning-2"))
Expect(executeErr).To(MatchError("get-revision-error"))
})
})
})
})
})
12 changes: 12 additions & 0 deletions actor/v7action/revision.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package v7action

import "code.cloudfoundry.org/cli/resources"

func (actor Actor) GetRevisionByGUID(revisionGUID string) (resources.Revision, Warnings, error) {
revision, warnings, err := actor.CloudControllerClient.GetRevision(revisionGUID)
if err != nil {
return resources.Revision{}, Warnings(warnings), err
}

return resources.Revision(revision), Warnings(warnings), err
}
Loading
Loading