Skip to content

Commit

Permalink
fix goreportcard issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dzungtran committed May 12, 2022
1 parent 9c9436b commit 746e954
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
16 changes: 2 additions & 14 deletions pkg/authz/opa.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,8 @@ func CheckPolicies(user *domains.UserWithRoles, callOpts ...CallOPAInputOption)
"user": user,
}

// Apply options to input
if opts.RequestMethod != "" && opts.RequestEndpoint != "" {
input["method"] = opts.RequestMethod
input["endpoint"] = opts.RequestEndpoint
if opts.Org != nil {
input["org"] = opts.Org
}

if len(opts.ExtraData) > 0 {
Expand All @@ -223,16 +221,6 @@ func CheckPolicies(user *domains.UserWithRoles, callOpts ...CallOPAInputOption)
input["endpoint"] = opts.RequestEndpoint
}

if opts.Org != nil {
input["org"] = opts.Org
}

if len(opts.ExtraData) > 0 {
for k, v := range opts.ExtraData {
input[k] = v
}
}

// Run evaluation.
rs, err := preparedQuery.Eval(ctx, rego.EvalInput(input))
if err != nil {
Expand Down
31 changes: 20 additions & 11 deletions pkg/utils/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,35 +112,44 @@ func ToScreamingDelimited(s string, del uint8, screaming bool) string {
// treat acronyms as words, eg for JSONData -> JSON is a whole word
nextCaseIsChanged := false
if i+1 < len(s) {
next := s[i+1]
if (v >= 'A' && v <= 'Z' && next >= 'a' && next <= 'z') || (v >= 'a' && v <= 'z' && next >= 'A' && next <= 'Z') {
nextCaseIsChanged = true
}
next := rune(s[i+1])
nextCaseIsChanged = (isRuneInRange(v, 'A', 'Z') && isRuneInRange(next, 'a', 'z')) ||
(isRuneInRange(v, 'a', 'z') && isRuneInRange(next, 'A', 'Z'))
}

if i > 0 && n[len(n)-1] != del && nextCaseIsChanged {
// add underscore if next letter case type is changed
if v >= 'A' && v <= 'Z' {
if isRuneInRange(v, 'A', 'Z') {
n += string(del) + string(v)
} else if v >= 'a' && v <= 'z' {
}

if isRuneInRange(v, 'a', 'z') {
n += string(v) + string(del)
}
} else if v == ' ' || v == '_' || v == '-' {
continue
}

if v == ' ' || v == '_' || v == '-' {
// replace spaces/underscores with delimiters
n += string(del)
} else {
n = n + string(v)
continue
}

n = n + string(v)
}

n = strings.ToLower(n)
if screaming {
n = strings.ToUpper(n)
} else {
n = strings.ToLower(n)
}

return n
}

func isRuneInRange(chr rune, fromRune rune, toRune rune) bool {
return chr >= fromRune && chr <= toRune
}

// UcFirst Upper case first character
func UcFirst(str string) string {
r := []rune(str)
Expand Down

0 comments on commit 746e954

Please sign in to comment.