Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
# Conflicts:
#	actor/v7action/revisions_test.go
#	api/cloudcontroller/ccv3/revisions_test.go
#	command/v7/revision_command.go
#	command/v7/revision_command_test.go
#	integration/v7/isolated/revision_command_test.go
  • Loading branch information
jcvrabo committed Jan 7, 2025
2 parents 9b249d1 + 61197b9 commit 21df2a5
Show file tree
Hide file tree
Showing 22 changed files with 836 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check-cves.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
uses: actions/checkout@v4

- name: Scan current project
uses: anchore/scan-action@v5
uses: anchore/scan-action@v6
with:
path: "."
add-cpes-if-none: true
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ on:
- "doc/**"
- ".gitpod.yml"
- "README.md"
workflow_dispatch:

jobs:
golangci:
Expand Down
1 change: 1 addition & 0 deletions actor/v7action/cloud_controller_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,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 Down
14 changes: 14 additions & 0 deletions actor/v7action/revisions.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,20 @@ func (actor Actor) GetRevisionByApplicationAndVersion(appGUID string, revisionVe
return revisions[0], Warnings(warnings), nil
}

func (actor Actor) GetEnvironmentVariableGroupByRevision(revision resources.Revision) (EnvironmentVariableGroup, bool, Warnings, error) {
envVarApiLink, isPresent := revision.Links["environment_variables"]
if !isPresent {
return EnvironmentVariableGroup{}, isPresent, Warnings{"Unable to retrieve environment variables for revision."}, nil
}

environmentVariables, warnings, err := actor.CloudControllerClient.GetEnvironmentVariablesByURL(envVarApiLink.HREF)
if err != nil {
return EnvironmentVariableGroup{}, false, Warnings(warnings), err
}

return EnvironmentVariableGroup(environmentVariables), true, Warnings(warnings), nil
}

func (actor Actor) setRevisionsDeployableByDropletStateForApp(appGUID string, revisions []resources.Revision) ([]resources.Revision, Warnings, error) {
droplets, warnings, err := actor.CloudControllerClient.GetDroplets(
ccv3.Query{Key: ccv3.AppGUIDFilter, Values: []string{appGUID}},
Expand Down
78 changes: 78 additions & 0 deletions actor/v7action/revisions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"code.cloudfoundry.org/cli/v9/api/cloudcontroller/ccv3"
"code.cloudfoundry.org/cli/v9/api/cloudcontroller/ccv3/constant"
"code.cloudfoundry.org/cli/v9/resources"
"code.cloudfoundry.org/cli/v9/types"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
Expand Down Expand Up @@ -397,4 +398,81 @@ var _ = Describe("Revisions Actions", func() {
})
})
})

