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

add golangci lint to github action workflow #1068

Merged
merged 15 commits into from
Aug 31, 2023
Prev Previous commit
Next Next commit
update based on githubci lint
  • Loading branch information
suchen-sci committed Aug 28, 2023
commit 9a3d0f8ff0f16508865f6c14b2cb4a351da09fae
2 changes: 0 additions & 2 deletions pkg/filters/validator/basicauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ func (huc *htpasswdUserCache) WatchChanges() {
if err != nil {
logger.Errorf(err.Error())
}
return
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant return.

}

func (huc *htpasswdUserCache) Close() {
Expand Down Expand Up @@ -320,7 +319,6 @@ func (euc *etcdUserCache) WatchChanges() {
}
}
}()
return
}

func (euc *etcdUserCache) Close() {
Expand Down
3 changes: 1 addition & 2 deletions pkg/filters/validator/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,9 +535,8 @@ basicAuth:
return kvs, nil
}

var mockMap sync.Map
supervisor := supervisor.NewMock(
nil, clusterInstance, mockMap, mockMap, nil, nil, false, nil, nil)
nil, clusterInstance, sync.Map{}, sync.Map{}, nil, nil, false, nil, nil)

yamlConfig := `
kind: Validator
Expand Down
3 changes: 1 addition & 2 deletions pkg/object/autocertmanager/autocertmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -855,8 +855,7 @@ func TestDomain(t *testing.T) {
})

t.Run("renewCert", func(t *testing.T) {
var ca *httptest.Server
ca = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ca := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Replay-Nonce", "nonce")
w.WriteHeader(http.StatusForbidden)
w.Write([]byte("{}"))
Expand Down
6 changes: 1 addition & 5 deletions pkg/object/httpserver/routers/radixtree/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,11 +514,7 @@ func newMuxRule(rule *routers.Rule) *muxRule {

if seg.nodeType == ntStatic {
p := path.Path
if _, ok := mr.pathCache[p]; ok {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary guard.

mr.pathCache[p] = append(mr.pathCache[p], newMuxPath(path))
} else {
mr.pathCache[p] = []*muxPath{newMuxPath(path)}
}
mr.pathCache[p] = append(mr.pathCache[p], newMuxPath(path))
} else {
mr.root.insert(path)
}
Expand Down
11 changes: 5 additions & 6 deletions pkg/util/jmxtool/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,24 @@ func JSONToKVMap(jsonStr string) (map[string]string, error) {
func extractKVs(prefix string, obj interface{}) []map[string]string {
var rst []map[string]string

switch obj.(type) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary type assertion.

switch o := obj.(type) {
case map[string]interface{}:
for k, v := range obj.(map[string]interface{}) {
for k, v := range o {
current := k
rst = append(rst, extractKVs(join(prefix, current), v)...)
}

case []interface{}:
o := obj.([]interface{})
length := len(o)
for i := 0; i < length; i++ {
rst = append(rst, extractKVs(join(prefix, strconv.Itoa(i)), o[i])...)
}
case bool:
rst = append(rst, map[string]string{prefix: strconv.FormatBool(obj.(bool))})
rst = append(rst, map[string]string{prefix: strconv.FormatBool(o)})
case int:
rst = append(rst, map[string]string{prefix: strconv.Itoa(obj.(int))})
rst = append(rst, map[string]string{prefix: strconv.Itoa(o)})
case float64:
rst = append(rst, map[string]string{prefix: strconv.FormatFloat(obj.(float64), 'f', 0, 64)})
rst = append(rst, map[string]string{prefix: strconv.FormatFloat(o, 'f', 0, 64)})
default:
if obj == nil {
rst = append(rst, map[string]string{prefix: ""})
Expand Down
28 changes: 14 additions & 14 deletions pkg/util/signer/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,53 +50,53 @@ type (
Literal struct {
// ScopeSuffix is the last part when build the credential scope.
// Default: megaease_request
ScopeSuffix string `json:"scopeSuffix" json:"scopeSuffix" jsonschema:"required"`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

json twice.

ScopeSuffix string `json:"scopeSuffix" jsonschema:"required"`

// AlgorithmName is the query name of the signature algorithm
// Default: X-Me-Algorithm
AlgorithmName string `json:"algorithmName" json:"algorithmName" jsonschema:"required"`
AlgorithmName string `json:"algorithmName" jsonschema:"required"`

// AlgorithmName is the header/query value of the signature algorithm
// Default: ME-HMAC-SHA256
AlgorithmValue string `json:"algorithmValue" json:"alrithmValue" jsonschema:"required"`
AlgorithmValue string `json:"algorithmValue" jsonschema:"required"`

// SignedHeaders is the header/query headers of the signed headers
// Default: X-Me-SignedHeaders
SignedHeaders string `json:"signedHeaders" json:"signedHeaders" jsonschema:"required"`
SignedHeaders string `json:"signedHeaders" jsonschema:"required"`

// Signature is the query name of the signature
// Default: X-Me-Signature
Signature string `json:"signature" json:"signature" jsonschema:"required"`
Signature string `json:"signature" jsonschema:"required"`

// Date is the header/query name of request time
// Default: X-Me-Date
Date string `json:"date" json:"date" jsonschema:"required"`
Date string `json:"date" jsonschema:"required"`

// Expires is the query name of expire duration
// Default: X-Me-Expires
Expires string `json:"expires" json:"expires" jsonschema:"required"`
Expires string `json:"expires" jsonschema:"required"`

// Credential is the query name of credential
// Default: X-Me-Credential
Credential string `json:"credential" json:"credential" jsonschema:"required"`
Credential string `json:"credential" jsonschema:"required"`

// ContentSHA256 is the header name of body/payload hash
// Default: X-Me-Content-Sha256
ContentSHA256 string `json:"contentSha256" json:"contentSha256" jsonschema:"required"`
ContentSHA256 string `json:"contentSha256" jsonschema:"required"`

// SigningKeyPrefix is prepend to access key secret when derive the signing key
// Default: ME
SigningKeyPrefix string `json:"signingKeyPrefix" json:"signingKeyPrefix" jsonschema:"omitempty"`
SigningKeyPrefix string `json:"signingKeyPrefix" jsonschema:"omitempty"`
}

// HeaderHoisting defines which headers are allowed to be moved from header to query
// in presign: header with name has one of the allowed prefixes, but hasn't any
// disallowed prefixes and doesn't match any of disallowed names are allowed to be
// hoisted
HeaderHoisting struct {
AllowedPrefix []string `json:"allowedPrefix" json:"allowedPrefix" jsonschema:"omitempty,uniqueItems=true"`
DisallowedPrefix []string `json:"disallowedPrefix" json:"disallowedPrefix" jsonschema:"omitempty,uniqueItems=true"`
Disallowed []string `json:"disallowed" json:"disallowed" jsonschema:"omitempty,uniqueItems=true"`
AllowedPrefix []string `json:"allowedPrefix" jsonschema:"omitempty,uniqueItems=true"`
DisallowedPrefix []string `json:"disallowedPrefix" jsonschema:"omitempty,uniqueItems=true"`
Disallowed []string `json:"disallowed" jsonschema:"omitempty,uniqueItems=true"`
disallowed map[string]bool
}

Expand Down Expand Up @@ -781,7 +781,7 @@ func (ctx *Context) Verify(req *http.Request, getBody func() io.Reader) error {
return e
}

age := time.Now().Sub(ctx.Time)
age := time.Since(ctx.Time)
if ctx.signer.ttl > 0 {
if age < -ctx.signer.ttl || age > ctx.signer.ttl {
return fmt.Errorf("signature expired")
Expand Down
3 changes: 1 addition & 2 deletions pkg/util/signer/signer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ var awsSpec = &Spec{
}

func buildRequest(serviceName, region, payload string) *http.Request {
var body io.Reader
body = strings.NewReader(payload)
var body io.Reader = strings.NewReader(payload)

var bodyLen int

Expand Down
16 changes: 8 additions & 8 deletions pkg/util/signer/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import "time"

// Spec defines the configuration of a Signer
type Spec struct {
Literal *Literal `json:"literal,omitempty" json:"literal,omitempty" jsonschema:"omitempty"`
HeaderHoisting *HeaderHoisting `json:"headerHoisting,omitempty" json:"headerHoisting,omitempty" jsonschema:"omitempty"`
IgnoredHeaders []string `json:"ignoredHeaders" json:"ignoredHeaders" jsonschema:"omitempty,uniqueItems=true"`
ExcludeBody bool `json:"excludeBody" json:"excludeBody" jsonschema:"omitempty"`
TTL string `json:"ttl" json:"ttl" jsonschema:"omitempty,format=duration"`
AccessKeyID string `json:"accessKeyId" json:"accessKeyId" jsonschema:"omitempty"`
AccessKeySecret string `json:"accessKeySecret" json:"accessKeySecret" jsonschema:"omitempty"`
AccessKeys map[string]string `json:"accessKeys" json:"accessKeys" jsonschema:"omitempty"`
Literal *Literal `json:"literal,omitempty" jsonschema:"omitempty"`
HeaderHoisting *HeaderHoisting `json:"headerHoisting,omitempty" jsonschema:"omitempty"`
IgnoredHeaders []string `json:"ignoredHeaders" jsonschema:"omitempty,uniqueItems=true"`
ExcludeBody bool `json:"excludeBody" jsonschema:"omitempty"`
TTL string `json:"ttl" jsonschema:"omitempty,format=duration"`
AccessKeyID string `json:"accessKeyId" jsonschema:"omitempty"`
AccessKeySecret string `json:"accessKeySecret" jsonschema:"omitempty"`
AccessKeys map[string]string `json:"accessKeys" jsonschema:"omitempty"`
// TODO: AccessKeys is used as an internal access key store, but an external store is also needed
}

Expand Down
Loading