Skip to content

Commit

Permalink
Added logging of identified bindings & fixed bug which created bindin…
Browse files Browse the repository at this point in the history
…gs from hidden files/dirs

Signed-off-by: David O'Sullivan <davidos@vmware.com>
  • Loading branch information
pivotal-david-osullivan committed Sep 24, 2021
1 parent 3a76485 commit afb92db
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/pipeline-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.10.2
1.10.5
30 changes: 29 additions & 1 deletion build.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"os"
"path/filepath"
"reflect"
"sort"
"strings"

"github.com/BurntSushi/toml"
Expand Down Expand Up @@ -183,7 +184,6 @@ func Build(builder Builder, options ...Option) {
config.exitHandler.Error(fmt.Errorf("unable to read platform bindings %s\n%w", ctx.Platform.Path, err))
return
}
logger.Debugf("Platform Bindings: %+v", ctx.Platform.Bindings)

file = filepath.Join(ctx.Platform.Path, "env")
if ctx.Platform.Environment, err = internal.NewConfigMapFromPath(file); err != nil {
Expand Down Expand Up @@ -364,6 +364,34 @@ func Build(builder Builder, options ...Option) {
return
}
}
logBindings(ctx.Platform.Bindings, logger)
}

func logBindings(bindings Bindings, logger poet.Logger) {
numBindings := len(bindings)
if numBindings > 0 {
if numBindings == 1 {
logger.Info("\n1 Binding Identified:")
} else {
logger.Infof("\n%d Bindings Identified:", numBindings)
}
var s []string
for _, binding := range bindings {
for k := range binding.Secret {
s = append(s, k)
}
sort.Strings(s)
logger.Infof(" Name: %s", binding.Name)
if len(s) > 0 {
logger.Infof(" Keys: %s", strings.Join(s, ", "))
} else {
logger.Infof(" Keys: None")
}
s = nil
}
} else {
logger.Infof("No Platform Bindings Identified")
}
}

func contains(candidates []string, s string) bool {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/buildpacks/libcnb
go 1.15

require (
github.com/BurntSushi/toml v0.3.1
github.com/onsi/gomega v1.14.0
github.com/BurntSushi/toml v0.4.1
github.com/onsi/gomega v1.16.0
github.com/sclevine/spec v1.4.0
github.com/stretchr/testify v1.7.0
)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/toml v0.4.1 h1:GaI7EiDXDRfa8VshkTj7Fym7ha+y8/XxIgD2okUIjLw=
github.com/BurntSushi/toml v0.4.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -32,8 +32,8 @@ github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc=
github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.14.0 h1:ep6kpPVwmr/nTbklSx2nrLNSIO62DoYAhnPNIMhK8gI=
github.com/onsi/gomega v1.14.0/go.mod h1:cIuvLEne0aoVhAgh/O6ac0Op8WWw9H6eYCriF+tEHG0=
github.com/onsi/gomega v1.16.0 h1:6gjqkI8iiRHMvdccRJM8rVKjCWk6ZIm6FTm3ddIe4/c=
github.com/onsi/gomega v1.16.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sclevine/spec v1.4.0 h1:z/Q9idDcay5m5irkZ28M7PtQM4aOISzOpj4bUPkDee8=
Expand Down
4 changes: 4 additions & 0 deletions platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ func NewBindingsFromPath(path string) (Bindings, error) {

bindings := Bindings{}
for _, file := range files {
if strings.HasPrefix(filepath.Base(file), ".") {
// ignore hidden files
continue
}
binding, err := NewBindingFromPath(file)
if err != nil {
return nil, fmt.Errorf("unable to create new binding from %s\n%w", file, err)
Expand Down
8 changes: 8 additions & 0 deletions platform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ func testPlatform(t *testing.T, context spec.G, it spec.S) {
Expect(os.MkdirAll(filepath.Join(path, "bravo", "secret"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "bravo", "secret", "test-secret-key"), []byte("test-secret-value"), 0600)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "bravo", "secret", "test-secret-key-trimmed"), []byte(" test-secret-value-trimmed \n"), 0600)).To(Succeed())

Expect(os.MkdirAll(filepath.Join(path, ".hidden", "metadata"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, ".hidden", "metadata", "kind"), []byte("test-kind"), 0600)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, ".hiddenFile"), []byte("test-kind"), 0600)).To(Succeed())
})

context("Binding", func() {
Expand Down Expand Up @@ -205,6 +209,10 @@ func testPlatform(t *testing.T, context spec.G, it spec.S) {
Expect(ioutil.WriteFile(filepath.Join(path, "bravo", "type"), []byte("test-type"), 0600)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "bravo", "provider"), []byte("test-provider"), 0600)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "bravo", "test-secret-key"), []byte("test-secret-value"), 0600)).To(Succeed())

Expect(os.MkdirAll(filepath.Join(path, ".hidden", "metadata"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, ".hidden", "metadata", "kind"), []byte("test-kind"), 0600)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, ".hiddenFile"), []byte("test-kind"), 0600)).To(Succeed())
})

context("Binding", func() {
Expand Down

0 comments on commit afb92db

Please sign in to comment.