Describe("GetEnvironmentVariableGroupByRevision", func() {
var (
actor *Actor
environmentVariablesGroup EnvironmentVariableGroup
executeErr error
fakeCloudControllerClient *v7actionfakes.FakeCloudControllerClient
fakeConfig *v7actionfakes.FakeConfig
isPresent bool
revision resources.Revision
warnings Warnings
)

BeforeEach(func() {
fakeCloudControllerClient = new(v7actionfakes.FakeCloudControllerClient)
fakeConfig = new(v7actionfakes.FakeConfig)
actor = NewActor(fakeCloudControllerClient, fakeConfig, nil, nil, nil, nil)
revision = resources.Revision{
Links: resources.APILinks{
"environment_variables": resources.APILink{
HREF: "url",
},
},
}
fakeConfig.APIVersionReturns("3.86.0")
})

JustBeforeEach(func() {
environmentVariablesGroup, isPresent, warnings, executeErr = actor.GetEnvironmentVariableGroupByRevision(revision)
})

When("the revision does not provide HREF", func() {
BeforeEach(func() {
revision = resources.Revision{}
})

It("returns as not present", func() {
Expect(executeErr).To(Not(HaveOccurred()))
Expect(warnings).To(ConsistOf("Unable to retrieve environment variables for revision."))
Expect(isPresent).To(Equal(false))
})
})

When("finding the environment variables fails", func() {
BeforeEach(func() {
fakeCloudControllerClient.GetEnvironmentVariablesByURLReturns(
nil,
ccv3.Warnings{"get-env-vars-warning-1"},
errors.New("get-env-vars-error-1"),
)
})

It("returns an error and warnings", func() {
Expect(executeErr).To(MatchError("get-env-vars-error-1"))
Expect(warnings).To(ConsistOf("get-env-vars-warning-1"))
})
})

When("finding the environment variables succeeds", func() {
BeforeEach(func() {
fakeCloudControllerClient.GetEnvironmentVariablesByURLReturns(
resources.EnvironmentVariables{"foo": *types.NewFilteredString("bar")},
ccv3.Warnings{"get-env-vars-warning-1"},
nil,
)
})

It("returns the environment variables and warnings", func() {
Expect(executeErr).ToNot(HaveOccurred())
Expect(fakeCloudControllerClient.GetEnvironmentVariablesByURLCallCount()).To(Equal(1))
Expect(fakeCloudControllerClient.GetEnvironmentVariablesByURLArgsForCall(0)).To(Equal("url"))
Expect(warnings).To(ConsistOf("get-env-vars-warning-1"))
Expect(len(environmentVariablesGroup)).To(Equal(1))
Expect(environmentVariablesGroup["foo"].Value).To(Equal("bar"))
})
})
})
})
84 changes: 84 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.

11 changes: 11 additions & 0 deletions api/cloudcontroller/ccv3/revisions.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,14 @@ func (client *Client) GetApplicationRevisionsDeployed(appGUID string) ([]resourc
})
return revisions, warnings, err
}

func (client *Client) GetEnvironmentVariablesByURL(url string) (resources.EnvironmentVariables, Warnings, error) {
environmentVariables := make(resources.EnvironmentVariables)

_, warnings, err := client.MakeRequest(RequestParams{
URL: url,
ResponseBody: &environmentVariables,
})

return environmentVariables, warnings, err
}
76 changes: 76 additions & 0 deletions api/cloudcontroller/ccv3/revisions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"code.cloudfoundry.org/cli/v9/api/cloudcontroller/ccv3/ccv3fakes"
"code.cloudfoundry.org/cli/v9/api/cloudcontroller/ccv3/internal"
"code.cloudfoundry.org/cli/v9/resources"
"code.cloudfoundry.org/cli/v9/types"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
Expand Down Expand Up @@ -133,4 +134,79 @@ var _ = Describe("Revisions", func() {
})
})
})

