From 6850db639552d762776df2ebbb96ac0c61399af2 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Tue, 20 Sep 2022 13:15:26 +0100 Subject: [PATCH] Fix API wiring, linting --- clientapi/auth/sso/oauth2.go | 6 +++--- cmd/generate-config/main.go | 40 +++++++++++++++++------------------ userapi/inthttp/client_sso.go | 34 +++++++++++++---------------- 3 files changed, 38 insertions(+), 42 deletions(-) diff --git a/clientapi/auth/sso/oauth2.go b/clientapi/auth/sso/oauth2.go index c36fa8c43..7e81027d5 100644 --- a/clientapi/auth/sso/oauth2.go +++ b/clientapi/auth/sso/oauth2.go @@ -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] diff --git a/cmd/generate-config/main.go b/cmd/generate-config/main.go index be34b58f0..1a3f221ee 100644 --- a/cmd/generate-config/main.go +++ b/cmd/generate-config/main.go @@ -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{} diff --git a/userapi/inthttp/client_sso.go b/userapi/inthttp/client_sso.go index e34130ed0..4e1a24dfe 100644 --- a/userapi/inthttp/client_sso.go +++ b/userapi/inthttp/client_sso.go @@ -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, + ) }