Skip to content

Commit

Permalink
better output
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesWoolfenden committed Jul 25, 2024
1 parent 68b797c commit 978e13e
Show file tree
Hide file tree
Showing 26 changed files with 133 additions and 92 deletions.
38 changes: 0 additions & 38 deletions .depguard.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ repos:
hooks:
- id: golangci-lint
- repo: https://github.com/bridgecrewio/checkov
rev: 3.2.194
rev: 3.2.205
hooks:
- id: checkov
language_version: python3.11
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ require (
github.com/hashicorp/terraform-exec v0.17.3
github.com/rs/zerolog v1.33.0
github.com/stretchr/testify v1.7.0
github.com/urfave/cli/v2 v2.27.2
golang.org/x/exp v0.0.0-20240716175740-e3f259677ff7
github.com/urfave/cli/v2 v2.27.3
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
)

require (
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/urfave/cli/v2 v2.27.2 h1:6e0H+AkS+zDckwPCUrZkKX38mRaau4nL2uipkJpbkcI=
github.com/urfave/cli/v2 v2.27.2/go.mod h1:g0+79LmHHATl7DAcHO99smiR/T7uGLw84w8Y42x+4eM=
github.com/urfave/cli/v2 v2.27.3 h1:/POWahRmdh7uztQ3CYnaDddk0Rm90PyOgIxgW2rr41M=
github.com/urfave/cli/v2 v2.27.3/go.mod h1:m4QzxcD2qpra4z7WhzEGn74WZLViBnMpb1ToCAKdGRQ=
github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4=
github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI=
Expand All @@ -149,8 +149,8 @@ golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/exp v0.0.0-20240716175740-e3f259677ff7 h1:wDLEX9a7YQoKdKNQt88rtydkqDxeGaBUTnIYc3iG/mA=
golang.org/x/exp v0.0.0-20240716175740-e3f259677ff7/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
golang.org/x/net v0.0.0-20180811021610-c39426892332/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
Expand Down
13 changes: 6 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import (
_ "embed" // required for embed
"fmt"
"os"
"sort"
"time"

"sato/src/version"

"sato/src/arm"
"sato/src/cf"
"sato/src/see"
"sato/src/version"
"sort"
"time"

"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -40,7 +38,7 @@ func main() {
Action: func(*cli.Context) error {
err := cf.Parse(file, destination)
if err != nil {
log.Error().Err(err)
log.Info().Msgf(err.Error())
}

return nil
Expand Down Expand Up @@ -80,7 +78,7 @@ func main() {
Action: func(*cli.Context) error {
err := arm.Parse(file, destination)
if err != nil {
return fmt.Errorf("bisect failure: %w", err)
log.Info().Msgf(err.Error())
}

return nil
Expand Down Expand Up @@ -113,6 +111,7 @@ func main() {
}

fmt.Print(*result)

fmt.Print("\n")

return err
Expand Down
4 changes: 2 additions & 2 deletions src/arm/data_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package arm_test

import (
"sato/src/arm"
"testing"
"text/template"

"sato/src/arm"
)

func Test_parseData(t *testing.T) {
Expand Down Expand Up @@ -44,6 +43,7 @@ func Test_parseData(t *testing.T) {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

if err := arm.ParseData(tt.args.result, tt.args.funcMap, tt.args.destination); (err != nil) != tt.wantErr {
t.Errorf("ParseData() error = %v, wantErr %v", err, tt.wantErr)
}
Expand Down
12 changes: 8 additions & 4 deletions src/arm/helpers.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package arm

import (
"errors"
"fmt"
"regexp"
"sort"
Expand Down Expand Up @@ -54,13 +53,14 @@ func FixType(myItem map[string]interface{}) (map[string]interface{}, error) {
myType, ok := myItem["type"].(string)

if !ok {
return myItem, errors.New("type is not string")
return myItem, &castError{Type: "string"}
}

switch myType {
case "object":
{
var types string

var result string

defaultValue, ok := myItem["defaultValue"].(map[string]interface{})
Expand All @@ -73,12 +73,15 @@ func FixType(myItem map[string]interface{}) (map[string]interface{}, error) {
case []interface{}:
{
var temp string

var temptTypes string

var myType string

for _, y := range item {
y, ok := y.(map[string]interface{})
if !ok {
return myItem, errors.New("failed to assert (map[string]interface{}")
return myItem, &castError{Type: "map[string]interface{}"}
}

for name, value := range y {
Expand All @@ -89,6 +92,7 @@ func FixType(myItem map[string]interface{}) (map[string]interface{}, error) {
temp = "{\n" + strings.TrimSuffix(temp, "\n") + "}"
temptTypes = "{\n" + strings.TrimSuffix(myType, "\n") + "}"
}

if result != "" {
result += "," + name + "= [" + temp + "]"
types += "," + name + "= list(object(" + temptTypes + "))"
Expand Down Expand Up @@ -242,7 +246,7 @@ func LoseSQBrackets(newAttribute string) string {
return newAttribute
}

// Ditch helps to drop functions for arm.
// Ditch helps to drop functions for ARM.
func Ditch(attribute string, ditch string) string {
splitter := strings.SplitN(attribute, ditch+"(", 2)

Expand Down
6 changes: 4 additions & 2 deletions src/arm/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package arm_test

import (
"reflect"
"testing"

"sato/src/arm"
"testing"
)

func TestIsLocal(t *testing.T) {
Expand Down Expand Up @@ -40,6 +39,7 @@ func TestIsLocal(t *testing.T) {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

if got := arm.IsLocal(tt.args.target, tt.args.result); got != tt.want {
t.Errorf("IsLocal() = %v, want %v", got, tt.want)
}
Expand Down Expand Up @@ -103,6 +103,7 @@ func Test_contains(t *testing.T) {
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("Contains() got = %v, want %v", got, tt.want)
}

if got1 != tt.want1 {
t.Errorf("Contains() got1 = %v, want %v", got1, tt.want1)
}
Expand Down Expand Up @@ -384,6 +385,7 @@ func Test_ditch(t *testing.T) {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

if got := arm.Ditch(tt.args.Attribute, tt.args.name); got != tt.want {
t.Errorf("Ditch() = %v, want %v", got, tt.want)
}
Expand Down
1 change: 1 addition & 0 deletions src/arm/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func lookup(myType string) []byte {

var myContent []byte

//goland:noinspection GoLinter
var ok bool

myType = strings.ToLower(strings.TrimSuffix(myType, "/"))
Expand Down
1 change: 1 addition & 0 deletions src/arm/lookup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func Test_lookup(t *testing.T) {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

if got := lookup(tt.args.myType); !reflect.DeepEqual(got, tt.want) {
t.Errorf("lookup() = %v, want %v", got, tt.want)
}
Expand Down
7 changes: 3 additions & 4 deletions src/arm/outputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ package arm

import (
"bytes"
"errors"
"fmt"
"log"
tftemplate "text/template"

"sato/src/cf"
tftemplate "text/template"
)

// ParseOutputs writes out to outputs.tf.
Expand All @@ -17,8 +15,9 @@ func ParseOutputs(result map[string]interface{}, funcMap tftemplate.FuncMap, des
}

outputs, ok := result["outputs"].(map[string]interface{})

if !ok {
return errors.New("failed to assert to map[string]interface{}")
return &castError{"map[string]interface{}"}
}

var All string
Expand Down
6 changes: 3 additions & 3 deletions src/arm/outputs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package arm_test

import (
"encoding/json"
"sato/src/arm"
"sato/src/cf"
"strings"
"testing"
"text/template"

"sato/src/arm"
"sato/src/cf"
)

var badFunk template.FuncMap
Expand Down Expand Up @@ -83,6 +82,7 @@ func Test_parseOutputs(t *testing.T) {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

if err := arm.ParseOutputs(tt.args.result, tt.args.funcMap, tt.args.destination); (err != nil) != tt.wantErr {
t.Errorf("ParseOutputs() error = %v, wantErr %v", err, tt.wantErr)
}
Expand Down
16 changes: 14 additions & 2 deletions src/arm/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,30 @@ import (
"github.com/rs/zerolog/log"
)

type castError struct {
Type string
}

func (m *castError) Error() string {
return fmt.Sprintf("failed to cast to %s", m.Type)
}

func parseParameters(result map[string]interface{}, funcMap tftemplate.FuncMap, all string) (string, []interface{}, error) {
parameters, ok := result["parameters"].(map[string]interface{})
if !ok {
return "", nil, fmt.Errorf("failed to cast to map")
return "", nil, &castError{Type: "map[string]interface{}"}
}

myVariables := make([]interface{}, 0)

var err error

for name, item := range parameters {
myItem := item.(map[string]interface{})
myItem, ok := item.(map[string]interface{})

if !ok {
return "", nil, &castError{Type: "map[string]interface{}"}
}

myItem, err = FixType(myItem)
if err != nil {
Expand Down
Loading

0 comments on commit 978e13e

Please sign in to comment.