Describe("GetEnvironmentVariablesByURL", func() {
var (
warnings Warnings
executeErr error
environmentVariables resources.EnvironmentVariables
)

JustBeforeEach(func() {
environmentVariables, warnings, executeErr = client.GetEnvironmentVariablesByURL("url")
})

When("the cloud controller returns errors and warnings", func() {
BeforeEach(func() {
errors := []ccerror.V3Error{
{
Code: 10008,
Detail: "The request is semantically invalid: command presence",
Title: "CF-UnprocessableEntity",
},
{
Code: 10010,
Detail: "App not found",
Title: "CF-ResourceNotFound",
},
}

requester.MakeRequestReturns(
"url",
Warnings{"this is a warning"},
ccerror.MultiError{ResponseCode: http.StatusTeapot, Errors: errors},
)
})

It("returns the error and all warnings", func() {
Expect(executeErr).To(MatchError(ccerror.MultiError{
ResponseCode: http.StatusTeapot,
Errors: []ccerror.V3Error{
{
Code: 10008,
Detail: "The request is semantically invalid: command presence",
Title: "CF-UnprocessableEntity",
},
{
Code: 10010,
Detail: "App not found",
Title: "CF-ResourceNotFound",
},
},
}))
Expect(warnings).To(ConsistOf("this is a warning"))
})
})

When("revision exist", func() {
BeforeEach(func() {
requester.MakeRequestCalls(func(requestParams RequestParams) (JobURL, Warnings, error) {
(*requestParams.ResponseBody.(*resources.EnvironmentVariables))["foo"] = *types.NewFilteredString("bar")
return "url", Warnings{"this is a warning"}, nil
})
})

It("returns the environment variables and all warnings", func() {
Expect(requester.MakeRequestCallCount()).To(Equal(1))
actualParams := requester.MakeRequestArgsForCall(0)
Expect(actualParams.URL).To(Equal("url"))

Expect(executeErr).NotTo(HaveOccurred())
Expect(warnings).To(ConsistOf("this is a warning"))

Expect(len(environmentVariables)).To(Equal(1))
Expect(environmentVariables["foo"].Value).To(Equal("bar"))
})
})
})
})
2 changes: 0 additions & 2 deletions command/common/help_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ func (cmd HelpCommand) displayHelpFooter(cmdInfo map[string]sharedaction.Command
cmd.UI.DisplayNonWrappingTable(sharedaction.AllCommandsIndent, cmd.globalOptionsTableData(), 25)

cmd.UI.DisplayNewline()

cmd.displayCommandGroups(internal.ExperimentalHelpCategoryList, cmdInfo, 34)
}

func (cmd HelpCommand) displayCommonCommands() {
Expand Down
11 changes: 1 addition & 10 deletions command/common/internal/help_all_display.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var HelpCategoryList = []HelpCategory{
{"start", "stop", "restart", "stage-package", "restage", "restart-app-instance"},
{"run-task", "task", "tasks", "terminate-task"},
{"packages", "create-package"},
{"revisions", "rollback"},
{"revision", "revisions", "rollback"},
{"droplets", "set-droplet", "download-droplet"},
{"events", "logs"},
{"env", "set-env", "unset-env"},
Expand Down Expand Up @@ -168,12 +168,3 @@ var HelpCategoryList = []HelpCategory{
},
},
}

var ExperimentalHelpCategoryList = []HelpCategory{
{
CategoryName: "EXPERIMENTAL COMMANDS:",
CommandList: [][]string{
{"revision"},
},
},
}
10 changes: 0 additions & 10 deletions command/common/internal/help_all_display_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,6 @@ var _ = Describe("test help all display", func() {
}
}
}

for _, category := range internal.ExperimentalHelpCategoryList {
for _, row := range category.CommandList {
for _, command := range row {
if command != "" {
fromHelpAllDisplay = append(fromHelpAllDisplay, command)
}
}
}
}
})

It("lists all commands from command list in at least one category", func() {
Expand Down
1 change: 1 addition & 0 deletions command/v7/actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ type Actor interface {
GetDomainLabels(domainName string) (map[string]types.NullString, v7action.Warnings, error)
GetEffectiveIsolationSegmentBySpace(spaceGUID string, orgDefaultIsolationSegmentGUID string) (resources.IsolationSegment, v7action.Warnings, error)
GetEnvironmentVariableGroup(group constant.EnvironmentVariableGroupName) (v7action.EnvironmentVariableGroup, v7action.Warnings, error)
GetEnvironmentVariableGroupByRevision(revision resources.Revision) (v7action.EnvironmentVariableGroup, bool, v7action.Warnings, error)
GetEnvironmentVariablesByApplicationNameAndSpace(appName string, spaceGUID string) (v7action.EnvironmentVariableGroups, v7action.Warnings, error)
GetFeatureFlagByName(featureFlagName string) (resources.FeatureFlag, v7action.Warnings, error)
GetFeatureFlags() ([]resources.FeatureFlag, v7action.Warnings, error)
Expand Down
Loading

0 comments on commit 21df2a5

Please sign in to comment.