Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into ryanking/output_flags
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanking committed Jul 16, 2018
2 parents c669d45 + f6a92c1 commit d6e14e2
Show file tree
Hide file tree
Showing 24 changed files with 42 additions and 5,262 deletions.
2 changes: 1 addition & 1 deletion .gometalinter.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"Exclude": [
"exported (\\w+) (\\w+) should have comment or be unexported"
"exported (\\w+) ([\\w\\.]+) should have comment or be unexported"
]
}
8 changes: 1 addition & 7 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 18 additions & 12 deletions apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ func Apply(fs afero.Fs, conf *config.Config, tmp *templates.T, siccMode bool) er

e = applyGlobal(fs, p.Global, &tmp.Global)
if e != nil {
return e
return errors.Wrap(e, "unable to apply global")
}

e = applyModules(fs, p.Modules, &tmp.Module)

return e
return errors.Wrap(e, "unable to apply modules")
}

func applyRepo(fs afero.Fs, p *plan.Plan, repoBox *packr.Box) error {
Expand All @@ -61,7 +61,7 @@ func applyGlobal(fs afero.Fs, p plan.Component, repoBox *packr.Box) error {
path := fmt.Sprintf("%s/global", rootPath)
e := fs.MkdirAll(path, 0755)
if e != nil {
return e
return errors.Wrapf(e, "unable to make directory %s", path)
}
return applyTree(repoBox, afero.NewBasePathFs(fs, path), p.SiccMode, p)
}
Expand All @@ -87,11 +87,11 @@ func applyModules(fs afero.Fs, p map[string]plan.Module, moduleBox *packr.Box) e
path := fmt.Sprintf("%s/modules/%s", rootPath, module)
e = fs.MkdirAll(path, 0755)
if e != nil {
return e
return errors.Wrapf(e, "unable to make path %s", path)
}
e = applyTree(moduleBox, afero.NewBasePathFs(fs, path), modulePlan.SiccMode, modulePlan)
if e != nil {
return e
return errors.Wrap(e, "unable to apply tree")
}
}
return nil
Expand All @@ -102,7 +102,7 @@ func applyEnvs(fs afero.Fs, p *plan.Plan, envBox *packr.Box, componentBox *packr
path := fmt.Sprintf("%s/envs/%s", rootPath, env)
e = fs.MkdirAll(path, 0755)
if e != nil {
return errors.Wrap(e, "unable to make directies for envs")
return errors.Wrapf(e, "unable to make directory %s", path)
}
e := applyTree(envBox, afero.NewBasePathFs(fs, path), envPlan.SiccMode, envPlan)
if e != nil {
Expand Down Expand Up @@ -147,7 +147,7 @@ func applyTree(source *packr.Box, dest afero.Fs, siccMode bool, subst interface{

e = touchFile(dest, target)
if e != nil {
return e
return errors.Wrapf(e, "unable to touch file %s", target)
}

} else if extension == ".create" {
Expand Down Expand Up @@ -188,11 +188,11 @@ func applyTree(source *packr.Box, dest afero.Fs, siccMode bool, subst interface{
func fmtHcl(fs afero.Fs, path string) error {
in, e := afero.ReadFile(fs, path)
if e != nil {
return e
return errors.Wrapf(e, "unable to read file %s", path)
}
out, e := printer.Format(in)
if e != nil {
return e
return errors.Wrapf(e, "fmt hcl failed for %s", path)
}
return afero.WriteReader(fs, path, bytes.NewReader(out))
}
Expand Down Expand Up @@ -282,11 +282,11 @@ func applyModule(fs afero.Fs, path, mod string, box packr.Box) error {

e = applyTemplate(f, fs, filepath.Join(path, "main.tf"), &moduleData{moduleName, mod, variables, outputs})
if e != nil {
return e
return errors.Wrap(e, "unable to apply template for main.tf")
}
e = fmtHcl(fs, filepath.Join(path, "main.tf"))
if e != nil {
return e
return errors.Wrap(e, "unable to format main.tf")
}

f, e = box.Open("outputs.tf.tmpl")
Expand All @@ -296,9 +296,15 @@ func applyModule(fs afero.Fs, path, mod string, box packr.Box) error {

e = applyTemplate(f, fs, filepath.Join(path, "outputs.tf"), &moduleData{moduleName, mod, variables, outputs})
if e != nil {
return e
return errors.Wrap(e, "unable to apply template for outputs.tf")
}

// TODO
// e = fmtHcl(fs, filepath.Join(path, "outputs.tf"))
// if e != nil {
// return errors.Wrap(e, "unable to format outputs.tf")
// }

return nil
}

Expand Down
11 changes: 7 additions & 4 deletions cmd/util.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package cmd

import (
"fmt"
"log"
"os"
"strings"

"github.com/chanzuckerberg/fogg/config"
"github.com/go-playground/validator"
log "github.com/sirupsen/logrus"
"github.com/spf13/afero"
validator "gopkg.in/go-playground/validator.v9"
git "gopkg.in/src-d/go-git.v4"
)

Expand Down Expand Up @@ -36,11 +38,12 @@ func readAndValidateConfig(fs afero.Fs, configFile string, verbose bool) (*confi

func exitOnConfigErrors(err error) {
if err != nil {
log.Error("Config Error(s):")
fmt.Println("fogg.json has error(s):")
errs, ok := err.(validator.ValidationErrors)
if ok {
for _, err := range errs {
log.Error("\t%s is a %s %s\n", err.Namespace(), err.Tag(), err.Kind())
msg := fmt.Sprintf("\t%s is a %s %s", err.Namespace(), err.Tag(), err.Kind())
fmt.Println(strings.Replace(msg, "Config.", "", 1))
}
} else {
log.Panic(err)
Expand Down
11 changes: 11 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"encoding/json"
"io"
"io/ioutil"
"reflect"
"strings"

"github.com/pkg/errors"
"github.com/spf13/afero"
Expand Down Expand Up @@ -145,5 +147,14 @@ func FindAndReadConfig(fs afero.Fs, configFile string) (*Config, error) {

func (c *Config) Validate() error {
v := validator.New()
// https://github.com/go-playground/validator/issues/323#issuecomment-343670840
v.RegisterTagNameFunc(func(fld reflect.StructField) string {
name := strings.SplitN(fld.Tag.Get("json"), ",", 2)[0]

if name == "-" {
return ""
}
return name
})
return v.Struct(c)
}
3 changes: 2 additions & 1 deletion plan/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/chanzuckerberg/fogg/config"
"github.com/chanzuckerberg/fogg/util"
"github.com/pkg/errors"
)

type account struct {
Expand Down Expand Up @@ -84,7 +85,7 @@ func Eval(config *config.Config, siccMode, verbose bool) (*Plan, error) {
p := &Plan{}
v, e := util.VersionString()
if e != nil {
return nil, e
return nil, errors.Wrap(e, "unable to parse fogg version")
}
p.Version = v
p.SiccMode = siccMode
Expand Down
2 changes: 1 addition & 1 deletion util/debugging.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package util
import log "github.com/sirupsen/logrus"

func Dump(foo interface{}) {
log.Printf("%#v\n", foo)
log.Debugf("%#v\n", foo)
}
2 changes: 1 addition & 1 deletion util/module_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func DownloadModule(cacheDir, source string) (string, error) {

e = storage.Get(hash, s, false)
if e != nil {
return "", e
return "", errors.Wrap(e, "unable to read module from local storage")
}
d, _, e := storage.Dir(hash)
if e != nil {
Expand Down
29 changes: 0 additions & 29 deletions vendor/github.com/go-playground/validator/.gitignore

This file was deleted.

22 changes: 0 additions & 22 deletions vendor/github.com/go-playground/validator/LICENSE

This file was deleted.

16 changes: 0 additions & 16 deletions vendor/github.com/go-playground/validator/Makefile

This file was deleted.

Loading

0 comments on commit d6e14e2

Please sign in to comment.