Skip to content

Commit

Permalink
Merge branch 'main' into add-current-droplet-relationships-for-apps-main
Browse files Browse the repository at this point in the history
  • Loading branch information
joaopapereira authored Jan 21, 2025
2 parents a84c483 + bef20a2 commit 0f9f273
Show file tree
Hide file tree
Showing 7 changed files with 247 additions and 88 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/check-cves.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
uses: actions/checkout@v4

- name: Scan current project
id: scan
uses: anchore/scan-action@v6
with:
path: "."
Expand All @@ -21,12 +22,12 @@ jobs:
output-format: json

- name: Print scan results
run: .github/scripts/format-cve-scan-results.sh results.json > $GITHUB_STEP_SUMMARY
run: .github/scripts/format-cve-scan-results.sh ${{ steps.scan.outputs.json }} > $GITHUB_STEP_SUMMARY
if: always()

- name: Archive CVE scan results
uses: actions/upload-artifact@v4
if: always()
with:
name: cve-scan-results-${{ github.sha }}-${{ github.run_id }}-${{ github.run_number }}
path: results.json
path: ${{ steps.scan.outputs.json }}
62 changes: 44 additions & 18 deletions command/v7/revision_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type RevisionCommand struct {
BaseCommand
usage interface{} `usage:"CF_NAME revision APP_NAME [--version VERSION]"`
RequiredArgs flag.AppName `positional-args:"yes"`
Version flag.Revision `long:"version" required:"true" description:"The integer representing the specific revision to show"`
Version flag.Revision `long:"version" description:"The integer representing the specific revision to show"`
relatedCommands interface{} `related_commands:"revisions, rollback"`
}

Expand All @@ -30,13 +30,23 @@ func (cmd RevisionCommand) Execute(_ []string) error {
}

appName := cmd.RequiredArgs.AppName
cmd.UI.DisplayTextWithFlavor("Showing revision {{.Version}} for app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...", map[string]interface{}{
"AppName": appName,
"OrgName": cmd.Config.TargetedOrganization().Name,
"SpaceName": cmd.Config.TargetedSpace().Name,
"Username": user.Name,
"Version": cmd.Version.Value,
})
if cmd.Version.Value > 0 {
cmd.UI.DisplayTextWithFlavor("Showing revision {{.Version}} for app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...", map[string]interface{}{
"AppName": appName,
"OrgName": cmd.Config.TargetedOrganization().Name,
"SpaceName": cmd.Config.TargetedSpace().Name,
"Username": user.Name,
"Version": cmd.Version.Value,
})
} else {
cmd.UI.DisplayTextWithFlavor("Showing revisions for app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...", map[string]interface{}{
"AppName": appName,
"OrgName": cmd.Config.TargetedOrganization().Name,
"SpaceName": cmd.Config.TargetedSpace().Name,
"Username": user.Name,
})
}

cmd.UI.DisplayNewline()

app, warnings, err := cmd.Actor.GetApplicationByNameAndSpace(appName, cmd.Config.TargetedSpace().GUID)
Expand All @@ -51,16 +61,33 @@ func (cmd RevisionCommand) Execute(_ []string) error {
return err
}

revision, warnings, err := cmd.Actor.GetRevisionByApplicationAndVersion(
app.GUID,
cmd.Version.Value,
)
cmd.UI.DisplayWarnings(warnings)
if err != nil {
return err
if cmd.Version.Value > 0 {
revision, warnings, err := cmd.Actor.GetRevisionByApplicationAndVersion(
app.GUID,
cmd.Version.Value,
)
cmd.UI.DisplayWarnings(warnings)
if err != nil {
return err
}
isDeployed := cmd.revisionDeployed(revision, deployedRevisions)

err = cmd.displayRevisionInfo(revision, isDeployed)
if err != nil {
return err
}
} else {
for _, deployedRevision := range deployedRevisions {
err = cmd.displayRevisionInfo(deployedRevision, true)
if err != nil {
return err
}
}
}
isDeployed := cmd.revisionDeployed(revision, deployedRevisions)
return nil
}

func (cmd RevisionCommand) displayRevisionInfo(revision resources.Revision, isDeployed bool) error {
cmd.displayBasicRevisionInfo(revision, isDeployed)
cmd.UI.DisplayNewline()

Expand All @@ -80,13 +107,12 @@ func (cmd RevisionCommand) Execute(_ []string) error {
cmd.displayEnvVarGroup(envVars)
cmd.UI.DisplayNewline()
}

return nil
}

