Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cli lint and update protbuf and yaml #1810

Merged
merged 15 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cli/bpbuild/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"

cloudbuild "google.golang.org/api/cloudbuild/v1"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"
)

const (
Expand All @@ -22,12 +22,12 @@ func getCBBuildsWithFilter(projectID string, filter string, cFilters []clientBui
ctx := context.Background()
cloudbuildService, err := cloudbuild.NewService(ctx)
if err != nil {
return nil, fmt.Errorf("error creating cloudbuild service: %v", err)
return nil, fmt.Errorf("error creating cloudbuild service: %w", err)
}

c, err := cloudbuildService.Projects.Builds.List(projectID).Filter(filter).Do()
if err != nil {
return nil, fmt.Errorf("error listing builds with filter %s in project %s: %v", filter, projectID, err)
return nil, fmt.Errorf("error listing builds with filter %s in project %s: %w", filter, projectID, err)
}

cbBuilds := []*cloudbuild.Build{}
Expand Down Expand Up @@ -56,7 +56,7 @@ func getCBBuildsWithFilter(projectID string, filter string, cFilters []clientBui
for {
c, err = cloudbuildService.Projects.Builds.List(projectID).Filter(filter).PageToken(c.NextPageToken).Do()
if err != nil {
return nil, fmt.Errorf("error retriving next page with token %s: %v", c.NextPageToken, err)
return nil, fmt.Errorf("error retrieving next page with token %s: %w", c.NextPageToken, err)
}
appendClientFilteredBuilds(c.Builds)
if c.NextPageToken == "" {
Expand Down
1 change: 0 additions & 1 deletion cli/bpbuild/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func init() {
avgTimeCmd.Flags().StringVar(&avgTimeFlags.lookUpEnd, "end-time", "", "Time to stop computing build step avg in form MM-DD-YYYY. Defaults to current date.")
avgTimeCmd.Flags().StringVar(&avgTimeFlags.projectId, "project-id", "cloud-foundation-cicd", "Project ID where builds are executed.")
avgTimeCmd.Flags().StringVar(&avgTimeFlags.repoName, "repo", "", "Name of repo that triggered the builds. Defaults to extracting from git config.")

}

var Cmd = &cobra.Command{
Expand Down
1 change: 0 additions & 1 deletion cli/bpcatalog/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ func init() {

listCmd.Flags().Var(&catalogListFlags.format, "format", fmt.Sprintf("Format to display catalog. Defaults to table. Options are %+v.", renderFormats))
listCmd.Flags().Var(&catalogListFlags.sort, "sort", fmt.Sprintf("Sort results. Defaults to created date. Options are %+v.", sortOptions))

}

var Cmd = &cobra.Command{
Expand Down
2 changes: 1 addition & 1 deletion cli/bpcatalog/gh.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"os"
"sort"

"github.com/google/go-github/v53/github"
"github.com/google/go-github/v55/github"
"golang.org/x/oauth2"
)

Expand Down
3 changes: 1 addition & 2 deletions cli/bpcatalog/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"testing"
"time"

"github.com/google/go-github/v53/github"
"github.com/google/go-github/v55/github"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -305,7 +305,6 @@ func TestRenderDocHTML(t *testing.T) {
updateExpected(t, expectedPath, got)
expected := readFile(t, expectedPath)
assert.Equal(t, expected, got)

})
}
}
4 changes: 2 additions & 2 deletions cli/bpcatalog/tf.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"strings"

"github.com/google/go-github/v53/github"
"github.com/google/go-github/v55/github"
)

// sortOption defines the set of sort options for catalog.
Expand Down Expand Up @@ -55,7 +55,7 @@ var (
func fetchSortedTFRepos(gh *ghService, sortOpt sortOption) (repos, error) {
repos, err := gh.fetchRepos()
if err != nil {
return nil, fmt.Errorf("error fetching repos: %v", err)
return nil, fmt.Errorf("error fetching repos: %w", err)
}
repos = repos.filter(func(r *github.Repository) bool {
if r.GetArchived() {
Expand Down
2 changes: 1 addition & 1 deletion cli/bpcatalog/tf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"
"time"

"github.com/google/go-github/v53/github"
"github.com/google/go-github/v55/github"
"github.com/migueleliasweb/go-github-mock/src/mock"
"github.com/stretchr/testify/assert"
)
Expand Down
16 changes: 8 additions & 8 deletions cli/bpmetadata/markdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ func TestProcessMarkdownContent(t *testing.T) {
getContent: true,
want: &mdContent{
listItems: []mdListItem{
mdListItem{
{
text: "User requests are sent to the front end, which is deployed on two Cloud Run services as containers to support high scalability applications.",
},
mdListItem{
{
text: "The request then lands on the middle tier, which is the API layer that provides access to the backend. This is also deployed on Cloud Run for scalability and ease of deployment in multiple languages. This middleware is a Golang based API.",
},
},
Expand All @@ -127,19 +127,19 @@ func TestProcessMarkdownContent(t *testing.T) {
getContent: true,
want: &mdContent{
listItems: []mdListItem{
mdListItem{
{
text: "document-01",
url: "http://google.com/doc-01",
},
mdListItem{
{
text: "document-02",
url: "http://google.com/doc-02",
},
mdListItem{
{
text: "document-03",
url: "http://google.com/doc-03",
},
mdListItem{
{
text: "document-04",
url: "http://google.com/doc-04",
},
Expand All @@ -155,10 +155,10 @@ func TestProcessMarkdownContent(t *testing.T) {
getContent: true,
want: &mdContent{
listItems: []mdListItem{
mdListItem{
{
text: "text-document-01",
},
mdListItem{
{
text: "text-document-02",
},
},
Expand Down
6 changes: 3 additions & 3 deletions cli/bpmetadata/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var (
func fileExists(path string) (bool, error) {
info, err := os.Stat(path)
if err != nil {
return false, fmt.Errorf("unable to read file at the provided path: %v", err)
return false, fmt.Errorf("unable to read file at the provided path: %w", err)
}

if info.IsDir() {
Expand All @@ -48,7 +48,7 @@ func getDirPaths(configPath string, re *regexp.Regexp) ([]*BlueprintMiscContent,
paths := []*BlueprintMiscContent{}
err := filepath.Walk(configPath, func(path string, info fs.FileInfo, err error) error {
if err != nil {
return fmt.Errorf("error accessing examples in the path %q: %v", configPath, err)
return fmt.Errorf("error accessing examples in the path %q: %w", configPath, err)
}

// skip if this is a .terraform dir
Expand All @@ -74,7 +74,7 @@ func getDirPaths(configPath string, re *regexp.Regexp) ([]*BlueprintMiscContent,
})

if err != nil {
return nil, fmt.Errorf("error accessing examples in the path %q: %v", configPath, err)
return nil, fmt.Errorf("error accessing examples in the path %q: %w", configPath, err)
}

// Sort by configPath name before returning
Expand Down
18 changes: 9 additions & 9 deletions cli/bpmetadata/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,19 @@ func TestDirContent(t *testing.T) {
path: "content/examples",
regex: regexExamples,
want: []*BlueprintMiscContent{
&BlueprintMiscContent{
{
Name: "terraform",
Location: "examples/acm/acm-terraform-blog-part1/terraform",
},
&BlueprintMiscContent{
{
Name: "acm-terraform-blog-part2",
Location: "examples/acm/acm-terraform-blog-part2",
},
&BlueprintMiscContent{
{
Name: "simple_regional",
Location: "examples/simple_regional",
},
&BlueprintMiscContent{
{
Name: "simple_regional_beta",
Location: "examples/simple_regional_beta",
},
Expand All @@ -89,15 +89,15 @@ func TestDirContent(t *testing.T) {
path: "content/modules",
regex: regexModules,
want: []*BlueprintMiscContent{
&BlueprintMiscContent{
{
Name: "beta-public-cluster",
Location: "modules/beta-public-cluster",
},
&BlueprintMiscContent{
{
Name: "binary-authorization",
Location: "modules/binary-authorization",
},
&BlueprintMiscContent{
{
Name: "private-cluster",
Location: "modules/private-cluster",
},
Expand All @@ -115,11 +115,11 @@ func TestDirContent(t *testing.T) {
path: "content/examples-some-without-tf/examples",
regex: regexExamples,
want: []*BlueprintMiscContent{
&BlueprintMiscContent{
{
Name: "terraform",
Location: "examples/acm/acm-terraform-blog-part1/terraform",
},
&BlueprintMiscContent{
{
Name: "simple_regional",
Location: "examples/simple_regional",
},
Expand Down
2 changes: 1 addition & 1 deletion cli/bpmetadata/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func getRepoDetailsByPath(bpPath string, r *repoDetail, readme []byte) {
// if it's still in memory.
if strings.Contains(bpPath, nestedBpPath) && r.Source != nil {
// try to parse the module name from MD which will get
// overriden with "["repoName-submoduleName" if repoName is available
// overridden with "["repoName-submoduleName" if repoName is available
r.ModuleName = parseRepoNameFromMd(readme)
if r.RepoName != "" {
r.ModuleName = r.RepoName + "-" + getBpSubmoduleNameInKebabCase(bpPath)
Expand Down
30 changes: 10 additions & 20 deletions cli/bpmetadata/schema/gcp-blueprint-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,8 @@
]
},
"quotaType": {
"patternProperties": {
".*": {
"type": "string"
}
"additionalProperties": {
"type": "string"
},
"type": "object"
}
Expand Down Expand Up @@ -543,10 +541,8 @@
"BlueprintUIInput": {
"properties": {
"variables": {
"patternProperties": {
".*": {
"$ref": "#/$defs/DisplayVariable"
}
"additionalProperties": {
"$ref": "#/$defs/DisplayVariable"
},
"type": "object"
},
Expand All @@ -572,10 +568,8 @@
"type": "array"
},
"outputs": {
"patternProperties": {
".*": {
"$ref": "#/$defs/DisplayOutput"
}
"additionalProperties": {
"$ref": "#/$defs/DisplayOutput"
},
"type": "object"
}
Expand Down Expand Up @@ -1013,18 +1007,14 @@
"type": "string"
},
"labels": {
"patternProperties": {
".*": {
"type": "string"
}
"additionalProperties": {
"type": "string"
},
"type": "object"
},
"annotations": {
"patternProperties": {
".*": {
"type": "string"
}
"additionalProperties": {
"type": "string"
},
"type": "object"
}
Expand Down
2 changes: 1 addition & 1 deletion cli/bpmetadata/tfconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func getBlueprintVersion(configPath string) (*blueprintVersion, error) {
//parse out the blueprint version from the config
modName, err := parseBlueprintVersion(versionsFile, diags)
if err != nil {
return nil, fmt.Errorf("error parsing blueprint version: %v", err)
return nil, fmt.Errorf("error parsing blueprint version: %w", err)
}

//parse out the required version from the config
Expand Down
1 change: 0 additions & 1 deletion cli/bpmetadata/tfconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ func TestTFVersions(t *testing.T) {
t.Errorf("getBlueprintVersion() = %v, want %v", got.moduleVersion, tt.wantModuleVersion)
return
}

} else {
if tt.wantModuleVersion != "" && tt.wantRequiredVersion != "" {
t.Errorf("getBlueprintVersion() = returned nil when we want core: %v and bpVersion: %v", tt.wantRequiredVersion, tt.wantModuleVersion)
Expand Down
6 changes: 3 additions & 3 deletions cli/bpmetadata/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func validateMetadataYaml(m string, schema gojsonschema.JSONLoader) error {
// prepare metadata for validation by converting it from YAML to JSON
mBytes, err := convertYamlToJson(m)
if err != nil {
return fmt.Errorf("yaml to json conversion failed for metadata at path %s. error: %s", m, err)
return fmt.Errorf("yaml to json conversion failed for metadata at path %s. error: %w", m, err)
}

// load metadata from the path
Expand All @@ -63,7 +63,7 @@ func validateMetadataYaml(m string, schema gojsonschema.JSONLoader) error {
// validate metadata against the schema
result, err := gojsonschema.Validate(schema, yamlLoader)
if err != nil {
return fmt.Errorf("metadata validation failed for %s. error: %s", m, err)
return fmt.Errorf("metadata validation failed for %s. error: %w", m, err)
}

if !result.Valid() {
Expand All @@ -84,7 +84,7 @@ func convertYamlToJson(m string) ([]byte, error) {
// read metadata for validation
b, err := os.ReadFile(m)
if err != nil {
return nil, fmt.Errorf("unable to read metadata at path %s. error: %s", m, err)
return nil, fmt.Errorf("unable to read metadata at path %s. error: %w", m, err)
}

if len(b) == 0 {
Expand Down
4 changes: 2 additions & 2 deletions cli/bptest/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var Cmd = &cobra.Command{
var listCmd = &cobra.Command{
Use: "list",
Short: "list tests",
Long: "Lists both auto discovered and explicit intergration tests",
Long: "Lists both auto discovered and explicit integration tests",

Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -80,7 +80,7 @@ var runCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
intTestDir, err := getIntTestDir(flags.testDir)
if err != nil {
return fmt.Errorf("error discovering test dir: %v", err)
return fmt.Errorf("error discovering test dir: %w", err)
}
testStage, err := validateAndGetStage(flags.testStage)
if err != nil {
Expand Down
Loading
Loading