middleware

package
v0.29.0-rc.6 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: AGPL-3.0 Imports: 42 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ListBucketsOperation = "ListBuckets"

	OptionsOperation                   = "Options"
	HeadBucketOperation                = "HeadBucket"
	ListMultipartUploadsOperation      = "ListMultipartUploads"
	GetBucketLocationOperation         = "GetBucketLocation"
	GetBucketPolicyOperation           = "GetBucketPolicy"
	GetBucketLifecycleOperation        = "GetBucketLifecycle"
	GetBucketEncryptionOperation       = "GetBucketEncryption"
	GetBucketCorsOperation             = "GetBucketCors"
	GetBucketACLOperation              = "GetBucketACL"
	GetBucketWebsiteOperation          = "GetBucketWebsite"
	GetBucketAccelerateOperation       = "GetBucketAccelerate"
	GetBucketRequestPaymentOperation   = "GetBucketRequestPayment"
	GetBucketLoggingOperation          = "GetBucketLogging"
	GetBucketReplicationOperation      = "GetBucketReplication"
	GetBucketTaggingOperation          = "GetBucketTagging"
	GetBucketObjectLockConfigOperation = "GetBucketObjectLockConfig"
	GetBucketVersioningOperation       = "GetBucketVersioning"
	GetBucketNotificationOperation     = "GetBucketNotification"
	ListenBucketNotificationOperation  = "ListenBucketNotification"
	ListBucketObjectVersionsOperation  = "ListBucketObjectVersions"
	ListObjectsV2MOperation            = "ListObjectsV2M"
	ListObjectsV2Operation             = "ListObjectsV2"
	ListObjectsV1Operation             = "ListObjectsV1"
	PutBucketCorsOperation             = "PutBucketCors"
	PutBucketACLOperation              = "PutBucketACL"
	PutBucketLifecycleOperation        = "PutBucketLifecycle"
	PutBucketEncryptionOperation       = "PutBucketEncryption"
	PutBucketPolicyOperation           = "PutBucketPolicy"
	PutBucketObjectLockConfigOperation = "PutBucketObjectLockConfig"
	PutBucketTaggingOperation          = "PutBucketTagging"
	PutBucketVersioningOperation       = "PutBucketVersioning"
	PutBucketNotificationOperation     = "PutBucketNotification"
	CreateBucketOperation              = "CreateBucket"
	DeleteMultipleObjectsOperation     = "DeleteMultipleObjects"
	PostObjectOperation                = "PostObject"
	DeleteBucketCorsOperation          = "DeleteBucketCors"
	DeleteBucketWebsiteOperation       = "DeleteBucketWebsite"
	DeleteBucketTaggingOperation       = "DeleteBucketTagging"
	DeleteBucketPolicyOperation        = "DeleteBucketPolicy"
	DeleteBucketLifecycleOperation     = "DeleteBucketLifecycle"
	DeleteBucketEncryptionOperation    = "DeleteBucketEncryption"
	DeleteBucketOperation              = "DeleteBucket"

	HeadObjectOperation              = "HeadObject"
	ListPartsOperation               = "ListParts"
	GetObjectACLOperation            = "GetObjectACL"
	GetObjectTaggingOperation        = "GetObjectTagging"
	GetObjectRetentionOperation      = "GetObjectRetention"
	GetObjectLegalHoldOperation      = "GetObjectLegalHold"
	GetObjectAttributesOperation     = "GetObjectAttributes"
	GetObjectOperation               = "GetObject"
	UploadPartCopyOperation          = "UploadPartCopy"
	UploadPartOperation              = "UploadPart"
	PutObjectACLOperation            = "PutObjectACL"
	PutObjectTaggingOperation        = "PutObjectTagging"
	CopyObjectOperation              = "CopyObject"
	PutObjectRetentionOperation      = "PutObjectRetention"
	PutObjectLegalHoldOperation      = "PutObjectLegalHold"
	PutObjectOperation               = "PutObject"
	CompleteMultipartUploadOperation = "CompleteMultipartUpload"
	CreateMultipartUploadOperation   = "CreateMultipartUpload"
	SelectObjectContentOperation     = "SelectObjectContent"
	AbortMultipartUploadOperation    = "AbortMultipartUpload"
	DeleteObjectTaggingOperation     = "DeleteObjectTagging"
	DeleteObjectOperation            = "DeleteObject"
)
View Source
const (
	UploadsQuery        = "uploads"
	LocationQuery       = "location"
	PolicyQuery         = "policy"
	LifecycleQuery      = "lifecycle"
	EncryptionQuery     = "encryption"
	CorsQuery           = "cors"
	ACLQuery            = "acl"
	WebsiteQuery        = "website"
	AccelerateQuery     = "accelerate"
	RequestPaymentQuery = "requestPayment"
	LoggingQuery        = "logging"
	ReplicationQuery    = "replication"
	TaggingQuery        = "tagging"
	ObjectLockQuery     = "object-lock"
	VersioningQuery     = "versioning"
	NotificationQuery   = "notification"
	EventsQuery         = "events"
	VersionsQuery       = "versions"
	ListTypeQuery       = "list-type"
	MetadataQuery       = "metadata"
	DeleteQuery         = "delete"
	UploadIDQuery       = "uploadId"
	RetentionQuery      = "retention"
	LegalQuery          = "legal"
	AttributesQuery     = "attributes"
	PartNumberQuery     = "partNumber"
	LegalHoldQuery      = "legal-hold"
)
View Source
const (

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

	// MimeXML means response type is XML.
	MimeXML mimeType = "application/xml"
)
View Source
const (
	BucketURLPrm = "bucket"
)
View Source
const HdrAmzRequestID = "x-amz-request-id"

