Skip to content

Commit a304756

Browse files
committed
fix: sonarcloud issues
Use pointer receivers and use methods instead of attributes for proto fields
1 parent af1179a commit a304756

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

services/idp/pkg/service/v0/service.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func NewService(opts ...Option) Service {
123123
routes := []server.WithRoutes{managers.Must("identity").(server.WithRoutes)}
124124
handlers := managers.Must("handler").(http.Handler)
125125

126-
svc := IDP{
126+
svc := &IDP{
127127
logger: options.Logger,
128128
config: options.Config,
129129
assets: assetVFS,
@@ -294,12 +294,12 @@ func (idp *IDP) initMux(ctx context.Context, r []server.WithRoutes, h http.Handl
294294
}
295295

296296
// ServeHTTP implements the Service interface.
297-
func (idp IDP) ServeHTTP(w http.ResponseWriter, r *http.Request) {
297+
func (idp *IDP) ServeHTTP(w http.ResponseWriter, r *http.Request) {
298298
idp.mux.ServeHTTP(w, r)
299299
}
300300

301301
// Index renders the static html with templated variables.
302-
func (idp IDP) Index() http.HandlerFunc {
302+
func (idp *IDP) Index() http.HandlerFunc {
303303
f, err := idp.assets.Open("/identifier/index.html")
304304
if err != nil {
305305
idp.logger.Fatal().Err(err).Msg("Could not open index template")

services/proxy/pkg/user/backend/cs3.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,14 @@ func (c *cs3backend) GetUserByClaims(ctx context.Context, claim, value string) (
125125
switch {
126126
case err != nil:
127127
return nil, "", fmt.Errorf("could not get user by claim %v with value %v: %w", claim, value, err)
128-
case res.Status.Code != rpcv1beta1.Code_CODE_OK:
129-
if res.Status.Code == rpcv1beta1.Code_CODE_NOT_FOUND {
128+
case res.GetStatus().GetCode() != rpcv1beta1.Code_CODE_OK:
129+
if res.GetStatus().GetCode() == rpcv1beta1.Code_CODE_NOT_FOUND {
130130
return nil, "", ErrAccountNotFound
131131
}
132132
return nil, "", fmt.Errorf("could not get user by claim %v with value %v : %s ", claim, value, res.GetStatus().GetMessage())
133133
}
134134

135-
user := res.User
135+
user := res.GetUser()
136136

137137
return user, res.GetToken(), nil
138138
}
@@ -152,11 +152,11 @@ func (c *cs3backend) Authenticate(ctx context.Context, username string, password
152152
switch {
153153
case err != nil:
154154
return nil, "", fmt.Errorf("could not authenticate with username and password user: %s, %w", username, err)
155-
case res.Status.Code != rpcv1beta1.Code_CODE_OK:
155+
case res.GetStatus().GetCode() != rpcv1beta1.Code_CODE_OK:
156156
return nil, "", fmt.Errorf("could not authenticate with username and password user: %s, got code: %d", username, res.GetStatus().GetCode())
157157
}
158158

159-
return res.User, res.Token, nil
159+
return res.GetUser(), res.GetToken(), nil
160160
}
161161

162162
// CreateUserFromClaims creates a new user via libregraph users API, taking the
@@ -235,7 +235,7 @@ func (c *cs3backend) CreateUserFromClaims(ctx context.Context, claims map[string
235235
return &cs3UserCreated, nil
236236
}
237237

238-
func (c cs3backend) UpdateUserIfNeeded(ctx context.Context, user *cs3.User, claims map[string]interface{}) error {
238+
func (c *cs3backend) UpdateUserIfNeeded(ctx context.Context, user *cs3.User, claims map[string]interface{}) error {
239239
newUser, err := c.libregraphUserFromClaims(claims)
240240
if err != nil {
241241
c.logger.Error().Err(err).Interface("claims", claims).Msg("Error converting claims to user")
@@ -260,7 +260,7 @@ func (c cs3backend) UpdateUserIfNeeded(ctx context.Context, user *cs3.User, clai
260260
}
261261

262262
// SyncGroupMemberships maintains a users group memberships based on an OIDC claim
263-
func (c cs3backend) SyncGroupMemberships(ctx context.Context, user *cs3.User, claims map[string]interface{}) error {
263+
func (c *cs3backend) SyncGroupMemberships(ctx context.Context, user *cs3.User, claims map[string]interface{}) error {
264264
gatewayClient, err := c.gatewaySelector.Next()
265265
if err != nil {
266266
c.logger.Error().Err(err).Msg("could not select next gateway client")
@@ -378,7 +378,7 @@ func (c cs3backend) SyncGroupMemberships(ctx context.Context, user *cs3.User, cl
378378
return nil
379379
}
380380

381-
func (c cs3backend) getLibregraphGroup(ctx context.Context, client *libregraph.APIClient, group string) (*libregraph.Group, error) {
381+
func (c *cs3backend) getLibregraphGroup(ctx context.Context, client *libregraph.APIClient, group string) (*libregraph.Group, error) {
382382
lgGroup, resp, err := client.GroupApi.GetGroup(ctx, group).Execute()
383383
if resp != nil {
384384
defer resp.Body.Close()
@@ -396,7 +396,7 @@ func (c cs3backend) getLibregraphGroup(ctx context.Context, client *libregraph.A
396396
return lgGroup, nil
397397
}
398398

399-
func (c cs3backend) updateLibregraphUser(userid string, user libregraph.UserUpdate) error {
399+
func (c *cs3backend) updateLibregraphUser(userid string, user libregraph.UserUpdate) error {
400400
gatewayClient, err := c.gatewaySelector.Next()
401401
if err != nil {
402402
c.logger.Error().Err(err).Msg("could not select next gateway client")
@@ -427,7 +427,7 @@ func (c cs3backend) updateLibregraphUser(userid string, user libregraph.UserUpda
427427
return nil
428428
}
429429

430-
func (c cs3backend) setupLibregraphClient(ctx context.Context, cs3token string) (*libregraph.APIClient, error) {
430+
func (c *cs3backend) setupLibregraphClient(ctx context.Context, cs3token string) (*libregraph.APIClient, error) {
431431
// Use micro registry to resolve next graph service endpoint
432432
next, err := c.graphSelector.Select("com.owncloud.web.graph")
433433
if err != nil {
@@ -454,7 +454,7 @@ func (c cs3backend) setupLibregraphClient(ctx context.Context, cs3token string)
454454
return libregraph.NewAPIClient(lgconf), nil
455455
}
456456

457-
func (c cs3backend) isAlreadyExists(resp *http.Response) (bool, error) {
457+
func (c *cs3backend) isAlreadyExists(resp *http.Response) (bool, error) {
458458
oDataErr := libregraph.NewOdataErrorWithDefaults()
459459
body, err := io.ReadAll(resp.Body)
460460
if err != nil {
@@ -475,7 +475,7 @@ func (c cs3backend) isAlreadyExists(resp *http.Response) (bool, error) {
475475
return false, nil
476476
}
477477

478-
func (c cs3backend) libregraphUserFromClaims(claims map[string]interface{}) (libregraph.User, error) {
478+
func (c *cs3backend) libregraphUserFromClaims(claims map[string]interface{}) (libregraph.User, error) {
479479
user := libregraph.User{}
480480
if dn, ok := claims[c.autoProvisionClaims.DisplayName].(string); ok {
481481
user.SetDisplayName(dn)
@@ -505,7 +505,7 @@ func (c cs3backend) libregraphUserFromClaims(claims map[string]interface{}) (lib
505505
return user, nil
506506
}
507507

508-
func (c cs3backend) cs3UserFromLibregraph(_ context.Context, lu *libregraph.User) cs3.User {
508+
func (c *cs3backend) cs3UserFromLibregraph(_ context.Context, lu *libregraph.User) cs3.User {
509509
cs3id := cs3.UserId{
510510
Type: cs3.UserType_USER_TYPE_PRIMARY,
511511
Idp: c.oidcISS,

services/userlog/pkg/service/http.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ func RequireAdminOrSecret(rm *roles.Manager, secret string) func(http.HandlerFun
255255
return func(next http.HandlerFunc) http.HandlerFunc {
256256
return func(w http.ResponseWriter, r *http.Request) {
257257
// allow bypassing admin requirement by sending the correct secret
258-
if secret != "" && r.Header.Get("secret") == secret {
258+
if secret != "" && r.Header.Get("Secret") == secret {
259259
next.ServeHTTP(w, r)
260260
return
261261
}

0 commit comments

Comments
 (0)