api

package
v0.31.1 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2024 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MetadataPrefix            = "X-Amz-Meta-"
	NeoFSSystemMetadataPrefix = "S3-"
	AmzMetadataDirective      = "X-Amz-Metadata-Directive"
	AmzTaggingDirective       = "X-Amz-Tagging-Directive"
	AmzVersionID              = "X-Amz-Version-Id"
	AmzTaggingCount           = "X-Amz-Tagging-Count"
	AmzTagging                = "X-Amz-Tagging"
	AmzDeleteMarker           = "X-Amz-Delete-Marker"
	AmzCopySource             = "X-Amz-Copy-Source"
	AmzCopySourceRange        = "X-Amz-Copy-Source-Range"
	AmzDate                   = "X-Amz-Date"

	LastModified       = "Last-Modified"
	Date               = "Date"
	ETag               = "ETag"
	ContentType        = "Content-Type"
	ContentMD5         = "Content-Md5"
	ContentEncoding    = "Content-Encoding"
	Expires            = "Expires"
	ContentLength      = "Content-Length"
	ContentLanguage    = "Content-Language"
	ContentRange       = "Content-Range"
	Connection         = "Connection"
	AcceptRanges       = "Accept-Ranges"
	AmzBucketRegion    = "X-Amz-Bucket-Region"
	ServerInfo         = "Server"
	RetryAfter         = "Retry-After"
	Location           = "Location"
	CacheControl       = "Cache-Control"
	ContentDisposition = "Content-Disposition"
	Authorization      = "Authorization"
	Action             = "Action"
	IfModifiedSince    = "If-Modified-Since"
	IfUnmodifiedSince  = "If-Unmodified-Since"
	IfMatch            = "If-Match"
	IfNoneMatch        = "If-None-Match"

	AmzCopyIfModifiedSince       = "X-Amz-Copy-Source-If-Modified-Since"
	AmzCopyIfUnmodifiedSince     = "X-Amz-Copy-Source-If-Unmodified-Since"
	AmzCopyIfMatch               = "X-Amz-Copy-Source-If-Match"
	AmzCopyIfNoneMatch           = "X-Amz-Copy-Source-If-None-Match"
	AmzACL                       = "X-Amz-Acl"
	AmzGrantFullControl          = "X-Amz-Grant-Full-Control"
	AmzGrantRead                 = "X-Amz-Grant-Read"
	AmzGrantWrite                = "X-Amz-Grant-Write"
	AmzExpectedBucketOwner       = "X-Amz-Expected-Bucket-Owner"
	AmzSourceExpectedBucketOwner = "X-Amz-Source-Expected-Bucket-Owner"
	AmzBucketObjectLockEnabled   = "X-Amz-Bucket-Object-Lock-Enabled"
	AmzObjectLockLegalHold       = "X-Amz-Object-Lock-Legal-Hold"
	AmzObjectLockMode            = "X-Amz-Object-Lock-Mode"
	AmzObjectLockRetainUntilDate = "X-Amz-Object-Lock-Retain-Until-Date"
	AmzBypassGovernanceRetention = "X-Amz-Bypass-Governance-Retention"
	AmzObjectAttributes          = "X-Amz-Object-Attributes"
	AmzMaxParts                  = "X-Amz-Max-Parts"
	AmzPartNumberMarker          = "X-Amz-Part-Number-Marker"

	AmzServerSideEncryptionCustomerAlgorithm = "x-amz-server-side-encryption-customer-algorithm"
	AmzServerSideEncryptionCustomerKey       = "x-amz-server-side-encryption-customer-key"
	AmzServerSideEncryptionCustomerKeyMD5    = "x-amz-server-side-encryption-customer-key-MD5"

	ContainerID = "X-Container-Id"

	AccessControlAllowOrigin      = "Access-Control-Allow-Origin"
	AccessControlAllowMethods     = "Access-Control-Allow-Methods"
	AccessControlExposeHeaders    = "Access-Control-Expose-Headers"
	AccessControlAllowHeaders     = "Access-Control-Allow-Headers"
	AccessControlMaxAge           = "Access-Control-Max-Age"
	AccessControlAllowCredentials = "Access-Control-Allow-Credentials"

	Origin                      = "Origin"
	AccessControlRequestMethod  = "Access-Control-Request-Method"
	AccessControlRequestHeaders = "Access-Control-Request-Headers"

	Vary = "Vary"

	DefaultLocationConstraint = "default"
)

