Skip to content

Commit

Permalink
fix: adds blueprint metadata path to errors (#1821)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrew Peabody <[email protected]>
  • Loading branch information
g-awmalik and apeabody authored Sep 11, 2023
1 parent 04a0798 commit c72544f
Show file tree
Hide file tree
Showing 6 changed files with 240 additions and 301 deletions.
2 changes: 1 addition & 1 deletion cli/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
SHELL := /bin/bash

# Changing this value will trigger a new release
VERSION=v1.2.5
VERSION=v1.2.6
BINARY=bin/cft
GITHUB_REPO=github.com/GoogleCloudPlatform/cloud-foundation-toolkit
PLATFORMS := linux windows darwin
Expand Down
14 changes: 7 additions & 7 deletions cli/bpmetadata/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"

"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/cli/util"
goyaml "github.com/goccy/go-yaml"
"github.com/itchyny/json2yaml"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"google.golang.org/protobuf/encoding/protojson"
Expand Down Expand Up @@ -121,7 +121,8 @@ func generate(cmd *cobra.Command, args []string) error {

err = generateMetadataForBpPath(modPath)
if err != nil {
errors = append(errors, err.Error())
e := fmt.Sprintf("path: %s\n %s", modPath, err.Error())
errors = append(errors, e)
}
}

Expand Down Expand Up @@ -419,14 +420,13 @@ func WriteMetadata(obj *BlueprintMetadata, bpPath, fileName string) error {
return err
}

// convert json bytes to yaml bytes for before writing to disk
// using go-yaml package here since that preserves the order of fields
yBytes, err := goyaml.JSONToYAML(jBytes)
if err != nil {
input := strings.NewReader(string(jBytes))
var output strings.Builder
if err := json2yaml.Convert(&output, input); err != nil {
return err
}

return os.WriteFile(path.Join(bpPath, fileName), yBytes, 0644)
return os.WriteFile(path.Join(bpPath, fileName), []byte(output.String()), 0644)
}

func UnmarshalMetadata(bpPath, fileName string) (*BlueprintMetadata, error) {
Expand Down
Loading

0 comments on commit c72544f

Please sign in to comment.