golangci-lint fixes.

This commit is contained in:
Tommie Gannert 2022-05-25 19:05:16 +02:00
parent 6de730b2ee
commit 46b4abd4cf
4 changed files with 9 additions and 10 deletions

View file

@ -39,7 +39,6 @@ type oauth2IdentityProvider struct {
scopes []string scopes []string
responseMimeType string responseMimeType string
issPath string
subPath string subPath string
emailPath string emailPath string
displayNamePath string displayNamePath string
@ -79,7 +78,7 @@ func (p *oauth2IdentityProvider) ProcessCallback(ctx context.Context, callbackUR
desc = error desc = error
} }
switch error { switch error {
case "unauthorized_client", "access_denied": case "unauthorized_client", "access_denied": // nolint:misspell
return nil, jsonerror.Forbidden("SSO said no: " + desc) return nil, jsonerror.Forbidden("SSO said no: " + desc)
default: default:
return nil, fmt.Errorf("SSO failed: %v", error) return nil, fmt.Errorf("SSO failed: %v", error)
@ -135,7 +134,7 @@ func (p *oauth2IdentityProvider) getAccessToken(ctx context.Context, callbackURL
if err != nil { if err != nil {
return "", err return "", err
} }
defer hresp.Body.Close() defer hresp.Body.Close() // nolint:errcheck
var resp oauth2TokenResponse var resp oauth2TokenResponse
if err := json.NewDecoder(hresp.Body).Decode(&resp); err != nil { if err := json.NewDecoder(hresp.Body).Decode(&resp); err != nil {
@ -178,7 +177,7 @@ func (p *oauth2IdentityProvider) getUserInfo(ctx context.Context, accessToken st
if err != nil { if err != nil {
return "", "", "", err return "", "", "", err
} }
defer hresp.Body.Close() defer hresp.Body.Close() // nolint:errcheck
body, err := ioutil.ReadAll(hresp.Body) body, err := ioutil.ReadAll(hresp.Body)
if err != nil { if err != nil {

View file

@ -136,7 +136,7 @@ func oidcDiscover(ctx context.Context, url string) (*oidcDiscovery, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer hresp.Body.Close() defer hresp.Body.Close() // nolint:errcheck
var disc oidcDiscovery var disc oidcDiscovery
if err := json.NewDecoder(hresp.Body).Decode(&disc); err != nil { if err := json.NewDecoder(hresp.Body).Decode(&disc); err != nil {

View file

@ -193,7 +193,7 @@ func SSOCallback(
return util.RedirectResponse(result.RedirectURL) return util.RedirectResponse(result.RedirectURL)
} }
localpart, err := verifySSOUserIdentifier(ctx, userAPI, result.Identifier, serverName) localpart, err := verifySSOUserIdentifier(ctx, userAPI, result.Identifier)
if err != nil { if err != nil {
util.GetLogger(ctx).WithError(err).WithField("ssoIdentifier", result.Identifier).Error("failed to find user") util.GetLogger(ctx).WithError(err).WithField("ssoIdentifier", result.Identifier).Error("failed to find user")
return util.JSONResponse{ return util.JSONResponse{
@ -278,7 +278,7 @@ func parseNonce(s string) (redirectURL *url.URL, _ error) {
// verifySSOUserIdentifier resolves an sso.UserIdentifier to a local // verifySSOUserIdentifier resolves an sso.UserIdentifier to a local
// part using the User API. Returns empty if there is no associated // part using the User API. Returns empty if there is no associated
// user. // user.
func verifySSOUserIdentifier(ctx context.Context, userAPI userAPIForSSO, id *sso.UserIdentifier, serverName gomatrixserverlib.ServerName) (localpart string, _ error) { func verifySSOUserIdentifier(ctx context.Context, userAPI userAPIForSSO, id *sso.UserIdentifier) (localpart string, _ error) {
req := &uapi.QueryLocalpartForSSORequest{ req := &uapi.QueryLocalpartForSSORequest{
Namespace: id.Namespace, Namespace: id.Namespace,
Issuer: id.Issuer, Issuer: id.Issuer,

View file

@ -190,11 +190,11 @@ type IdentityProvider struct {
func (idp *IdentityProvider) Verify(configErrs *ConfigErrors) { func (idp *IdentityProvider) Verify(configErrs *ConfigErrors) {
checkNotEmpty(configErrs, "client_api.sso.providers.id", idp.ID) checkNotEmpty(configErrs, "client_api.sso.providers.id", idp.ID)
if !checkIdentityProviderBrand(SSOBrand(idp.ID)) { if !checkIdentityProviderBrand(SSOBrand(idp.ID)) {
configErrs.Add(fmt.Sprintf("unrecognized ID config key %q: %s", "client_api.sso.providers", idp.ID)) configErrs.Add(fmt.Sprintf("unrecognised ID config key %q: %s", "client_api.sso.providers", idp.ID))
} }
checkNotEmpty(configErrs, "client_api.sso.providers.name", idp.Name) checkNotEmpty(configErrs, "client_api.sso.providers.name", idp.Name)
if idp.Brand != "" && !checkIdentityProviderBrand(idp.Brand) { if idp.Brand != "" && !checkIdentityProviderBrand(idp.Brand) {
configErrs.Add(fmt.Sprintf("unrecognized brand in identity provider %q for config key %q: %s", idp.ID, "client_api.sso.providers", idp.Brand)) configErrs.Add(fmt.Sprintf("unrecognised brand in identity provider %q for config key %q: %s", idp.ID, "client_api.sso.providers", idp.Brand))
} }
if idp.Icon != "" { if idp.Icon != "" {
checkURL(configErrs, "client_api.sso.providers.icon", idp.Icon) checkURL(configErrs, "client_api.sso.providers.icon", idp.Icon)
@ -215,7 +215,7 @@ func (idp *IdentityProvider) Verify(configErrs *ConfigErrors) {
checkNotEmpty(configErrs, "client_api.sso.providers.oidc.client_secret", idp.OIDC.ClientSecret) checkNotEmpty(configErrs, "client_api.sso.providers.oidc.client_secret", idp.OIDC.ClientSecret)
default: default:
configErrs.Add(fmt.Sprintf("unrecognized type in identity provider %q for config key %q: %s", idp.ID, "client_api.sso.providers", typ)) configErrs.Add(fmt.Sprintf("unrecognised type in identity provider %q for config key %q: %s", idp.ID, "client_api.sso.providers", typ))
} }
} }