Standard S3 HTTP request/response constants.

View Source
const (
	// SlashSeparator -- slash separator.
	SlashSeparator = "/"

	// MimeNone means no response type.
	MimeNone mimeType = ""

	// MimeXML means response type is XML.
	MimeXML mimeType = "application/xml"
)
View Source
const (
	QueryVersionID = "versionId"
)

S3 request query params.

Variables

View Source
var AnonymousRequest = KeyWrapper("__context_anonymous_request")

AnonymousRequest is a boolean flag to show explicitly that request was made without authorization. Typical usage with `--no-sign-request`.

View Source
var BoxData = KeyWrapper("__context_box_key")

BoxData is an ID used to store accessbox.Box in a context.

View Source
var ClientTime = KeyWrapper("__context_client_time")

ClientTime is an ID used to store client time.Time in a context.

View Source
var ResponseModifiers = map[string]string{
	"response-content-type":        ContentType,
	"response-content-language":    ContentLanguage,
	"response-expires":             Expires,
	"response-cache-control":       CacheControl,
	"response-content-disposition": ContentDisposition,
	"response-content-encoding":    ContentEncoding,
}

ResponseModifiers maps response modifies headers to regular headers.

View Source
var SystemMetadata = map[string]struct{}{
	Date:               {},
	CacheControl:       {},
	ContentDisposition: {},
	ContentLength:      {},
	ContentType:        {},
	LastModified:       {},
	ETag:               {},
}

Functions

func Attach

func Attach(r *mux.Router, domains []string, m MaxClients, h Handler, center auth.Center, log *zap.Logger)

Attach adds S3 API handlers from h to r for domains with m client limit using center authentication and log logger.

func AttachUserAuth

func AttachUserAuth(router *mux.Router, center auth.Center, log *zap.Logger)

AttachUserAuth adds user authentication via center to router using log for logging.

func EncodeResponse

func EncodeResponse(response any) []byte

EncodeResponse encodes the response headers into XML format.

func EncodeToResponse

func EncodeToResponse(w http.ResponseWriter, response any) error

EncodeToResponse encodes the response into ResponseWriter.

func GetRequestID

func GetRequestID(v any) string

GetRequestID returns the request ID from the response writer or the context.

func GetSourceIP

func GetSourceIP(r *http.Request) string

GetSourceIP retrieves the IP from the X-Forwarded-For, X-Real-IP and RFC7239 Forwarded headers (in that order), falls back to r.RemoteAddr when everything else fails.

func IsAnonymousRequest added in v0.28.0

func IsAnonymousRequest(ctx context.Context) bool

IsAnonymousRequest helps to check the request was made as an anonymous user.

func SetReqInfo

func SetReqInfo(ctx context.Context, req *ReqInfo) context.Context

SetReqInfo sets ReqInfo in the context.

func WriteErrorResponse

func WriteErrorResponse(w http.ResponseWriter, reqInfo *ReqInfo, err error) int

WriteErrorResponse writes error headers.

func WriteResponse

func WriteResponse(w http.ResponseWriter, statusCode int, response []byte, mType mimeType)

WriteResponse writes given statusCode and response into w (with mType header if set).

func WriteSuccessResponseHeadersOnly

func WriteSuccessResponseHeadersOnly(w http.ResponseWriter)

WriteSuccessResponseHeadersOnly writes HTTP (200) OK response with no data to the client.

Types

type ErrorResponse

type ErrorResponse struct {
	XMLName    xml.Name `xml:"Error" json:"-"`
	Code       string
	Message    string
	Key        string `xml:"Key,omitempty" json:"Key,omitempty"`
	BucketName string `xml:"BucketName,omitempty" json:"BucketName,omitempty"`
	Resource   string
	RequestID  string `xml:"RequestId" json:"RequestId"`
	HostID     string `xml:"HostId" json:"HostId"`

	// The region where the bucket is located. This header is returned
	// only in HEAD bucket and ListObjects response.
	Region string `xml:"Region,omitempty" json:"Region,omitempty"`

	// Captures the server string returned in response header.
	Server string `xml:"-" json:"-"`

	// Underlying HTTP status code for the returned error.
	StatusCode int `xml:"-" json:"-"`
}

