Skip to content

Commit

Permalink
lint #188
Browse files Browse the repository at this point in the history
  • Loading branch information
srinandan committed Apr 15, 2023
1 parent a90f536 commit 68be03d
Show file tree
Hide file tree
Showing 260 changed files with 934 additions and 884 deletions.
116 changes: 116 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

run:
concurrency: 4
deadline: 20m
issues-exit-code: 1
tests: false
skip-dirs:
- cicd
- docs
- test
- third-party

output:
format: tab
print-issued-lines: true
print-linter-name: true

linters-settings:
errcheck:
check-type-assertions: false
check-blank: false
govet:
check-shadowing: true
golint:
min-confidence: 0.8
gofmt:
simplify: true
gocyclo:
min-complexity: 10
maligned:
suggest-new: true
goconst:
min-len: 3
min-occurrences: 3
depguard:
list-type: blacklist
include-go-root: false
misspell:
locale: US
lll:
line-length: 120
tab-width: 1
unused:
check-exported: false
unparam:
check-exported: false
nakedret:
max-func-lines: 30
prealloc:
simple: true
range-loops: true
for-loops: false
gosec:
includes:
- G401
- G402
- G404

linters:
enable:
- errcheck
- exportloopref
- gocritic
- gofumpt
- revive
- gosimple
- govet
- lll
- stylecheck
- unconvert
- unparam
- ineffassign
- staticcheck
- typecheck
- unused
- bodyclose
- depguard
- goconst
- gofmt
- goimports
- gosec
- misspell
- nakedret
- prealloc
- unconvert
enable-all: false
disable-all: true
fast: false

issues:
exclude-rules:
- linters:
- gosec
text: "G[105,202,401,505]"
- linters:
- goimports
text: "File is not `goimports`-ed"
- linters:
- govet
text: "shadows declaration"
- linters:
- staticcheck
text: "SA1019:"
15 changes: 11 additions & 4 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ builds:
- amd64
flags:
- -trimpath
ldflags:
- -s -w -a -extldflags "-static" -X main.Version={{.Tag}} -X main.Git={{.Commit}}
- -buildvcs=true
gcflags:
- all="-l"
env:
Expand All @@ -48,8 +47,7 @@ builds:
- arm64
flags:
- -trimpath
ldflags:
- -s -w -a -extldflags "-static" -X main.Version={{.Tag}} -X main.Git={{.Commit}}
- -buildvcs=true
gcflags:
- all="-l"
env:
Expand All @@ -64,6 +62,7 @@ builds:
- amd64
flags:
- -trimpath
- -buildvcs=true
ldflags:
- -s -w -a -extldflags "-static" -X main.Version={{.Tag}} -X main.Git={{.Commit}}
gcflags:
Expand All @@ -81,6 +80,7 @@ archives:
amd64: x86_64
windows: Windows
wrap_in_directory: true
rlcp: true
files:
- LICENSE.txt
builds:
Expand All @@ -104,6 +104,13 @@ signs:
"${artifact}",
]

changelog:
sort: asc
use: github
groups:
- title: 'Change Log'
order: 0

release:
draft: true
prerelease: true
7 changes: 4 additions & 3 deletions cmd/apis/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ var Cmd = &cobra.Command{
Long: "Manage Apigee API proxies in an org",
}

var org, env, name string
var conn, revision int
var (
org, env, name string
conn, revision int
)

