Skip to content

Commit

Permalink
chore: Fix lint failures
Browse files Browse the repository at this point in the history
  • Loading branch information
bryantbiggs committed Feb 14, 2025
1 parent 04cb092 commit a965dbe
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ require (
golang.org/x/crypto v0.33.0
golang.org/x/oauth2 v0.25.0
golang.org/x/sync v0.11.0
golang.org/x/text v0.22.0
golang.org/x/tools v0.30.0
gopkg.in/yaml.v2 v2.4.0
helm.sh/helm/v3 v3.17.0
Expand Down Expand Up @@ -405,7 +406,6 @@ require (
golang.org/x/net v0.35.0 // indirect
golang.org/x/sys v0.30.0 // indirect
golang.org/x/term v0.29.0 // indirect
golang.org/x/text v0.22.0 // indirect
golang.org/x/time v0.8.0 // indirect
google.golang.org/api v0.215.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241223144023-3abc09e42ca8 // indirect
Expand Down
27 changes: 15 additions & 12 deletions pkg/goformation/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import (
"encoding/json"
"fmt"
"go/format"
"io/ioutil"
"io"
"net/http"
"net/url"
"os"
"sort"
"strings"
"text/template"

"golang.org/x/text/cases"
"golang.org/x/text/language"
)

// ResourceGenerator takes AWS CloudFormation Resource Specification
Expand Down Expand Up @@ -138,14 +141,14 @@ func (rg *ResourceGenerator) downloadSpec(location string) ([]byte, error) {
return nil, err
}

data, err := ioutil.ReadAll(response.Body)
data, err := io.ReadAll(response.Body)
if err != nil {
return nil, err
}

return data, nil
case "file":
data, err := ioutil.ReadFile(strings.Replace(location, "file://", "", -1))
data, err := os.ReadFile(strings.Replace(location, "file://", "", -1))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -242,7 +245,7 @@ func (rg *ResourceGenerator) generateAllResourcesMap(resources []GeneratedResour
}

// Write the file contents out
if err := ioutil.WriteFile("cloudformation/all.go", formatted, 0644); err != nil {
if err := os.WriteFile("cloudformation/all.go", formatted, 0644); err != nil {
return fmt.Errorf("failed to write Go file for iterable map of all resources: %s", err)
}

Expand Down Expand Up @@ -344,7 +347,7 @@ func (rg *ResourceGenerator) generateResources(name string, resource Resource, i
// Check if the file has changed since the last time generate ran
dir := "cloudformation/" + pname
fn := dir + "/" + filename(name)
current, err := ioutil.ReadFile(fn)
current, err := os.ReadFile(fn)

if err != nil || bytes.Compare(formatted, current) != 0 {

Expand All @@ -354,7 +357,7 @@ func (rg *ResourceGenerator) generateResources(name string, resource Resource, i
}

// Write the file contents out
if err := ioutil.WriteFile(fn, formatted, 0644); err != nil {
if err := os.WriteFile(fn, formatted, 0644); err != nil {
return fmt.Errorf("failed to write resource file %s: %s", fn, err)
}
// Log the updated resource name to the results
Expand Down Expand Up @@ -403,20 +406,20 @@ func (rg *ResourceGenerator) generateJSONSchema(specname string, spec *CloudForm
}

filename := fmt.Sprintf("schema/%s.schema.json", specname)
if err := ioutil.WriteFile(filename, formatted, 0644); err != nil {
if err := os.WriteFile(filename, formatted, 0644); err != nil {
return fmt.Errorf("failed to write JSON Schema: %s", err)
}

// Also create a Go importable version
var gocode []byte
gocode = append(gocode, []byte("package schema\n")...)
gocode = append(gocode, []byte("\n")...)
gocode = append(gocode, []byte("// "+strings.Title(specname)+"Schema defined a JSON Schema that can be used to validate CloudFormation/SAM templates\n")...)
gocode = append(gocode, []byte("var "+strings.Title(specname)+"Schema = `")...)
gocode = append(gocode, []byte("// "+cases.Title(language.Und, cases.NoLower).String(specname)+"Schema defined a JSON Schema that can be used to validate CloudFormation/SAM templates\n")...)
gocode = append(gocode, []byte("var "+cases.Title(language.Und, cases.NoLower).String(specname)+"Schema = `")...)
gocode = append(gocode, formatted...)
gocode = append(gocode, []byte("`\n")...)
gofilename := fmt.Sprintf("schema/%s.go", specname)
if err := ioutil.WriteFile(gofilename, gocode, 0644); err != nil {
if err := os.WriteFile(gofilename, gocode, 0644); err != nil {
return fmt.Errorf("failed to write Go version of JSON Schema: %s", err)
}

Expand All @@ -430,7 +433,7 @@ func generatePolymorphicProperty(typename string, name string, property Property

// Open the polymorphic property template
tmpl, err := template.New("polymorphic-property.template").Funcs(template.FuncMap{
"convertToGoType": convertTypeToGo,
"convertToGoType": convertTypeToGo,
"convertToPureGoType": convertTypeToPureGo,
}).ParseFiles("generate/templates/polymorphic-property.template")

Expand Down Expand Up @@ -485,7 +488,7 @@ func generatePolymorphicProperty(typename string, name string, property Property
}

// Write the file out
if err := ioutil.WriteFile(dir+"/"+filename(name), formatted, 0644); err != nil {
if err := os.WriteFile(dir+"/"+filename(name), formatted, 0644); err != nil {
fmt.Printf("Error: Failed to write JSON Schema\n%s\n", err)
os.Exit(1)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/goformation/generate/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (r Resource) Required() string {
}
}

// As Go doesn't provide ordering guarentees for maps, we should
// As Go doesn't provide ordering guarantees for maps, we should
// sort the required property names by alphabetical order so that
// they don't shuffle on every generation, and cause annoying commit diffs
sort.Strings(required)
Expand Down
4 changes: 2 additions & 2 deletions pkg/goformation/goformation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package goformation

import (
"encoding/json"
"io/ioutil"
"os"
"strings"

"github.com/weaveworks/eksctl/pkg/goformation/cloudformation"
Expand All @@ -22,7 +22,7 @@ func Open(filename string) (*cloudformation.Template, error) {
// Parsing can be tweaked via the specified options.
func OpenWithOptions(filename string, options *intrinsics.ProcessorOptions) (*cloudformation.Template, error) {

data, err := ioutil.ReadFile(filename)
data, err := os.ReadFile(filename)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit a965dbe

Please sign in to comment.