ErrorResponse -- error response format.

func (ErrorResponse) Error

func (e ErrorResponse) Error() string

Error -- Returns S3 error string.

type Handler

type Handler interface {
	HeadObjectHandler(http.ResponseWriter, *http.Request)
	GetObjectACLHandler(http.ResponseWriter, *http.Request)
	PutObjectACLHandler(http.ResponseWriter, *http.Request)
	GetObjectTaggingHandler(http.ResponseWriter, *http.Request)
	PutObjectTaggingHandler(http.ResponseWriter, *http.Request)
	DeleteObjectTaggingHandler(http.ResponseWriter, *http.Request)
	SelectObjectContentHandler(http.ResponseWriter, *http.Request)
	GetObjectRetentionHandler(http.ResponseWriter, *http.Request)
	GetObjectLegalHoldHandler(http.ResponseWriter, *http.Request)
	GetObjectHandler(http.ResponseWriter, *http.Request)
	GetObjectAttributesHandler(http.ResponseWriter, *http.Request)
	CopyObjectHandler(http.ResponseWriter, *http.Request)
	PutObjectRetentionHandler(http.ResponseWriter, *http.Request)
	PutObjectLegalHoldHandler(http.ResponseWriter, *http.Request)
	PutObjectHandler(http.ResponseWriter, *http.Request)
	DeleteObjectHandler(http.ResponseWriter, *http.Request)
	GetBucketLocationHandler(http.ResponseWriter, *http.Request)
	GetBucketPolicyHandler(http.ResponseWriter, *http.Request)
	GetBucketLifecycleHandler(http.ResponseWriter, *http.Request)
	GetBucketEncryptionHandler(http.ResponseWriter, *http.Request)
	GetBucketACLHandler(http.ResponseWriter, *http.Request)
	PutBucketACLHandler(http.ResponseWriter, *http.Request)
	GetBucketCorsHandler(http.ResponseWriter, *http.Request)
	PutBucketCorsHandler(http.ResponseWriter, *http.Request)
	DeleteBucketCorsHandler(http.ResponseWriter, *http.Request)
	GetBucketWebsiteHandler(http.ResponseWriter, *http.Request)
	GetBucketAccelerateHandler(http.ResponseWriter, *http.Request)
	GetBucketRequestPaymentHandler(http.ResponseWriter, *http.Request)
	GetBucketLoggingHandler(http.ResponseWriter, *http.Request)
	PutBucketLoggingHandler(http.ResponseWriter, *http.Request)
	GetBucketReplicationHandler(http.ResponseWriter, *http.Request)
	GetBucketTaggingHandler(http.ResponseWriter, *http.Request)
	DeleteBucketWebsiteHandler(http.ResponseWriter, *http.Request)
	DeleteBucketTaggingHandler(http.ResponseWriter, *http.Request)
	GetBucketObjectLockConfigHandler(http.ResponseWriter, *http.Request)
	GetBucketVersioningHandler(http.ResponseWriter, *http.Request)
	GetBucketNotificationHandler(http.ResponseWriter, *http.Request)
	ListenBucketNotificationHandler(http.ResponseWriter, *http.Request)
	ListObjectsV2MHandler(http.ResponseWriter, *http.Request)
	ListObjectsV2Handler(http.ResponseWriter, *http.Request)
	ListBucketObjectVersionsHandler(http.ResponseWriter, *http.Request)
	ListObjectsV1Handler(http.ResponseWriter, *http.Request)
	PutBucketLifecycleHandler(http.ResponseWriter, *http.Request)
	PutBucketEncryptionHandler(http.ResponseWriter, *http.Request)
	PutBucketPolicyHandler(http.ResponseWriter, *http.Request)
	PutBucketObjectLockConfigHandler(http.ResponseWriter, *http.Request)
	PutBucketTaggingHandler(http.ResponseWriter, *http.Request)
	PutBucketVersioningHandler(http.ResponseWriter, *http.Request)
	PutBucketNotificationHandler(http.ResponseWriter, *http.Request)
	CreateBucketHandler(http.ResponseWriter, *http.Request)
	HeadBucketHandler(http.ResponseWriter, *http.Request)
	PostObject(http.ResponseWriter, *http.Request)
	DeleteMultipleObjectsHandler(http.ResponseWriter, *http.Request)
	DeleteBucketPolicyHandler(http.ResponseWriter, *http.Request)
	GetBucketPolicyStatusHandler(http.ResponseWriter, *http.Request)
	DeleteBucketLifecycleHandler(http.ResponseWriter, *http.Request)
	DeleteBucketEncryptionHandler(http.ResponseWriter, *http.Request)
	DeleteBucketHandler(http.ResponseWriter, *http.Request)
	ListBucketsHandler(http.ResponseWriter, *http.Request)
	Preflight(w http.ResponseWriter, r *http.Request)
	AppendCORSHeaders(w http.ResponseWriter, r *http.Request)
	CreateMultipartUploadHandler(http.ResponseWriter, *http.Request)
	UploadPartHandler(http.ResponseWriter, *http.Request)
	UploadPartCopy(w http.ResponseWriter, r *http.Request)
	CompleteMultipartUploadHandler(http.ResponseWriter, *http.Request)
	AbortMultipartUploadHandler(http.ResponseWriter, *http.Request)
	ListPartsHandler(w http.ResponseWriter, r *http.Request)
	ListMultipartUploadsHandler(http.ResponseWriter, *http.Request)
	GetObjectTorrentHandler(http.ResponseWriter, *http.Request)
	PutPublicAccessBlockHandler(http.ResponseWriter, *http.Request)
	GetPublicAccessBlockHandler(http.ResponseWriter, *http.Request)
}

