utils

package
v0.0.0-...-d88ec87 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//SignV2Algorithm is a prefix for v2 auth header
	SignV2Algorithm = "AWS"
	//SignV4Algorithm indicates a v4
	SignV4Algorithm = "AWS4-HMAC-SHA256"
	//RegexV2Algorithm is a regexp for parsing v2 auth headers
	RegexV2Algorithm = "AWS +(?P<access_key>[a-zA-Z0-9_-]+):(?P<Signature>(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?)"
	//RegexV4Algorithm is a regexp for parsing v4 auth headers
	RegexV4Algorithm = "" /* 213-byte string literal not displayed */
)

Variables

View Source
var ErrNoAuthHeader = fmt.Errorf("cannot find correct authorization header")

ErrNoAuthHeader indicates that no authorization header was found in the request

View Source
var ReqMetadataKey = ContextKey("ContextReqHost")

Functions

func DumpResponseBody

func DumpResponseBody(resp *http.Response) []byte

func ExtractAccessKey

func ExtractAccessKey(req *http.Request) string

ExtractAccessKey extracts s3 auth key from header

func ExtractBucketAndKey

func ExtractBucketAndKey(requestPath string) (string, string)

ExtractBucketAndKey extract object's bucket and key from request URL

func ExtractBucketFrom

func ExtractBucketFrom(requestPath string) string

ExtractBucketFrom extract bucket's name from request's path, if no bucket name is found, empty string is returned

func ExtractMultiPartUploadIDFrom

func ExtractMultiPartUploadIDFrom(response *http.Response) (string, error)

ExtractMultiPartUploadIDFrom extract multipart upload id from http response

func GetRequestProcessingMetadata

func GetRequestProcessingMetadata(req *http.Request, key string) string

func IsBucketPath

func IsBucketPath(path string) bool

IsBucketPath check if a given path is a bucket path

func IsInitiateMultiPartUploadRequest

func IsInitiateMultiPartUploadRequest(request *http.Request) bool

IsInitiateMultiPartUploadRequest checks if a request is an initiate multipart upload request

func IsMultiPartUploadRequest

func IsMultiPartUploadRequest(request *http.Request) bool

TODO Query() parses the query string every time it's called... this can (and should!) be optimized IsMultiPartUploadRequest checks if a request is a multipart upload request

func IsObjectPath

func IsObjectPath(path string) bool

IsObjectPath check if a given path is an object path

func PutResponseHeaderToContext

func PutResponseHeaderToContext(context context.Context, contextValueName log.ContextKey, resp *http.Response, headerName string)

PutResponseHeaderToContext extracts the header value from the response and puts it into the context under the specified key

func ReadRequestBody

func ReadRequestBody(request *http.Request) ([]byte, error)

ReadRequestBody returns the bytes of the request body or nil of body is not present

func ReplicateRequest

func ReplicateRequest(request *http.Request) (*http.Request, error)

ReplicateRequest makes a copy of the provided request

func RequestID

func RequestID(req *http.Request) string

RequestID extracts the request id from context

func ResponseForbidden

func ResponseForbidden(req *http.Request) *http.Response

func SetRequestProcessingMetadata

func SetRequestProcessingMetadata(req *http.Request, key, value string)

Types

type BackendError

type BackendError interface {
	Backend() string
	Err() error
	Error() string
}

BackendError interface helps logging inconsistencies

type ContextKey

type ContextKey string

type ParsedAuthorizationHeader

type ParsedAuthorizationHeader struct {
	Version       string
	AccessKey     string
	Signature     string
	SignedHeaders string
	Region        string
	Service       string
}

ParsedAuthorizationHeader holds the parsed "Authorization" header content

func ParseAuthorizationHeader

func ParseAuthorizationHeader(authorizationHeader string) (authHeader ParsedAuthorizationHeader, err error)

ParseAuthorizationHeader - extract S3 authorization header details

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL