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 Golangci-lint errors #63

Merged
merged 7 commits into from
May 13, 2024
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
10 changes: 5 additions & 5 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
name: Workflow
on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]
jobs:
go_security_scan:
name: Go security
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Run Go Security
uses: securego/gosec@master
with:
# added additional exclude arguments after gosec v2.9.4 came out
args: -exclude=G104,G402,G101 ./...
args: -exclude=G101,G402 ./...
malware_security_scan:
name: Malware Scanner
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Run malware scan
uses: dell/common-github-actions/malware-scanner@main
with:
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/linters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ jobs:
name: golangci-lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: "1.20"
go-version: "1.22"
cache: false
- name: Checkout the code
uses: actions/checkout@v3.2.0
uses: actions/checkout@v4
- name: Vendor packages
run: |
go mod vendor
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v5
with:
version: v1.53
version: latest
skip-cache: true
11 changes: 9 additions & 2 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
run:
timeout: 20m
issue-exit-code: 0 # we will change this later
tests: true
skip-dirs-use-default: true
modules-download-mode: readonly

issues:
max-issues-per-linter: 0
max-same-issues: 0
new: false
exclude:
- "error-naming: error var invalidFileMode should have name of the form errFoo"
- "var-naming: struct field"
- "var-naming: don't use underscores in Go names"
- "var-naming: func parameter"
- "var-naming: don't use ALL_CAPS in Go names; use CamelCase"
- "var-naming: method parameter"
- "var-naming: type"
- "unexported-return: exported func"

output:
print-linter-name: true
Expand Down
42 changes: 20 additions & 22 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const (
defaultVolumesPathPermissions = "0777"
defaultIgnoreUnresolvableHosts = false
headerISISessToken = "Cookie"
headerISICSRFToken = "X-CSRF-Token"
headerISICSRFToken = "X-CSRF-Token" //nolint:gosec,G101
headerISIReferer = "Referer"
isiSessCsrfToken = "Set-Cookie"
authTypeBasic = 0
Expand Down Expand Up @@ -266,7 +266,7 @@ func New(
if opts.Insecure {
c.http.Transport = &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
InsecureSkipVerify: true, //nolint:gosec,G402
},
}
} else {
Expand All @@ -275,7 +275,7 @@ func New(
return nil, err
}
c.http.Transport = &http.Transport{
TLSClientConfig: &tls.Config{
TLSClientConfig: &tls.Config{ //nolint:gosec,G402
RootCAs: pool,
InsecureSkipVerify: false,
},
Expand All @@ -284,7 +284,7 @@ func New(
}

if c.authType == authTypeSessionBased {
c.authenticate(ctx, username, password, hostname)
_ = c.authenticate(ctx, username, password, hostname)
}
resp := &apiVerResponse{}
if err := c.Get(ctx, "/platform/latest", "", nil, nil, resp); err != nil &&
Expand Down Expand Up @@ -627,19 +627,18 @@ func parseJSONHTMLError(r *http.Response) error {
htmlError.Message = doc.Find("title").Text()
}
return htmlError
} else {
jsonErr := &JSONError{}
// decode JSON error response
err := json.NewDecoder(r.Body).Decode(jsonErr)
if err != nil {
return err
}
jsonErr.StatusCode = r.StatusCode
if len(jsonErr.Err) > 0 && jsonErr.Err[0].Message == "" {
jsonErr.Err[0].Message = r.Status
}
return jsonErr
}
jsonErr := &JSONError{}
// decode JSON error response
err := json.NewDecoder(r.Body).Decode(jsonErr)
if err != nil {
return err
}
jsonErr.StatusCode = r.StatusCode
if len(jsonErr.Err) > 0 && jsonErr.Err[0].Message == "" {
jsonErr.Err[0].Message = r.Status
}
return jsonErr
}

// Authenticate make a REST API call [/session/1/session] to PowerScale to authenticate the given credentials.
Expand All @@ -650,7 +649,7 @@ func (c *client) authenticate(ctx context.Context, username string, password str
data := &setupConnection{Services: []string{"platform", "namespace"}, Username: username, Password: password}
resp, _, err := c.DoAndGetResponseBody(ctx, http.MethodPost, "/session/1/session", "", nil, headers, data)
if err != nil {
return errors.New(fmt.Sprintf("Authentication error: %v", err))
return fmt.Errorf("Authentication error: %v", err)
}

if resp != nil {
Expand All @@ -669,20 +668,19 @@ func (c *client) authenticate(ctx context.Context, username string, password str
case resp.StatusCode == 401:
{
log.Debug(ctx, "Response Code %v", resp)
return errors.New(fmt.Sprintf("Authentication failed. Unable to login to PowerScale. Verify username and password."))
return fmt.Errorf("authentication failed. unable to login to powerscale. verify username and password")
}
default:
return errors.New(fmt.Sprintf("Authenticate error. Response:"))
return fmt.Errorf("authenticate error. response-")
}

headerRes := strings.Join(resp.Header.Values(isiSessCsrfToken), " ")

startIndex, endIndex, matchStrLen := FetchValueIndexForKey(headerRes, "isisessid=", ";")
if startIndex < 0 || endIndex < 0 {
return errors.New(fmt.Sprintf("Session ID not retrieved"))
} else {
c.SetAuthToken(headerRes[startIndex : startIndex+matchStrLen+endIndex])
return fmt.Errorf("Session ID not retrieved")
}
c.SetAuthToken(headerRes[startIndex : startIndex+matchStrLen+endIndex])

startIndex, endIndex, matchStrLen = FetchValueIndexForKey(headerRes, "isicsrf=", ";")
if startIndex < 0 || endIndex < 0 {
Expand Down
6 changes: 3 additions & 3 deletions api/api_logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func isBinOctetBody(h http.Header) bool {
return h.Get(headerKeyContentType) == headerValContentTypeBinaryOctetStream
}

func logRequest(ctx context.Context, w io.Writer, req *http.Request, verbose VerboseType) {
func logRequest(_ context.Context, w io.Writer, req *http.Request, verbose VerboseType) {
fmt.Fprintln(w, "")
fmt.Fprint(w, " -------------------------- ")
fmt.Fprint(w, "GOISILON HTTP REQUEST")
Expand All @@ -47,7 +47,7 @@ func logRequest(ctx context.Context, w io.Writer, req *http.Request, verbose Ver
// full logging, i.e. print full request message content
buf, _ := httputil.DumpRequest(req, !isBinOctetBody(req.Header))
decodedBuf := encryptPassword(buf)
WriteIndented(w, decodedBuf)
_ = WriteIndented(w, decodedBuf)
fmt.Fprintln(w)
}
}
Expand Down Expand Up @@ -75,7 +75,7 @@ func logResponse(ctx context.Context, res *http.Response, verbose VerboseType) {
}

// when DumpResponse gets err, buf will be nil. No message content will be printed
WriteIndented(w, buf)
_ = WriteIndented(w, buf)

log.Debug(ctx, w.String())
}
Expand Down
2 changes: 1 addition & 1 deletion api/api_ordered_values.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (v *OrderedValues) Del(key []byte) {
// using insertion order.
func (v *OrderedValues) Encode() string {
buf := &bytes.Buffer{}
v.EncodeTo(buf)
_ = v.EncodeTo(buf)
return buf.String()
}

Expand Down
2 changes: 1 addition & 1 deletion api/common/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/stretchr/testify/assert"
)

func TestMain(m *testing.M) {
func TestMain(_ *testing.M) {
fmt.Print("executing TestMain\n")
}

Expand Down
Loading