feat: Completed SigV4 authentication for the root user

This commit is contained in:
jonaustin09
2023-05-31 22:20:58 +04:00
parent 510cf6ed57
commit ecd28bc2f7
6 changed files with 132 additions and 31 deletions

View File

@@ -1,10 +1,14 @@
package utils
import (
"bytes"
"errors"
"flag"
"net/http"
"os"
"strings"
"github.com/gofiber/fiber/v2"
"github.com/valyala/fasthttp"
)
@@ -42,3 +46,28 @@ func GetRootUserCreds() (rootUser RootUser) {
}
return
}
func CreateHttpRequestFromCtx(ctx *fiber.Ctx) (*http.Request, error) {
req := ctx.Request()
httpReq, err := http.NewRequest(string(req.Header.Method()), req.URI().String(), bytes.NewReader(req.Body()))
if err != nil {
return nil, errors.New("error in creating an http request")
}
// Set the request headers
req.Header.VisitAll(func(key, value []byte) {
keyStr := string(key)
if keyStr == "X-Amz-Date" || keyStr == "X-Amz-Content-Sha256" || keyStr == "Host" {
httpReq.Header.Add(keyStr, string(value))
}
})
// Set the Content-Length header
httpReq.ContentLength = int64(len(req.Body()))
// Set the Host header
httpReq.Host = string(req.Header.Host())
return httpReq, nil
}