func (cmd RevisionCommand) displayBasicRevisionInfo(revision resources.Revision, isDeployed bool) {
keyValueTable := [][]string{
{"revision:", fmt.Sprintf("%d", cmd.Version.Value)},
{"revision:", fmt.Sprintf("%d", revision.Version)},
{"deployed:", strconv.FormatBool(isDeployed)},
{"description:", revision.Description},
{"deployable:", strconv.FormatBool(revision.Deployable)},
Expand Down
90 changes: 90 additions & 0 deletions command/v7/revision_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,101 @@ var _ = Describe("revision Command", func() {
})
})

When("no revision version is provided", func() {
BeforeEach(func() {
deployedRevisions := []resources.Revision{
{
Version: 3,
GUID: "A68F13F7-7E5E-4411-88E8-1FAC54F73F50",
Description: "On a different note",
CreatedAt: "2020-03-10T17:11:58Z",
Deployable: true,
Droplet: resources.Droplet{
GUID: "droplet-guid",
},
Links: resources.APILinks{
"environment_variables": resources.APILink{
HREF: "revision-environment-variables-link-3",
},
},
Metadata: &resources.Metadata{
Labels: map[string]types.NullString{
"label": types.NewNullString("foo3"),
},
Annotations: map[string]types.NullString{
"annotation": types.NewNullString("foo3"),
},
},
},
{
Version: 2,
GUID: "A89F8259-D32B-491A-ABD6-F100AC42D74C",
Description: "Something else",
CreatedAt: "2020-03-08T12:43:30Z",
Deployable: true,
Droplet: resources.Droplet{
GUID: "droplet-guid2",
},
Metadata: &resources.Metadata{},
},
}
fakeActor.GetApplicationByNameAndSpaceReturns(resources.Application{GUID: "app-guid"}, nil, nil)
fakeActor.GetApplicationRevisionsDeployedReturns(deployedRevisions, nil, nil)

environmentVariableGroup := v7action.EnvironmentVariableGroup{
"foo": *types.NewFilteredString("bar3"),
}
fakeActor.GetEnvironmentVariableGroupByRevisionReturns(
environmentVariableGroup,
true,
nil,
nil,
)
cmd.Version = flag.Revision{NullInt: types.NullInt{Value: 0, IsSet: false}}
})

It("displays all deployed revisions", func() {
Expect(executeErr).ToNot(HaveOccurred())

Expect(testUI.Out).To(Say(`Showing revisions for app some-app in org some-org / space some-space as banana...`))
Expect(testUI.Out).To(Say(`revision: 3`))
Expect(testUI.Out).To(Say(`deployed: true`))
Expect(testUI.Out).To(Say(`description: On a different note`))
Expect(testUI.Out).To(Say(`deployable: true`))
Expect(testUI.Out).To(Say(`revision GUID: A68F13F7-7E5E-4411-88E8-1FAC54F73F50`))
Expect(testUI.Out).To(Say(`droplet GUID: droplet-guid`))
Expect(testUI.Out).To(Say(`created on: 2020-03-10T17:11:58Z`))

Expect(testUI.Out).To(Say(`labels:`))
Expect(testUI.Out).To(Say(`label: foo3`))

Expect(testUI.Out).To(Say(`annotations:`))
Expect(testUI.Out).To(Say(`annotation: foo3`))

Expect(testUI.Out).To(Say(`application environment variables:`))
Expect(testUI.Out).To(Say(`foo: bar3`))

Expect(testUI.Out).To(Say(`revision: 2`))
Expect(testUI.Out).To(Say(`deployed: true`))
Expect(testUI.Out).To(Say(`description: Something else`))
Expect(testUI.Out).To(Say(`deployable: true`))
Expect(testUI.Out).To(Say(`revision GUID: A89F8259-D32B-491A-ABD6-F100AC42D74C`))
Expect(testUI.Out).To(Say(`droplet GUID: droplet-guid2`))
Expect(testUI.Out).To(Say(`created on: 2020-03-08T12:43:30Z`))

Expect(testUI.Out).To(Say(`labels:`))
Expect(testUI.Out).To(Say(`annotations:`))
Expect(testUI.Out).To(Say(`application environment variables:`))
Expect(testUI.Out).To(Say(`foo: bar3`))
})
})

