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

View file

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