Skip to content

Commit

Permalink
Add support for providing credentials for Cloud Native Buildpacks
Browse files Browse the repository at this point in the history
Co-authored-by: Pavel Busko <pavel.busko@sap.com>
Co-authored-by: Nicolas Bender <nicolas.bender@sap.com>
  • Loading branch information
nicolasbender and pbusko committed Jul 26, 2024
1 parent 759f79d commit 0bdafee
Show file tree
Hide file tree
Showing 17 changed files with 528 additions and 173 deletions.
1 change: 1 addition & 0 deletions actor/v7action/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func (actor Actor) CreateApplicationInSpace(app resources.Application, spaceGUID
LifecycleBuildpacks: app.LifecycleBuildpacks,
StackName: app.StackName,
Name: app.Name,
Credentials: app.Credentials,
SpaceGUID: spaceGUID,
})

Expand Down
1 change: 1 addition & 0 deletions actor/v7pushaction/actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func NewActor(v3Actor V7Actor, sharedActor SharedActor) *Actor {

HandleInstancesOverride,
HandleStartCommandOverride,
HandleCNBCredentialsOverride,

HandleLifecycleOverride,

Expand Down
4 changes: 4 additions & 0 deletions actor/v7pushaction/create_push_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ func (actor Actor) CreatePushPlans(
plan.Application.LifecycleType = overrides.Lifecycle
}

if overrides.CNBCredentials != nil {
plan.Application.Credentials = overrides.CNBCredentials
}

if manifestApplication.Docker != nil {
plan.DockerImageCredentials = v7action.DockerImageCredentials{
Path: manifestApplication.Docker.Image,
Expand Down
6 changes: 6 additions & 0 deletions actor/v7pushaction/create_push_plans_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ var _ = Describe("CreatePushPlans", func() {
spaceGUID = "space"
flagOverrides = FlagOverrides{
DockerPassword: "passwd",
CNBCredentials: map[string]interface{}{
"foo": "bar",
},
}

testUpdatePlanCount = 0
Expand Down Expand Up @@ -121,6 +124,9 @@ var _ = Describe("CreatePushPlans", func() {
Expect(pushPlans[0].DockerImageCredentials.Password).To(Equal(""))
Expect(pushPlans[0].BitsPath).To(Equal("path1"))
Expect(pushPlans[0].Application.LifecycleType).To(BeEquivalentTo("cnb"))
Expect(pushPlans[0].Application.Credentials).To(Equal(map[string]interface{}{
"foo": "bar",
}))
Expect(pushPlans[1].Application.Name).To(Equal("name-2"))
Expect(pushPlans[1].Application.GUID).To(Equal("app-guid-2"))
Expect(pushPlans[1].SpaceGUID).To(Equal(spaceGUID))
Expand Down
24 changes: 24 additions & 0 deletions actor/v7pushaction/handle_cnb_credentials_override.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package v7pushaction

import (
"code.cloudfoundry.org/cli/command/translatableerror"
"code.cloudfoundry.org/cli/util/manifestparser"
)

func HandleCNBCredentialsOverride(manifest manifestparser.Manifest, overrides FlagOverrides) (manifestparser.Manifest, error) {
if overrides.CNBCredentials != nil {
if manifest.ContainsMultipleApps() {
return manifest, translatableerror.CommandLineArgsWithMultipleAppsError{}
}

app := manifest.GetFirstApp()

if app.RemainingManifestFields == nil {
app.RemainingManifestFields = map[string]interface{}{}
}

app.RemainingManifestFields["cnb-credentials"] = overrides.CNBCredentials
}

return manifest, nil
}
65 changes: 65 additions & 0 deletions actor/v7pushaction/handle_cnb_credentials_override_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package v7pushaction_test

import (
. "code.cloudfoundry.org/cli/actor/v7pushaction"
"code.cloudfoundry.org/cli/util/manifestparser"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var _ = Describe("HandleCNBCredentialsOverride", func() {
var (
originalManifest manifestparser.Manifest
transformedManifest manifestparser.Manifest
overrides FlagOverrides
executeErr error
)

BeforeEach(func() {
originalManifest = manifestparser.Manifest{
Applications: []manifestparser.Application{{}},
}
overrides = FlagOverrides{}
})

JustBeforeEach(func() {
transformedManifest, executeErr = HandleCNBCredentialsOverride(originalManifest, overrides)
})

When("the cnb credentials are present", func() {
BeforeEach(func() {
overrides.CNBCredentials = map[string]interface{}{
"foo": "bar",
}
})

It("add it to the raw manifest", func() {
Expect(executeErr).NotTo(HaveOccurred())
Expect(transformedManifest).To(Equal(manifestparser.Manifest{
Applications: []manifestparser.Application{{
RemainingManifestFields: map[string]interface{}{
"cnb-credentials": map[string]interface{}{
"foo": "bar",
},
},
}},
}))
})

})

When("the credentials are not present", func() {
BeforeEach(func() {
overrides.CNBCredentials = nil
})
It("does not add it to the raw manifest", func() {
Expect(executeErr).NotTo(HaveOccurred())
Expect(transformedManifest).To(Equal(manifestparser.Manifest{
Applications: []manifestparser.Application{{}},
}))

})

})
})
1 change: 1 addition & 0 deletions actor/v7pushaction/push_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type FlagOverrides struct {
DockerImage string
DockerPassword string
DockerUsername string
CNBCredentials map[string]interface{}
HealthCheckEndpoint string
HealthCheckTimeout int64
HealthCheckType constant.HealthCheckType
Expand Down
Loading

0 comments on commit 0bdafee

Please sign in to comment.