Handler is an S3 API handler interface.

type KeyVal

type KeyVal struct {
	Key string
	Val string
}

KeyVal -- appended to ReqInfo.Tags.

type KeyWrapper

type KeyWrapper string

KeyWrapper is wrapper for context keys.

type MaxClients

type MaxClients interface {
	Handle(http.HandlerFunc) http.HandlerFunc
}

MaxClients provides HTTP handler wrapper with the client limit.

func NewMaxClientsMiddleware

func NewMaxClientsMiddleware(count int, timeout time.Duration) MaxClients

NewMaxClientsMiddleware returns MaxClients interface with handler wrapper based on the provided count and the timeout limits.

type ObjectRequest

type ObjectRequest struct {
	Bucket string
	Object string
	Method string
}

ObjectRequest represents object request data.

type ReqInfo

type ReqInfo struct {
	sync.RWMutex
	RemoteHost   string   // Client Host/IP
	Host         string   // Node Host/IP
	UserAgent    string   // User Agent
	DeploymentID string   // random generated s3-deployment-id
	RequestID    string   // x-amz-request-id
	API          string   // API name -- GetObject PutObject NewMultipartUpload etc.
	BucketName   string   // Bucket name
	ObjectName   string   // Object name
	URL          *url.URL // Request url
	// contains filtered or unexported fields
}

ReqInfo stores the request info.

func GetReqInfo

func GetReqInfo(ctx context.Context) *ReqInfo

GetReqInfo returns ReqInfo if set.

func NewReqInfo

func NewReqInfo(w http.ResponseWriter, r *http.Request, req ObjectRequest) *ReqInfo

NewReqInfo returns new ReqInfo based on parameters.

func (*ReqInfo) AppendTags

func (r *ReqInfo) AppendTags(key string, val string) *ReqInfo

AppendTags -- appends key/val to ReqInfo.tags.

func (*ReqInfo) GetTags

func (r *ReqInfo) GetTags() []KeyVal

GetTags -- returns the user defined tags.

func (*ReqInfo) SetTags

func (r *ReqInfo) SetTags(key string, val string) *ReqInfo

SetTags -- sets key/val to ReqInfo.tags.

Directories

Path Synopsis
signer/v4
Package v4 implements signing for AWS V4 signer
Package v4 implements signing for AWS V4 signer

Jump to

Keyboard shortcuts

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