Fix API wiring, linting

This commit is contained in:
Neil Alexander 2022-09-20 13:15:26 +01:00
parent d67ffb2df4
commit 6850db6395
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
3 changed files with 38 additions and 42 deletions

View file

@ -18,7 +18,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"strings"
@ -168,7 +168,7 @@ func (p *oauth2IdentityProvider) getUserInfo(ctx context.Context, accessToken st
}
defer hresp.Body.Close() // nolint:errcheck
body, err := ioutil.ReadAll(hresp.Body)
body, err := io.ReadAll(hresp.Body)
if err != nil {
return "", "", "", err
}
@ -205,7 +205,7 @@ func httpDo(ctx context.Context, hc *http.Client, req *http.Request) (*http.Resp
contentType := resp.Header.Get("Content-Type")
switch {
case strings.HasPrefix(contentType, "text/plain"):
bs, err := ioutil.ReadAll(resp.Body)
bs, err := io.ReadAll(resp.Body)
if err == nil {
if len(bs) > 80 {
bs = bs[:80]

View file

@ -65,26 +65,26 @@ func main() {
if *defaultsForCI {
cfg.AppServiceAPI.DisableTLSValidation = true
cfg.ClientAPI.RateLimiting.Enabled = false
cfg.ClientAPI.Login.SSO.Enabled = true
cfg.ClientAPI.Login.SSO.Providers = []config.IdentityProvider{
{
Brand: "github",
OAuth2: config.OAuth2{
ClientID: "aclientid",
ClientSecret: "aclientsecret",
},
},
{
Brand: "google",
OAuth2: config.OAuth2{
ClientID: "aclientid",
ClientSecret: "aclientsecret",
},
OIDC: config.OIDC{
DiscoveryURL: "https://accounts.google.com/.well-known/openid-configuration",
},
},
}
cfg.ClientAPI.Login.SSO.Enabled = true
cfg.ClientAPI.Login.SSO.Providers = []config.IdentityProvider{
{
Brand: "github",
OAuth2: config.OAuth2{
ClientID: "aclientid",
ClientSecret: "aclientsecret",
},
},
{
Brand: "google",
OAuth2: config.OAuth2{
ClientID: "aclientid",
ClientSecret: "aclientsecret",
},
OIDC: config.OIDC{
DiscoveryURL: "https://accounts.google.com/.well-known/openid-configuration",
},
},
}
cfg.FederationAPI.DisableTLSValidation = false
// don't hit matrix.org when running tests!!!
cfg.FederationAPI.KeyPerspectives = config.KeyPerspectives{}

View file

@ -19,7 +19,6 @@ import (
"github.com/matrix-org/dendrite/internal/httputil"
"github.com/matrix-org/dendrite/userapi/api"
"github.com/opentracing/opentracing-go"
)
const (
@ -28,26 +27,23 @@ const (
QueryLocalpartForSSOPath = "/userapi/queryLocalpartForSSO"
)
func (h *httpUserInternalAPI) QueryLocalpartForSSO(ctx context.Context, req *api.QueryLocalpartForSSORequest, res *api.QueryLocalpartForSSOResponse) error {
span, ctx := opentracing.StartSpanFromContext(ctx, QueryLocalpartForSSOPath)
defer span.Finish()
apiURL := h.apiURL + QueryLocalpartForSSOPath
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
func (h *httpUserInternalAPI) QueryLocalpartForSSO(ctx context.Context, request *api.QueryLocalpartForSSORequest, response *api.QueryLocalpartForSSOResponse) error {
return httputil.CallInternalRPCAPI(
"QuerytLocalpartForSSO", h.apiURL+QueryLocalpartForSSOPath,
h.httpClient, ctx, request, response,
)
}
func (h *httpUserInternalAPI) PerformForgetSSO(ctx context.Context, req *api.PerformForgetSSORequest, res *struct{}) error {
span, ctx := opentracing.StartSpanFromContext(ctx, PerformForgetSSOPath)
defer span.Finish()
apiURL := h.apiURL + PerformForgetSSOPath
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
func (h *httpUserInternalAPI) PerformForgetSSO(ctx context.Context, request *api.PerformForgetSSORequest, response *struct{}) error {
return httputil.CallInternalRPCAPI(
"PerformForgetSSO", h.apiURL+PerformForgetSSOPath,
h.httpClient, ctx, request, response,
)
}
func (h *httpUserInternalAPI) PerformSaveSSOAssociation(ctx context.Context, req *api.PerformSaveSSOAssociationRequest, res *struct{}) error {
span, ctx := opentracing.StartSpanFromContext(ctx, PerformSaveSSOAssociationPath)
defer span.Finish()
apiURL := h.apiURL + PerformSaveSSOAssociationPath
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
func (h *httpUserInternalAPI) PerformSaveSSOAssociation(ctx context.Context, request *api.PerformSaveSSOAssociationRequest, response *struct{}) error {
return httputil.CallInternalRPCAPI(
"PerformSaveSSOAssociation", h.apiURL+PerformSaveSSOAssociationPath,
h.httpClient, ctx, request, response,
)
}