Skip to content

Commit

Permalink
chore(golangci-lint): updating to sets with generics
Browse files Browse the repository at this point in the history
Signed-off-by: Dario Tranchitella <[email protected]>
  • Loading branch information
prometherion committed Dec 29, 2023
1 parent a00bfaf commit 1dae49a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions internal/controllers/capsule_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ type CapsuleConfiguration struct {
}

//nolint:gochecknoglobals
var CapsuleUserGroups sets.String
var CapsuleUserGroups sets.Set[string]

func (c *CapsuleConfiguration) SetupWithManager(ctx context.Context, mgr ctrl.Manager) error {
if len(c.DeprecatedCapsuleUserGroups) > 0 {
CapsuleUserGroups = sets.NewString(c.DeprecatedCapsuleUserGroups...)
CapsuleUserGroups = sets.New[string](c.DeprecatedCapsuleUserGroups...)

return nil
}
Expand All @@ -57,7 +57,7 @@ func (c *CapsuleConfiguration) Reconcile(ctx context.Context, request reconcile.
panic(err)
}

CapsuleUserGroups = sets.NewString(capsuleConfig.Spec.UserGroups...)
CapsuleUserGroups = sets.New(capsuleConfig.Spec.UserGroups...)

return reconcile.Result{}, nil
}
8 changes: 4 additions & 4 deletions internal/modules/utils/selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func HandleGetSelector(ctx context.Context, obj client.Object, client client.Rea
func HandleListSelector(requirements []labels.Requirement) (selector labels.Selector, err error) {
selector = labels.NewSelector()

requirementsMap := make(map[string]sets.String)
requirementsMap := make(map[string]sets.Set[string])
generateRequirementsKey := func(requirement labels.Requirement) string { //nolint:nolintlint
switch requirement.Operator() { //nolint:exhaustive
case selection.Equals, selection.DoubleEquals, selection.In:
Expand All @@ -58,18 +58,18 @@ func HandleListSelector(requirements []labels.Requirement) (selector labels.Sele
key := generateRequirementsKey(requirement)

if _, ok := requirementsMap[key]; !ok {
requirementsMap[key] = requirement.Values()
requirementsMap[key] = sets.Set[string](requirement.Values())

continue
}

requirementsMap[key] = requirementsMap[key].Union(requirement.Values())
requirementsMap[key] = requirementsMap[key].Union(sets.Set[string](requirement.Values()))
}

for k, v := range requirementsMap {
key, op := strings.Split(k, ":")[0], strings.Split(k, ":")[1]

requirement, err := labels.NewRequirement(key, selection.Operator(op), v.List())
requirement, err := labels.NewRequirement(key, selection.Operator(op), v.UnsortedList())
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/webserver/middleware/allowed_requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
)

func CheckPaths(log logr.Logger, allowedPaths sets.String, skipTo func(writer http.ResponseWriter, request *http.Request)) mux.MiddlewareFunc {
func CheckPaths(log logr.Logger, allowedPaths sets.Set[string], skipTo func(writer http.ResponseWriter, request *http.Request)) mux.MiddlewareFunc {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
if allowedPaths.Has(request.URL.Path) {
Expand Down
2 changes: 1 addition & 1 deletion internal/webserver/middleware/user_in_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
req "github.com/projectcapsule/capsule-proxy/internal/request"
)

func CheckUserInIgnoredGroupMiddleware(client client.Writer, log logr.Logger, claim string, authTypes []req.AuthType, ignoredUserGroups sets.String, fn func(writer http.ResponseWriter, request *http.Request)) mux.MiddlewareFunc {
func CheckUserInIgnoredGroupMiddleware(client client.Writer, log logr.Logger, claim string, authTypes []req.AuthType, ignoredUserGroups sets.Set[string], fn func(writer http.ResponseWriter, request *http.Request)) mux.MiddlewareFunc {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
if ignoredUserGroups.Len() > 0 {
Expand Down
8 changes: 4 additions & 4 deletions internal/webserver/webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ func NewKubeFilter(opts options.ListenerOpts, srv options.ServerOptions, rbRefle
reader: clientOverride,
writer: client,
managerReader: client,
allowedPaths: sets.NewString("/api", "/apis", "/version"),
allowedPaths: sets.New("/api", "/apis", "/version"),
authTypes: opts.AuthTypes(),
ignoredUserGroups: sets.NewString(opts.IgnoredGroupNames()...),
ignoredUserGroups: sets.New(opts.IgnoredGroupNames()...),
reverseProxy: reverseProxy,
bearerToken: opts.BearerToken(),
usernameClaimField: opts.PreferredUsernameClaim(),
Expand All @@ -77,9 +77,9 @@ func NewKubeFilter(opts options.ListenerOpts, srv options.ServerOptions, rbRefle
}

type kubeFilter struct {
allowedPaths sets.String
allowedPaths sets.Set[string]
authTypes []req.AuthType
ignoredUserGroups sets.String
ignoredUserGroups sets.Set[string]
reverseProxy *httputil.ReverseProxy
bearerToken string
usernameClaimField string
Expand Down

0 comments on commit 1dae49a

Please sign in to comment.