From 8d3dee77ac9ca89f7d4205d90e5324d96d988bcc Mon Sep 17 00:00:00 2001 From: "c_jean.silva" Date: Mon, 16 Dec 2024 20:49:44 -0300 Subject: [PATCH] fix: ajusts gateway --- src/funcs/generate_token/main.go | 38 ++------------------------------ 1 file changed, 2 insertions(+), 36 deletions(-) diff --git a/src/funcs/generate_token/main.go b/src/funcs/generate_token/main.go index 4305603..2857204 100644 --- a/src/funcs/generate_token/main.go +++ b/src/funcs/generate_token/main.go @@ -1,7 +1,6 @@ package main import ( - "encoding/json" "io" "log" "net/http" @@ -10,30 +9,12 @@ import ( "github.com/aws/aws-lambda-go/events" "github.com/aws/aws-lambda-go/lambda" - "github.com/go-playground/validator/v10" ) func handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) { var postValidateTokenUrl = os.Getenv("BACKEND_URL") - requestBody := struct { - Document string `json:"document"` - }{} - err := json.Unmarshal([]byte(request.Body), &requestBody) - if err != nil { - log.Printf("Error parsing request body: %v", err) - return events.APIGatewayProxyResponse{ - Body: "Error parsing request body", - StatusCode: 500, - }, nil - } - - if requestBody.Document == "" { - return events.APIGatewayProxyResponse{ - Body: "Please provide a document parameter", - StatusCode: 400, - }, nil - } - + log.Printf("request-body: %v", request.Body) + log.Printf("request-body-fmt: %v", strings.NewReader(request.Body)) resp, err := http.Post(postValidateTokenUrl, "application/json", strings.NewReader(request.Body)) if err != nil { log.Printf("Error getting access token: %v", err) @@ -55,21 +36,6 @@ func handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyRespo } defer resp.Body.Close() - // Validate the response before returning it - accessTokenResponse := struct { - AccessToken string `json:"access_token" validate:"required"` - Profile string `json:"profile" validate:"required"` - }{} - err = json.Unmarshal(body, &accessTokenResponse) - if err != nil || validator.New().Struct(accessTokenResponse) != nil { - log.Printf("Response: %s", body) - log.Printf("Error parsing access token: %v", err) - return events.APIGatewayProxyResponse{ - Body: "Error parsing access token", - StatusCode: 500, - }, nil - } - return events.APIGatewayProxyResponse{ Body: string(body), StatusCode: 200,