From 8fcc626d7bba508415f5ba3e43082f1f20eff689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pablo=20Villaf=C3=A1=C3=B1ez?= Date: Wed, 13 Mar 2024 14:52:33 +0100 Subject: [PATCH] ci: adjust code for sonarcloud issues --- services/collaboration/pkg/internal/app/claims.go | 2 +- services/collaboration/pkg/internal/app/wopidiscovery.go | 4 ++-- services/collaboration/pkg/internal/helpers/download.go | 4 +++- services/collaboration/pkg/internal/helpers/upload.go | 2 +- services/collaboration/pkg/service/grpc/v0/service.go | 6 +++--- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/services/collaboration/pkg/internal/app/claims.go b/services/collaboration/pkg/internal/app/claims.go index 6715996261..e310c7e3b7 100644 --- a/services/collaboration/pkg/internal/app/claims.go +++ b/services/collaboration/pkg/internal/app/claims.go @@ -4,5 +4,5 @@ import "github.com/golang-jwt/jwt/v4" type Claims struct { WopiContext WopiContext `json:"WopiContext"` - jwt.StandardClaims + jwt.RegisteredClaims } diff --git a/services/collaboration/pkg/internal/app/wopidiscovery.go b/services/collaboration/pkg/internal/app/wopidiscovery.go index 29a2e6cd7a..1e8ae29bef 100644 --- a/services/collaboration/pkg/internal/app/wopidiscovery.go +++ b/services/collaboration/pkg/internal/app/wopidiscovery.go @@ -45,6 +45,8 @@ func getAppURLs(wopiAppUrl string, insecure bool, logger log.Logger) (map[string return nil, err } + defer httpResp.Body.Close() + if httpResp.StatusCode != http.StatusOK { logger.Error(). Str("WopiAppUrl", wopiAppUrl). @@ -53,8 +55,6 @@ func getAppURLs(wopiAppUrl string, insecure bool, logger log.Logger) (map[string return nil, errors.New("status code was not 200") } - defer httpResp.Body.Close() - var appURLs map[string]map[string]string appURLs, err = parseWopiDiscovery(httpResp.Body) diff --git a/services/collaboration/pkg/internal/helpers/download.go b/services/collaboration/pkg/internal/helpers/download.go index ee0568f598..acba7a3753 100644 --- a/services/collaboration/pkg/internal/helpers/download.go +++ b/services/collaboration/pkg/internal/helpers/download.go @@ -92,7 +92,9 @@ func DownloadFile( // TODO: the access token shouldn't be needed httpReq.Header.Add("X-Access-Token", token) - httpResp, err := httpClient.Do(httpReq) + // TODO: this needs a refactor to comply with the "bodyclose" linter + // response body is closed in the caller method for now + httpResp, err := httpClient.Do(httpReq) //nolint:bodyclose if err != nil { logger.Error(). Err(err). diff --git a/services/collaboration/pkg/internal/helpers/upload.go b/services/collaboration/pkg/internal/helpers/upload.go index 95e0da2214..0a40220a71 100644 --- a/services/collaboration/pkg/internal/helpers/upload.go +++ b/services/collaboration/pkg/internal/helpers/upload.go @@ -18,7 +18,7 @@ import ( func UploadFile( ctx context.Context, - content io.ReadCloser, + content io.Reader, // content won't be closed inside the method contentLength int64, ref *providerv1beta1.Reference, gwc gatewayv1beta1.GatewayAPIClient, diff --git a/services/collaboration/pkg/service/grpc/v0/service.go b/services/collaboration/pkg/service/grpc/v0/service.go index 5c1fe9ad23..90b2da7375 100644 --- a/services/collaboration/pkg/service/grpc/v0/service.go +++ b/services/collaboration/pkg/service/grpc/v0/service.go @@ -170,7 +170,7 @@ func (s *Service) OpenInApp( ViewAppUrl: viewAppURL, } - cs3Claims := &jwt.StandardClaims{} + cs3Claims := &jwt.RegisteredClaims{} cs3JWTparser := jwt.Parser{} _, _, err = cs3JWTparser.ParseUnverified(req.AccessToken, cs3Claims) if err != nil { @@ -185,7 +185,7 @@ func (s *Service) OpenInApp( claims := &app.Claims{ WopiContext: wopiContext, - StandardClaims: jwt.StandardClaims{ + RegisteredClaims: jwt.RegisteredClaims{ ExpiresAt: cs3Claims.ExpiresAt, }, } @@ -220,7 +220,7 @@ func (s *Service) OpenInApp( // these parameters will be passed to the web server by the app provider application "access_token": accessToken, // milliseconds since Jan 1, 1970 UTC as required in https://docs.microsoft.com/en-us/microsoft-365/cloud-storage-partner-program/rest/concepts#access_token_ttl - "access_token_ttl": strconv.FormatInt(claims.ExpiresAt*1000, 10), + "access_token_ttl": strconv.FormatInt(claims.ExpiresAt.UnixMilli(), 10), }, }, }, nil