Skip to content

Commit

Permalink
Logging improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
leocomelli committed Jun 6, 2022
1 parent ae98102 commit 3adbf95
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
16 changes: 14 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ package main

import (
"flag"
"log"
"fmt"

"go.uber.org/zap"
)

var (
logger, _ = zap.NewProduction()

providers = map[string]SecretProvider{
"gcp": &GCPSecretManager{},
}
Expand Down Expand Up @@ -36,7 +40,15 @@ type Options struct {
Output string
}

func (o *Options) String() string {
return fmt.Sprintf(
"provider: %s, project: %s, filter: %s, parser: %s, template: %s, output: %s",
o.Provider, o.Project, o.Filter, o.Parser, o.Template, o.Output,
)
}

func main() {

options := &Options{}

flag.StringVar(&options.Provider, "provider", "gcp", "name of the provider that manages the secrets")
Expand All @@ -56,6 +68,6 @@ func main() {

err := Run(options)
if err != nil {
log.Fatal(err)
logger.Fatal("error getting the secrets", zap.Error(err))
}
}
4 changes: 3 additions & 1 deletion parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package main
import (
"encoding/json"
"fmt"

"go.uber.org/zap"
)

// ContentParser defines secret content parser behaviors
Expand Down Expand Up @@ -34,7 +36,7 @@ type JSONContentParser struct {
func (j *JSONContentParser) Parse(s *SecretData) []*SecretData {
m := map[string]interface{}{}
if err := json.Unmarshal([]byte(s.Data), &m); err != nil {
fmt.Printf("\nWARN: [%s] invalid json\n", s.Name)
logger.Warn("invalid json", zap.String("name", s.Name))
}

var secrets []*SecretData
Expand Down
6 changes: 6 additions & 0 deletions runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package main
import (
"errors"
"os"

"go.uber.org/zap"
)

var (
Expand Down Expand Up @@ -32,6 +34,8 @@ func Run(options *Options) error {

}

logger.Info("using options", zap.Any("values", options))

if err := provider.Init(); err != nil {
return err
}
Expand All @@ -41,6 +45,8 @@ func Run(options *Options) error {
return err
}

logger.Info("secrets found", zap.Int("len", len(data)))

output := os.Stdin
if options.Output != "" {
output, err = os.Create(options.Output)
Expand Down

0 comments on commit 3adbf95

Please sign in to comment.