When("there are no revisions available", func() {
BeforeEach(func() {
revision := resources.Revision{
Version: 120,
}
cmd.Version = flag.Revision{NullInt: types.NullInt{Value: 120, IsSet: true}}
fakeActor.GetRevisionByApplicationAndVersionReturns(
revision,
nil,
Expand Down
40 changes: 20 additions & 20 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,55 @@ module code.cloudfoundry.org/cli
go 1.23.1

require (
code.cloudfoundry.org/bytefmt v0.21.0
code.cloudfoundry.org/bytefmt v0.25.0
code.cloudfoundry.org/cfnetworking-cli-api v0.0.0-20190103195135-4b04f26287a6
code.cloudfoundry.org/cli-plugin-repo v0.0.0-20200304195157-af98c4be9b85
code.cloudfoundry.org/cli/integration/assets/hydrabroker v0.0.0-20201002233634-81722a1144e4
code.cloudfoundry.org/clock v1.24.0
code.cloudfoundry.org/clock v1.28.0
code.cloudfoundry.org/diego-ssh v0.0.0-20230810200140-af9d79fe9c82
code.cloudfoundry.org/go-log-cache/v2 v2.0.7
code.cloudfoundry.org/go-loggregator/v9 v9.2.1
code.cloudfoundry.org/gofileutils v0.0.0-20170111115228-4d0c80011a0f
code.cloudfoundry.org/jsonry v1.1.4
code.cloudfoundry.org/lager/v3 v3.18.0
code.cloudfoundry.org/tlsconfig v0.12.0
code.cloudfoundry.org/lager/v3 v3.22.0
code.cloudfoundry.org/tlsconfig v0.15.0
code.cloudfoundry.org/ykk v0.0.0-20170424192843-e4df4ce2fd4d
github.com/SermoDigital/jose v0.9.2-0.20161205224733-f6df55f235c2
github.com/blang/semver/v4 v4.0.0
github.com/cloudfoundry/bosh-cli v6.4.1+incompatible
github.com/creack/pty v1.1.24
github.com/cyphar/filepath-securejoin v0.3.5
github.com/cyphar/filepath-securejoin v0.4.0
github.com/distribution/reference v0.6.0
github.com/fatih/color v1.18.0
github.com/google/go-querystring v1.1.0
github.com/jessevdk/go-flags v1.6.1
github.com/lunixbochs/vtclean v1.0.0
github.com/mattn/go-colorable v0.1.13
github.com/mattn/go-colorable v0.1.14
github.com/mattn/go-runewidth v0.0.16
github.com/maxbrunsfeld/counterfeiter/v6 v6.10.0
github.com/moby/term v0.5.0
github.com/maxbrunsfeld/counterfeiter/v6 v6.11.2
github.com/moby/term v0.5.2
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d
github.com/onsi/ginkgo/v2 v2.22.0
github.com/onsi/gomega v1.36.1
github.com/onsi/ginkgo/v2 v2.22.2
github.com/onsi/gomega v1.36.2
github.com/pkg/errors v0.9.1
github.com/sabhiram/go-gitignore v0.0.0-20171017070213-362f9845770f
github.com/sajari/fuzzy v1.0.0
github.com/sirupsen/logrus v1.9.3
github.com/tedsuo/rata v1.0.1-0.20170830210128-07d200713958
github.com/vito/go-interact v0.0.0-20171111012221-fa338ed9e9ec
golang.org/x/crypto v0.31.0
golang.org/x/net v0.32.0
golang.org/x/term v0.27.0
golang.org/x/crypto v0.32.0
golang.org/x/net v0.34.0
golang.org/x/term v0.28.0
golang.org/x/text v0.21.0
gopkg.in/cheggaaa/pb.v1 v1.0.28
gopkg.in/yaml.v2 v2.4.0
k8s.io/apimachinery v0.32.0
k8s.io/client-go v0.32.0
k8s.io/apimachinery v0.32.1
k8s.io/client-go v0.32.1
)

require (
code.cloudfoundry.org/inigo v0.0.0-20230612153013-b300679e6ed6 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c // indirect
github.com/bmatcuk/doublestar v1.3.4 // indirect
github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40 // indirect
github.com/charlievieth/fs v0.0.3 // indirect
Expand All @@ -65,7 +65,7 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20241206021119-61a79c692802 // indirect
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kr/pty v1.1.8 // indirect
Expand All @@ -81,14 +81,14 @@ require (
golang.org/x/mod v0.22.0 // indirect
golang.org/x/oauth2 v0.23.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/time v0.7.0 // indirect
golang.org/x/tools v0.28.0 // indirect
golang.org/x/tools v0.29.0 // indirect
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240415180920-8c6c420018be // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.35.1 // indirect
google.golang.org/protobuf v1.36.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
Expand Down
Loading

0 comments on commit 0f9f273

Please sign in to comment.