From f1bd330b12ab0dc885935a6553cc2f78a503bae7 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 1 Dec 2020 12:59:50 -0800 Subject: [PATCH 1/2] internal/config: support waypoint.hcl.json for HCL-flavored JSON syntax The way we load (using the hclsimple package) will automatically use the JSON loader if it ends in ".json", we just never accepted ".json" before. --- internal/config/path.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/internal/config/path.go b/internal/config/path.go index 53954c904ee..300382e1b60 100644 --- a/internal/config/path.go +++ b/internal/config/path.go @@ -29,6 +29,7 @@ func FindPath(start, filename string) (string, error) { } for { + // Look for HCL syntax path := filepath.Join(start, filename) if _, err := os.Stat(path); err == nil { return path, nil @@ -36,6 +37,14 @@ func FindPath(start, filename string) (string, error) { return "", err } + // Look for JSON + path += ".json" + if _, err := os.Stat(path); err == nil { + return path, nil + } else if !os.IsNotExist(err) { + return "", err + } + next := filepath.Dir(start) if next == start { return "", nil From 6ad34b74cd92037914e630251fd38cc80d15ab45 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 1 Dec 2020 13:11:25 -0800 Subject: [PATCH 2/2] internal: runners need to use configpkg.FindPath --- internal/cli/base_init.go | 2 +- internal/config/path.go | 10 +++++++++- internal/runner/operation.go | 6 +++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/internal/cli/base_init.go b/internal/cli/base_init.go index 524cbc435dc..9816cf568f6 100644 --- a/internal/cli/base_init.go +++ b/internal/cli/base_init.go @@ -38,7 +38,7 @@ func (c *baseCommand) initConfig(optional bool) (*configpkg.Config, error) { // initConfigPath returns the configuration path to load. func (c *baseCommand) initConfigPath() (string, error) { - path, err := configpkg.FindPath("", "") + path, err := configpkg.FindPath("", "", true) if err != nil { return "", fmt.Errorf("Error looking for a Waypoint configuration: %s", err) } diff --git a/internal/config/path.go b/internal/config/path.go index 300382e1b60..c441a82d617 100644 --- a/internal/config/path.go +++ b/internal/config/path.go @@ -15,7 +15,11 @@ const Filename = "waypoint.hcl" // // If start is empty, start will be the current working directory. If // filename is empty, it will default to the Filename constant. -func FindPath(start, filename string) (string, error) { +// +// If searchParent is false, then we will not search parent directories +// and require the Waypoint configuration file be directly in the "start" +// directory. +func FindPath(start, filename string, searchParent bool) (string, error) { var err error if start == "" { start, err = os.Getwd() @@ -45,6 +49,10 @@ func FindPath(start, filename string) (string, error) { return "", err } + if !searchParent { + return "", nil + } + next := filepath.Dir(start) if next == start { return "", nil diff --git a/internal/runner/operation.go b/internal/runner/operation.go index aad66dfcfa7..5011f6b453b 100644 --- a/internal/runner/operation.go +++ b/internal/runner/operation.go @@ -31,9 +31,9 @@ func (r *Runner) executeJob( ) (*pb.Job_Result, error) { // Eventually we'll need to extract the data source. For now we're // just building for local exec so it is the working directory. - path := configpkg.Filename - if wd != "" { - path = filepath.Join(wd, path) + path, err := configpkg.FindPath(wd, "", false) + if err != nil { + return nil, err } // Determine the evaluation context we'll be using