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

Added logging of bindings & fixed bindings bug #75

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
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)
pivotal-david-osullivan marked this conversation as resolved.
Show resolved Hide resolved
}

func logBindings(bindings Bindings, logger poet.Logger) {
numBindings := len(bindings)
if numBindings > 0 {
if numBindings == 1 {
logger.Info("\n1 Binding Identified:")
pivotal-david-osullivan marked this conversation as resolved.
Show resolved Hide resolved
} 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")
pivotal-david-osullivan marked this conversation as resolved.
Show resolved Hide resolved
}
s = nil
}
} else {
logger.Infof("No Platform Bindings Identified")
pivotal-david-osullivan marked this conversation as resolved.
Show resolved Hide resolved
}
}

func contains(candidates []string, s string) bool {
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