Variables

View Source
var ErrNoAuthorizationHeader = errors.New("no authorization header")

ErrNoAuthorizationHeader is returned for unauthenticated requests.

Functions

func EncodeResponse

func EncodeResponse(response interface{}) ([]byte, error)

EncodeResponse encodes the response headers into XML format.

func EncodeResponseNoHeader

func EncodeResponseNoHeader(response interface{}) ([]byte, error)

EncodeResponseNoHeader encodes response without setting xml.Header. Should be used with periodicXMLWriter which sends xml.Header to the client with whitespaces to keep connection alive.

func EncodeToResponse

func EncodeToResponse(w http.ResponseWriter, response interface{}) error

EncodeToResponse encodes the response into ResponseWriter.

func EncodeToResponseNoHeader

func EncodeToResponseNoHeader(w http.ResponseWriter, response interface{}) error

EncodeToResponseNoHeader encodes the response into ResponseWriter without header status.

func GetBoxData

func GetBoxData(ctx context.Context) (*accessbox.Box, error)

GetBoxData extracts accessbox.Box from context.

func GetClientTime

func GetClientTime(ctx context.Context) (time.Time, error)

GetClientTime extracts time.Time from context.

func GetReqLog

func GetReqLog(ctx context.Context) *zap.Logger

GetReqLog returns log if set. If zap.Logger isn't set returns nil.

func GetRequestID

func GetRequestID(v interface{}) string

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

func SetAuthHeaders

func SetAuthHeaders(ctx context.Context, header *AuthHeader) context.Context

SetAuthHeaders sets auth.AuthHeader in the context.

func SetBoxData

func SetBoxData(ctx context.Context, box *accessbox.Box) context.Context

SetBoxData sets accessbox.Box in the context.

func SetClientTime

func SetClientTime(ctx context.Context, newTime time.Time) context.Context

SetClientTime sets time.Time in the context.

func SetReqInfo

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

SetReqInfo sets ReqInfo in the context.

func SetReqLogger

func SetReqLogger(ctx context.Context, log *zap.Logger) context.Context

SetReqLogger sets child zap.Logger in the context.

func StartHTTPServerSpan

func StartHTTPServerSpan(r *http.Request, operationName string, opts ...trace.SpanStartOption) (context.Context, trace.Span)

StartHTTPServerSpan starts root HTTP server span.

func WriteErrorResponse

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

WriteErrorResponse writes error headers. returns http error code and error in case of failure of response writing.

func WriteResponse

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

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

func WriteResponseBody

func WriteResponseBody(w http.ResponseWriter, response []byte) error

WriteResponseBody writes response into w.

func WriteSuccessResponseHeadersOnly