func init() {

Cmd.PersistentFlags().StringVarP(&org, "org", "o",
"", "Apigee organization name")

Expand Down
1 change: 0 additions & 1 deletion cmd/apis/bundlecrtapis.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ var BundleCreateCmd = &cobra.Command{
return apiclient.SetApigeeOrg(org)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {

if proxyZip != "" {
_, err = apis.CreateProxy(name, proxyZip)
} else if proxyFolder != "" {
Expand Down
6 changes: 4 additions & 2 deletions cmd/apis/cleanapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ var CleanCmd = &cobra.Command{
},
}

var reportOnly bool
var keepList []string
var (
reportOnly bool
keepList []string
)

func init() {
CleanCmd.Flags().StringVarP(&name, "name", "n",
Expand Down
23 changes: 9 additions & 14 deletions cmd/apis/cloneapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ var CloneCmd = &cobra.Command{
return apiclient.SetApigeeOrg(org)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {

if proxyZip != "" {
//extract the zip to a tmp folder and assign to proxyFolder
// extract the zip to a tmp folder and assign to proxyFolder
if proxyFolder, err = unzipBundle(); err != nil {
return err
}
Expand Down Expand Up @@ -110,7 +109,6 @@ func init() {
}

func copyDirectory() (tmpDir string, err error) {

if strings.Contains(runtime.GOOS, "windows") {
return "", fmt.Errorf("this operation is not supported on windows at the moment")
}
Expand All @@ -128,8 +126,7 @@ func copyDirectory() (tmpDir string, err error) {
}

func renameProxy(tmpDir string) (err error) {

//1. rename the file in the apiproxy folder
// 1. rename the file in the apiproxy folder
apiproxyFolder := path.Join(tmpDir, "apiproxy")
re := regexp.MustCompile(`apiproxy\/\w+\.xml`)

Expand All @@ -141,19 +138,19 @@ func renameProxy(tmpDir string) (err error) {
if !info.IsDir() {
oldFileName := filepath.Base(path)

if re.MatchString(path) { //this is the proxy xml
//1. rename the file based on the new proxy name
if re.MatchString(path) { // this is the proxy xml
// 1. rename the file based on the new proxy name
newFilePath := strings.Replace(path, oldFileName, name+".xml", 1)
if err = os.Rename(path, newFilePath); err != nil {
return err
}

//2. set the name
// 2. set the name
if err = setParam(newFilePath, "proxy"); err != nil {
return err
}

//3. set the basePath
// 3. set the basePath
if err = setParam(newFilePath, "basePath"); err != nil {
return err
}
Expand All @@ -166,10 +163,9 @@ func renameProxy(tmpDir string) (err error) {
}

func setParam(filePath string, paramType string) (err error) {

var proxyFile *os.File

proxyFile, err = os.OpenFile(filePath, os.O_RDONLY, 0644)
proxyFile, err = os.OpenFile(filePath, os.O_RDONLY, 0o644)
if err != nil {
return err
}
Expand All @@ -194,7 +190,7 @@ func setParam(filePath string, paramType string) (err error) {
stringValue = re.ReplaceAllString(stringValue, replaceBasePath)
}

proxyFile, err = os.OpenFile(filePath, os.O_WRONLY|os.O_TRUNC, 0644)
proxyFile, err = os.OpenFile(filePath, os.O_WRONLY|os.O_TRUNC, 0o644)
if err != nil {
return err
}
Expand All @@ -210,7 +206,6 @@ func setParam(filePath string, paramType string) (err error) {
}

func unzipBundle() (tmpDir string, err error) {

tmpDir, err = os.MkdirTemp("", "proxy")
if err != nil {
return tmpDir, err
Expand All @@ -237,7 +232,7 @@ func unzipBundle() (tmpDir string, err error) {
return tmpDir, err
}

bundleFile, err := os.OpenFile(bundlePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
bundleFile, err := os.OpenFile(bundlePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o644)
if err != nil {
return tmpDir, err
}
Expand Down
6 changes: 4 additions & 2 deletions cmd/apis/crtapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ var CreateCmd = &cobra.Command{
Long: "Creates an API proxy in an Apigee Org",
}

var targetUrlRef string
var importProxy, skipPolicy, addCORS bool
var (
targetURLRef string
importProxy, skipPolicy, addCORS bool
)

func init() {
CreateCmd.AddCommand(OasCreateCmd)
Expand Down
1 change: 0 additions & 1 deletion cmd/apis/crttrcapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ var CreateTrcCmd = &cobra.Command{
var filter map[string]string

func init() {

CreateTrcCmd.Flags().StringVarP(&name, "name", "n",
"", "API proxy name")
CreateTrcCmd.Flags().IntVarP(&revision, "rev", "v",
Expand Down
10 changes: 6 additions & 4 deletions cmd/apis/depapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import (
var DepCmd = &cobra.Command{
Use: "deploy",
Short: "Deploys a revision of an existing API proxy",
Long: "Deploys a revision of an existing API proxy to an environment in an organization, optionally waits for deployment",
Long: "Deploys a revision of an existing API proxy to an environment " +
"in an organization, optionally waits for deployment",
Args: func(cmd *cobra.Command, args []string) (err error) {
apiclient.SetApigeeEnv(env)
return apiclient.SetApigeeOrg(org)
Expand Down Expand Up @@ -80,13 +81,14 @@ var DepCmd = &cobra.Command{
},
}

var overrides, wait bool
var serviceAccountName string
var (
overrides, wait bool
serviceAccountName string
)

const interval = 10

func init() {

DepCmd.Flags().StringVarP(&name, "name", "n",
"", "API proxy name")
DepCmd.Flags().StringVarP(&env, "env", "e",
Expand Down
1 change: 0 additions & 1 deletion cmd/apis/expapis.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ var ExpCmd = &cobra.Command{
var allRevisions bool

func init() {

ExpCmd.Flags().IntVarP(&conn, "conn", "c",
4, "Number of connections")
ExpCmd.Flags().StringVarP(&folder, "folder", "f",
Expand Down
1 change: 0 additions & 1 deletion cmd/apis/fetchapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ var FetCmd = &cobra.Command{
}

func init() {

FetCmd.Flags().StringVarP(&name, "name", "n",
"", "API Proxy Bundle Name")
FetCmd.Flags().IntVarP(&revision, "rev", "v",
Expand Down
1 change: 0 additions & 1 deletion cmd/apis/gettrcapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ var GetTrcCmd = &cobra.Command{
var sessionID, messageID string

func init() {

GetTrcCmd.Flags().StringVarP(&name, "name", "n",
"", "API proxy name")
GetTrcCmd.Flags().IntVarP(&revision, "rev", "v",
Expand Down
3 changes: 1 addition & 2 deletions cmd/apis/ghcrtapis.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ import (
"github.com/spf13/cobra"
)

// GhCreateCmd create an api from a github repo
var GhCreateCmd = &cobra.Command{
Use: "github",
Aliases: []string{"gh"},
Short: "Creates an API proxy from a GitHub repo",
Long: "Creates an API proxy from a GitHub repo",
Args: func(cmd *cobra.Command, args []string) (err error) {
//(\w+)?\/apiproxy$
re := regexp.MustCompile(`(\w+)?\/apiproxy$`)
if ok := re.Match([]byte(ghPath)); !ok {
return fmt.Errorf("github path must end with /apiproxy")
Expand Down Expand Up @@ -76,5 +76,4 @@ func init() {
_ = GhCreateCmd.MarkFlagRequired("owner")
_ = GhCreateCmd.MarkFlagRequired("repo")
_ = GhCreateCmd.MarkFlagRequired("proxy-path")

}
Loading

0 comments on commit 68be03d

Please sign in to comment.