cubefs/objectnode/auth.go
Mofei Zhang d609fedb5c feature: object storage interface
Add ObjectNode provides S3-compatibile APIs.
Fusion Storage interface expose two interface (POSIX and S3-compatible) for file operation.

Signed-off-by: Mofei Zhang <mofei2816@gmail.com>
2019-12-17 17:36:53 +08:00

52 lines
1.2 KiB
Go

// Package s3 provides ...
package objectnode
import "net/http"
//https://docs.aws.amazon.com/AmazonS3/latest/dev/RESTAuthentication.html#ConstructingTheAuthenticationHeader
type AuthType string
const (
SignatrueV2 AuthType = "signature_v2"
SignatrueV4 = "signature_v4"
PresignedV2 = "presigned_v2"
PresignedV4 = "presigned_v4"
)
type RequestAuthInfo struct {
authType AuthType
accessKey string
}
func parseRequestAuthInfo(r *http.Request) *RequestAuthInfo {
auth := new(RequestAuthInfo)
if isSignaturedV2(r) {
auth.authType = SignatrueV2
ai, _ := parseRequestAuthInfoV2(r)
if ai != nil {
auth.accessKey = ai.accessKeyId
}
} else if isSignaturedV4(r) {
auth.authType = SignatrueV4
ai, _ := parseRequestV4(r)
if ai != nil {
auth.accessKey = ai.Credential.AccessKey
}
} else if isPresignedSignaturedV2(r) {
auth.authType = PresignedV2
ai, _ := parsePresignedV2AuthInfo(r)
if ai != nil {
auth.accessKey = ai.accessKeyId
}
} else if isPresignedSignaturedV4(r) {
auth.authType = PresignedV4
ai, _ := parseRequestV4(r)
if ai != nil {
auth.accessKey = ai.Credential.AccessKey
}
}
return auth
}