func WriteSuccessResponseHeadersOnly(w http.ResponseWriter) error

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

Types

type AuthHeader added in v0.29.0

type AuthHeader struct {
	AccessKeyID string
	Region      string
	SignatureV4 string
}

func GetAuthHeaders

func GetAuthHeaders(ctx context.Context) (*AuthHeader, error)

GetAuthHeaders extracts auth.AuthHeader from context.

type Box added in v0.29.0

type Box struct {
	AccessBox   *accessbox.Box
	ClientTime  time.Time
	AuthHeaders *AuthHeader
}

Box contains access box and additional info.

type BucketResolveFunc

type BucketResolveFunc func(ctx context.Context, bucket string) (*data.BucketInfo, error)

BucketResolveFunc is a func to resolve bucket info by name.

type Center added in v0.29.0

type Center interface {
	// Authenticate validate and authenticate request.
	// Must return ErrNoAuthorizationHeader if auth header is missed.
	Authenticate(request *http.Request) (*Box, error)
}

Center is a user authentication interface.

type ContainerIDResolveFunc added in v0.29.0

type ContainerIDResolveFunc func(ctx context.Context, bucket string) (cid.ID, error)

ContainerIDResolveFunc is a func to resolve container id by name.

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 FrostFSIDInformer added in v0.29.0

type FrostFSIDInformer interface {
	GetUserGroupIDs(userHash util.Uint160) ([]string, error)
}

type FrostFSIDValidator added in v0.29.0

type FrostFSIDValidator interface {
	ValidatePublicKey(key *keys.PublicKey) error
}

type Func

type Func func(h http.Handler) http.Handler

func AddBucketName

func AddBucketName(l *zap.Logger) Func

AddBucketName adds bucket name to ReqInfo from context.

func AddObjectName

func AddObjectName(l *zap.Logger) Func

AddObjectName adds objects name to ReqInfo from context.

func Auth

func Auth(center Center, log *zap.Logger) Func

func FrostfsIDValidation added in v0.29.0

func FrostfsIDValidation(frostfsID FrostFSIDValidator, log *zap.Logger) Func

func LogSuccessResponse

func LogSuccessResponse(l *zap.Logger) Func

func Metrics

func Metrics(log *zap.Logger, resolveBucket ContainerIDResolveFunc, appMetrics *metrics.AppMetrics, settings MetricsSettings) Func

Metrics wraps http handler for api with basic statistics collection.

func PolicyCheck added in v0.29.0

func PolicyCheck(cfg PolicyConfig) Func

func Request

func Request(log *zap.Logger, settings RequestSettings) Func

func Tracing

func Tracing() Func

Tracing adds tracing support for requests. Must be placed after prepareRequest middleware.

func WrapHandler

func WrapHandler(handler http.HandlerFunc) Func

type KeyVal

type KeyVal struct {
	Key string
	Val string
}

KeyVal -- appended to ReqInfo.Tags.

type MetricsSettings added in v0.29.0

type MetricsSettings interface {
	ResolveNamespaceAlias(namespace string) string
}

type ObjectRequest

type ObjectRequest struct {
	Bucket string
	Object string
	Method string
}

ObjectRequest represents object request data.

type PolicyConfig added in v0.29.0

type PolicyConfig struct {
	Storage        engine.ChainRouter
	FrostfsID      FrostFSIDInformer
	Settings       PolicySettings
	Domains        []string
	Log            *zap.Logger
	BucketResolver BucketResolveFunc
}

type PolicySettings added in v0.29.0

type PolicySettings interface {
	PolicyDenyByDefault() bool
	ACLEnabled() bool
}

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
	TraceID      string   // Trace ID
	URL          *url.URL // Request url
	Namespace    string
	User         string // User owner id
	// contains filtered or unexported fields
}

ReqInfo stores the request info.

func GetReqInfo

func GetReqInfo(ctx context.Context) *ReqInfo

GetReqInfo returns ReqInfo if set. If ReqInfo isn't set returns new empty ReqInfo.

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.

type ReqType added in v0.29.0

type ReqType int

type RequestSettings added in v0.29.0

type RequestSettings interface {
	NamespaceHeader() string
	ResolveNamespaceAlias(string) string
}

Jump to

Keyboard shortcuts

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