Skip to content

Commit 803db24

Browse files
committed
linting
1 parent bda9be8 commit 803db24

File tree

8 files changed

+42
-44
lines changed

8 files changed

+42
-44
lines changed

cli/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ import (
109109
"github.com/coder/coder/v2/tailnet"
110110
)
111111

112-
func createOIDCConfig(ctx context.Context, logger slog.Logger, entitlements *entitlements.Set, vals *codersdk.DeploymentValues) (*coderd.OIDCConfig, error) {
112+
func createOIDCConfig(ctx context.Context, logger slog.Logger, set *entitlements.Set, vals *codersdk.DeploymentValues) (*coderd.OIDCConfig, error) {
113113
if vals.OIDC.ClientID == "" {
114114
return nil, xerrors.Errorf("OIDC client ID must be set!")
115115
}
@@ -199,7 +199,7 @@ func createOIDCConfig(ctx context.Context, logger slog.Logger, entitlements *ent
199199
SignupsDisabledText: vals.OIDC.SignupsDisabledText.String(),
200200
IconURL: vals.OIDC.IconURL.String(),
201201
IgnoreEmailVerified: vals.OIDC.IgnoreEmailVerified.Value(),
202-
IDPSync: idpsync.NewSync(logger, entitlements, idpsync.SyncSettings{
202+
IDPSync: idpsync.NewSync(logger, set, idpsync.SyncSettings{
203203
OrganizationField: vals.OIDC.OrganizationField.Value(),
204204
OrganizationMapping: vals.OIDC.OrganizationMapping.Value,
205205
OrganizationAssignDefault: vals.OIDC.OrganizationAssignDefault.Value(),

coderd/idpsync/idpsync.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ import (
2323
// So instead, if the code is compiled with the enterprise logic, it will
2424
// override this function to return the enterprise IDP sync object.
2525
// For unit testing, the callers can specifically choose which "NewSync" to use.
26-
var NewSync = func(logger slog.Logger, entitlements *entitlements.Set, settings SyncSettings) IDPSync {
27-
return NewAGPLSync(logger, entitlements, settings)
26+
var NewSync = func(logger slog.Logger, set *entitlements.Set, settings SyncSettings) IDPSync {
27+
return NewAGPLSync(logger, set, settings)
2828
}
2929

3030
type IDPSync interface {
3131
// ParseOrganizationClaims takes claims from an OIDC provider, and returns the
3232
// organization sync params for assigning users into organizations.
33-
ParseOrganizationClaims(ctx context.Context, _ jwt.MapClaims) (OrganizationParams, *HttpError)
33+
ParseOrganizationClaims(ctx context.Context, _ jwt.MapClaims) (OrganizationParams, *HTTPError)
3434
// SyncOrganizations assigns and removed users from organizations based on the
3535
// provided params.
3636
SyncOrganizations(ctx context.Context, tx database.Store, user database.User, params OrganizationParams) error
@@ -111,18 +111,18 @@ func ParseStringSliceClaim(claim interface{}) ([]string, error) {
111111
return nil, xerrors.Errorf("invalid claim type. Expected an array of strings, got: %T", claim)
112112
}
113113

114-
// HttpError is a helper struct for returning errors from the IDP sync process.
114+
// HTTPError is a helper struct for returning errors from the IDP sync process.
115115
// A regular error is not sufficient because many of these errors are surfaced
116116
// to a user logging in, and the errors should be descriptive.
117-
type HttpError struct {
117+
type HTTPError struct {
118118
Code int
119119
Msg string
120120
Detail string
121121
RenderStaticPage bool
122122
RenderDetailMarkdown bool
123123
}
124124

125-
func (e HttpError) Write(rw http.ResponseWriter, r *http.Request) {
125+
func (e HTTPError) Write(rw http.ResponseWriter, r *http.Request) {
126126
if e.RenderStaticPage {
127127
site.RenderStaticErrorPage(rw, r, site.ErrorPageData{
128128
Status: e.Code,
@@ -142,7 +142,7 @@ func (e HttpError) Write(rw http.ResponseWriter, r *http.Request) {
142142
})
143143
}
144144

145-
func (e HttpError) Error() string {
145+
func (e HTTPError) Error() string {
146146
if e.Detail != "" {
147147
return e.Detail
148148
}

coderd/idpsync/organization.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ import (
1616
"github.com/coder/coder/v2/coderd/util/slice"
1717
)
1818

19-
func (s AGPLIDPSync) ParseOrganizationClaims(ctx context.Context, _ jwt.MapClaims) (OrganizationParams, *HttpError) {
20-
// nolint:gocritic // all syncing is done as a system user
21-
ctx = dbauthz.AsSystemRestricted(ctx)
22-
19+
func (s AGPLIDPSync) ParseOrganizationClaims(ctx context.Context, _ jwt.MapClaims) (OrganizationParams, *HTTPError) {
2320
// For AGPL we only sync the default organization.
2421
return OrganizationParams{
2522
SyncEnabled: false,

coderd/idpsync/organizations_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package idpsync
1+
package idpsync_test
22

33
import (
44
"testing"
@@ -9,6 +9,7 @@ import (
99

1010
"cdr.dev/slog/sloggers/slogtest"
1111
"github.com/coder/coder/v2/coderd/entitlements"
12+
"github.com/coder/coder/v2/coderd/idpsync"
1213
"github.com/coder/coder/v2/testutil"
1314
)
1415

@@ -18,7 +19,7 @@ func TestParseOrganizationClaims(t *testing.T) {
1819
t.Run("SingleOrgDeployment", func(t *testing.T) {
1920
t.Parallel()
2021

21-
s := NewAGPLSync(slogtest.Make(t, &slogtest.Options{}), entitlements.New(), SyncSettings{
22+
s := idpsync.NewAGPLSync(slogtest.Make(t, &slogtest.Options{}), entitlements.New(), idpsync.SyncSettings{
2223
OrganizationField: "",
2324
OrganizationMapping: nil,
2425
OrganizationAssignDefault: true,
@@ -38,7 +39,7 @@ func TestParseOrganizationClaims(t *testing.T) {
3839
t.Parallel()
3940

4041
// AGPL has limited behavior
41-
s := NewAGPLSync(slogtest.Make(t, &slogtest.Options{}), entitlements.New(), SyncSettings{
42+
s := idpsync.NewAGPLSync(slogtest.Make(t, &slogtest.Options{}), entitlements.New(), idpsync.SyncSettings{
4243
OrganizationField: "orgs",
4344
OrganizationMapping: map[string][]uuid.UUID{
4445
"random": {uuid.New()},

coderd/userauth.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ func (api *API) userOAuth2Github(rw http.ResponseWriter, r *http.Request) {
669669
})
670670
cookies, user, key, err := api.oauthLogin(r, params)
671671
defer params.CommitAuditLogs()
672-
var httpErr idpsync.HttpError
672+
var httpErr idpsync.HTTPError
673673
if xerrors.As(err, &httpErr) {
674674
httpErr.Write(rw, r)
675675
return
@@ -1069,7 +1069,7 @@ func (api *API) userOIDC(rw http.ResponseWriter, r *http.Request) {
10691069
})
10701070
cookies, user, key, err := api.oauthLogin(r, params)
10711071
defer params.CommitAuditLogs()
1072-
var httpErr idpsync.HttpError
1072+
var httpErr idpsync.HTTPError
10731073
if xerrors.As(err, &httpErr) {
10741074
httpErr.Write(rw, r)
10751075
return
@@ -1097,7 +1097,7 @@ func (api *API) userOIDC(rw http.ResponseWriter, r *http.Request) {
10971097
}
10981098

10991099
// oidcGroups returns the groups for the user from the OIDC claims.
1100-
func (api *API) oidcGroups(ctx context.Context, mergedClaims map[string]interface{}) (bool, []string, *idpsync.HttpError) {
1100+
func (api *API) oidcGroups(ctx context.Context, mergedClaims map[string]interface{}) (bool, []string, *idpsync.HTTPError) {
11011101
logger := api.Logger.Named(userAuthLoggerName)
11021102
usingGroups := false
11031103
var groups []string
@@ -1118,7 +1118,7 @@ func (api *API) oidcGroups(ctx context.Context, mergedClaims map[string]interfac
11181118
slog.F("type", fmt.Sprintf("%T", groupsRaw)),
11191119
slog.Error(err),
11201120
)
1121-
return false, nil, &idpsync.HttpError{
1121+
return false, nil, &idpsync.HTTPError{
11221122
Code: http.StatusBadRequest,
11231123
Msg: "Failed to sync groups from OIDC claims",
11241124
Detail: err.Error(),
@@ -1151,7 +1151,7 @@ func (api *API) oidcGroups(ctx context.Context, mergedClaims map[string]interfac
11511151
if len(groups) == 0 {
11521152
detail = "You are currently not a member of any groups! Ask an administrator to add you to an authorized group to login."
11531153
}
1154-
return usingGroups, groups, &idpsync.HttpError{
1154+
return usingGroups, groups, &idpsync.HTTPError{
11551155
Code: http.StatusForbidden,
11561156
Msg: "Not a member of an allowed group",
11571157
Detail: detail,
@@ -1175,7 +1175,7 @@ func (api *API) oidcGroups(ctx context.Context, mergedClaims map[string]interfac
11751175
// It would be preferred to just return an error, however this function
11761176
// decorates returned errors with the appropriate HTTP status codes and details
11771177
// that are hard to carry in a standard `error` without more work.
1178-
func (api *API) oidcRoles(ctx context.Context, mergedClaims map[string]interface{}) ([]string, *idpsync.HttpError) {
1178+
func (api *API) oidcRoles(ctx context.Context, mergedClaims map[string]interface{}) ([]string, *idpsync.HTTPError) {
11791179
roles := api.OIDCConfig.UserRolesDefault
11801180
if !api.OIDCConfig.RoleSyncEnabled() {
11811181
return roles, nil
@@ -1197,7 +1197,7 @@ func (api *API) oidcRoles(ctx context.Context, mergedClaims map[string]interface
11971197
slog.F("type", fmt.Sprintf("%T", rolesRow)),
11981198
slog.Error(err),
11991199
)
1200-
return nil, &idpsync.HttpError{
1200+
return nil, &idpsync.HTTPError{
12011201
Code: http.StatusInternalServerError,
12021202
Msg: "Login disabled until OIDC config is fixed",
12031203
Detail: fmt.Sprintf("Roles claim must be an array of strings, type found: %T. Disabling role sync will allow login to proceed.", rolesRow),
@@ -1358,7 +1358,7 @@ func (api *API) oauthLogin(r *http.Request, params *oauthLoginParams) ([]*http.C
13581358
if api.OIDCConfig != nil && api.OIDCConfig.SignupsDisabledText != "" {
13591359
signupsDisabledText = render.HTMLFromMarkdown(api.OIDCConfig.SignupsDisabledText)
13601360
}
1361-
return &idpsync.HttpError{
1361+
return &idpsync.HTTPError{
13621362
Code: http.StatusForbidden,
13631363
Msg: "Signups are disabled",
13641364
Detail: signupsDisabledText,
@@ -1409,7 +1409,7 @@ func (api *API) oauthLogin(r *http.Request, params *oauthLoginParams) ([]*http.C
14091409
}
14101410
}
14111411
if !validUsername {
1412-
return &idpsync.HttpError{
1412+
return &idpsync.HTTPError{
14131413
Code: http.StatusConflict,
14141414
Msg: fmt.Sprintf("exhausted alternatives for taken username %q", original),
14151415
}
@@ -1564,7 +1564,7 @@ func (api *API) oauthLogin(r *http.Request, params *oauthLoginParams) ([]*http.C
15641564
//nolint:gocritic
15651565
err := api.Options.SetUserSiteRoles(dbauthz.AsSystemRestricted(ctx), logger, tx, user.ID, filtered)
15661566
if err != nil {
1567-
return &idpsync.HttpError{
1567+
return &idpsync.HTTPError{
15681568
Code: http.StatusBadRequest,
15691569
Msg: "Invalid roles through OIDC claims",
15701570
Detail: fmt.Sprintf("Error from role assignment attempt: %s", err.Error()),
@@ -1679,15 +1679,15 @@ func (api *API) convertUserToOauth(ctx context.Context, r *http.Request, db data
16791679
// Trying to convert to OIDC, but the email does not match.
16801680
// So do not make a new user, just block the request.
16811681
if user.ID == uuid.Nil {
1682-
return database.User{}, idpsync.HttpError{
1682+
return database.User{}, idpsync.HTTPError{
16831683
Code: http.StatusBadRequest,
16841684
Msg: fmt.Sprintf("The oidc account with the email %q does not match the email of the account you are trying to convert. Contact your administrator to resolve this issue.", params.Email),
16851685
}
16861686
}
16871687

16881688
jwtCookie, err := r.Cookie(OAuthConvertCookieValue)
16891689
if err != nil {
1690-
return database.User{}, idpsync.HttpError{
1690+
return database.User{}, idpsync.HTTPError{
16911691
Code: http.StatusBadRequest,
16921692
Msg: fmt.Sprintf("Convert to oauth cookie not found. Missing signed jwt to authorize this action. " +
16931693
"Please try again."),
@@ -1699,13 +1699,13 @@ func (api *API) convertUserToOauth(ctx context.Context, r *http.Request, db data
16991699
})
17001700
if xerrors.Is(err, jwt.ErrSignatureInvalid) || !token.Valid {
17011701
// These errors are probably because the user is mixing 2 coder deployments.
1702-
return database.User{}, idpsync.HttpError{
1702+
return database.User{}, idpsync.HTTPError{
17031703
Code: http.StatusBadRequest,
17041704
Msg: "Using an invalid jwt to authorize this action. Ensure there is only 1 coder deployment and try again.",
17051705
}
17061706
}
17071707
if err != nil {
1708-
return database.User{}, idpsync.HttpError{
1708+
return database.User{}, idpsync.HTTPError{
17091709
Code: http.StatusInternalServerError,
17101710
Msg: fmt.Sprintf("Error parsing jwt: %v", err),
17111711
}
@@ -1727,14 +1727,14 @@ func (api *API) convertUserToOauth(ctx context.Context, r *http.Request, db data
17271727
oauthConvertAudit.Old = user
17281728

17291729
if claims.RegisteredClaims.Issuer != api.DeploymentID {
1730-
return database.User{}, idpsync.HttpError{
1730+
return database.User{}, idpsync.HTTPError{
17311731
Code: http.StatusForbidden,
17321732
Msg: "Request to convert login type failed. Issuer mismatch. Found a cookie from another coder deployment, please try again.",
17331733
}
17341734
}
17351735

17361736
if params.State.StateString != claims.State {
1737-
return database.User{}, idpsync.HttpError{
1737+
return database.User{}, idpsync.HTTPError{
17381738
Code: http.StatusForbidden,
17391739
Msg: "Request to convert login type failed. State mismatch.",
17401740
}
@@ -1746,7 +1746,7 @@ func (api *API) convertUserToOauth(ctx context.Context, r *http.Request, db data
17461746
if user.ID != claims.UserID ||
17471747
codersdk.LoginType(user.LoginType) != claims.FromLoginType ||
17481748
codersdk.LoginType(params.LoginType) != claims.ToLoginType {
1749-
return database.User{}, idpsync.HttpError{
1749+
return database.User{}, idpsync.HTTPError{
17501750
Code: http.StatusForbidden,
17511751
Msg: fmt.Sprintf("Request to convert login type from %s to %s failed", user.LoginType, params.LoginType),
17521752
}
@@ -1762,7 +1762,7 @@ func (api *API) convertUserToOauth(ctx context.Context, r *http.Request, db data
17621762
UserID: user.ID,
17631763
})
17641764
if err != nil {
1765-
return database.User{}, idpsync.HttpError{
1765+
return database.User{}, idpsync.HTTPError{
17661766
Code: http.StatusInternalServerError,
17671767
Msg: "Failed to convert user to new login type",
17681768
}
@@ -1850,12 +1850,12 @@ func clearOAuthConvertCookie() *http.Cookie {
18501850
}
18511851
}
18521852

1853-
func wrongLoginTypeHTTPError(user database.LoginType, params database.LoginType) idpsync.HttpError {
1853+
func wrongLoginTypeHTTPError(user database.LoginType, params database.LoginType) idpsync.HTTPError {
18541854
addedMsg := ""
18551855
if user == database.LoginTypePassword {
18561856
addedMsg = " You can convert your account to use this login type by visiting your account settings."
18571857
}
1858-
return idpsync.HttpError{
1858+
return idpsync.HTTPError{
18591859
Code: http.StatusForbidden,
18601860
RenderStaticPage: true,
18611861
Msg: "Incorrect login type",

enterprise/coderd/enidpsync/enidpsync.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ type EnterpriseIDPSync struct {
1818
*idpsync.AGPLIDPSync
1919
}
2020

21-
func NewSync(logger slog.Logger, entitlements *entitlements.Set, settings idpsync.SyncSettings) *EnterpriseIDPSync {
21+
func NewSync(logger slog.Logger, set *entitlements.Set, settings idpsync.SyncSettings) *EnterpriseIDPSync {
2222
return &EnterpriseIDPSync{
23-
entitlements: entitlements,
24-
AGPLIDPSync: idpsync.NewAGPLSync(logger.With(slog.F("enterprise_capable", "true")), entitlements, settings),
23+
entitlements: set,
24+
AGPLIDPSync: idpsync.NewAGPLSync(logger.With(slog.F("enterprise_capable", "true")), set, settings),
2525
}
2626
}

enterprise/coderd/enidpsync/organizations.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/coder/coder/v2/codersdk"
1515
)
1616

17-
func (e EnterpriseIDPSync) ParseOrganizationClaims(ctx context.Context, mergedClaims jwt.MapClaims) (idpsync.OrganizationParams, *idpsync.HttpError) {
17+
func (e EnterpriseIDPSync) ParseOrganizationClaims(ctx context.Context, mergedClaims jwt.MapClaims) (idpsync.OrganizationParams, *idpsync.HTTPError) {
1818
if !e.entitlements.Enabled(codersdk.FeatureMultipleOrganizations) {
1919
// Default to agpl if multi-org is not enabled
2020
return e.AGPLIDPSync.ParseOrganizationClaims(ctx, mergedClaims)
@@ -30,7 +30,7 @@ func (e EnterpriseIDPSync) ParseOrganizationClaims(ctx context.Context, mergedCl
3030
if ok {
3131
parsedOrganizations, err := idpsync.ParseStringSliceClaim(organizationRaw)
3232
if err != nil {
33-
return idpsync.OrganizationParams{}, &idpsync.HttpError{
33+
return idpsync.OrganizationParams{}, &idpsync.HTTPError{
3434
Code: http.StatusBadRequest,
3535
Msg: "Failed to sync organizations from the OIDC claims",
3636
Detail: err.Error(),

enterprise/coderd/enidpsync/organizations_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package enidpsync
1+
package enidpsync_test
22

33
import (
44
"context"
@@ -32,7 +32,7 @@ type Expectations struct {
3232
Name string
3333
Claims jwt.MapClaims
3434
// Parse
35-
ParseError func(t *testing.T, httpErr *idpsync.HttpError)
35+
ParseError func(t *testing.T, httpErr *idpsync.HTTPError)
3636
ExpectedParams idpsync.OrganizationParams
3737
// Mutate allows mutating the user before syncing
3838
Mutate func(t *testing.T, db database.Store, user database.User)
@@ -235,7 +235,7 @@ func TestOrganizationSync(t *testing.T) {
235235
}
236236

237237
// Create a new sync object
238-
sync := NewSync(logger, caseData.Entitlements, caseData.Settings)
238+
sync := idpsync.NewSync(logger, caseData.Entitlements, caseData.Settings)
239239
for _, exp := range caseData.Exps {
240240
t.Run(exp.Name, func(t *testing.T) {
241241
params, httpErr := sync.ParseOrganizationClaims(ctx, exp.Claims)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy