api

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2019 License: Apache-2.0 Imports: 33 Imported by: 0

README

API layer

Part of the code are stolen from https://github.com/minio/minio, and modified accordingly.

Apache license.

Documentation

Index

Constants

View Source
const (
	CombinedLogFormat = "{time_local} {request} {host} {bucket_name} {remote_addr} {http_x_real_ip} {project_id} {request_length} " +
		"{retain} {retain} {request_time} {status} {body_bytes_sent} {http_referer} {http_user_agent} {is_private_subnet} {region_id}"
)
View Source
const (
	MIN_PART_SIZE = 128 << 10 // 128KB
)

Variables

View Source
var ValidSuccessActionStatus = []string{"200", "201", "204"}

Functions

func CheckValidBucketName

func CheckValidBucketName(bucketName string) (err error)

CheckValidBucketName - checks if we have a valid input bucket name.

func EncodeResponse

func EncodeResponse(response interface{}) []byte

Encodes the response headers into XML format.

func GenerateCompleteMultpartUploadResponse

func GenerateCompleteMultpartUploadResponse(bucket, key, location, etag string) CompleteMultipartUploadResponse

GenerateCompleteMultipartUploadResponse

func GenerateCopyObjectPartResponse

func GenerateCopyObjectPartResponse(etag string, lastModified time.Time) CopyObjectPartResponse

func GenerateCopyObjectResponse

func GenerateCopyObjectResponse(etag string, lastModified time.Time) CopyObjectResponse

GenerateCopyObjectResponse

func GenerateInitiateMultipartUploadResponse

func GenerateInitiateMultipartUploadResponse(bucket, key, uploadID string) InitiateMultipartUploadResponse

GenerateInitiateMultipartUploadResponse

func GenerateListBucketsResponse

func GenerateListBucketsResponse(buckets []meta.Bucket, credential common.Credential) ListBucketsResponse

Takes an array of Bucket metadata information for serialization input: array of bucket metadata output: populated struct that can be serialized to match xml and json api spec output

func GenerateListObjectsResponse

func GenerateListObjectsResponse(bucketName string, request ListObjectsRequest,
	objectsInfo meta.ListObjectsInfo) (response ListObjectsResponse)

generates an ListObjects response for the said bucket with other enumerated options.

func GenerateVersionedListObjectResponse

func GenerateVersionedListObjectResponse(bucketName string, request ListObjectsRequest,
	objectsInfo meta.VersionedListObjectsInfo) (response VersionedListObjectsResponse)

func GetBucketAndObjectInfoFromRequest added in v0.6.1

func GetBucketAndObjectInfoFromRequest(r *http.Request) (bucketName string, objectName string)

func GetLocation

func GetLocation(r *http.Request) string

getLocation get URL location.

func GetObjectLocation

func GetObjectLocation(bucketName string, key string) string

getObjectLocation gets the relative URL for an object

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 all else fails.

func InReservedOrigins

func InReservedOrigins(origin string) bool

func IsBucketAllowed added in v1.1.3

func IsBucketAllowed(c common.Credential, api ObjectAPIHandlers, r *http.Request, action policy.Action, bucketName, objectName string) (common.Credential, error)

func NewAccessLogHandler

func NewAccessLogHandler(handler http.Handler, objectLayer ObjectLayer) http.Handler

func RegisterAPIRouter

func RegisterAPIRouter(mux *router.Router, api ObjectAPIHandlers)

registerAPIRouter - registers S3 compatible APIs.

func RegisterHandlers

func RegisterHandlers(router *mux.Router, objectLayer ObjectLayer, handlerFns ...HandlerFunc) http.Handler

func SetAuthHandler added in v1.1.0

func SetAuthHandler(h http.Handler, _ ObjectLayer) http.Handler

setAuthHandler to validate authorization header for the incoming request.

func SetCommonHeaderHandler

func SetCommonHeaderHandler(h http.Handler, _ ObjectLayer) http.Handler

func SetCorsHandler

func SetCorsHandler(h http.Handler, o ObjectLayer) http.Handler

setCorsHandler handler for CORS (Cross Origin Resource Sharing)

func SetIgnoreResourcesHandler

func SetIgnoreResourcesHandler(h http.Handler, _ ObjectLayer) http.Handler

setIgnoreResourcesHandler - Ignore resources handler is wrapper handler used for API request resource validation Since we do not support all the S3 queries, it is necessary for us to throw back a valid error message indicating that requested feature is not implemented.

func SetLogHandler

func SetLogHandler(h http.Handler, _ ObjectLayer) http.Handler

func SetObjectHeaders

func SetObjectHeaders(w http.ResponseWriter, object *meta.Object, contentRange *HttpRange)

Write object header

func SetRateLimitHandler added in v1.1.0

func SetRateLimitHandler(handler http.Handler, _ ObjectLayer) http.Handler

setRateLimitHandler limits the number of concurrent http requests based on CONFIG.ConcurrentRequestLimit

func WriteErrorResponse

func WriteErrorResponse(w http.ResponseWriter, r *http.Request, err error)

writeErrorResponse write error headers

func WriteErrorResponseHeaders

func WriteErrorResponseHeaders(w http.ResponseWriter, err error)

func WriteErrorResponseNoHeader

func WriteErrorResponseNoHeader(w http.ResponseWriter, req *http.Request, err error, resource string)

func WriteErrorResponseWithResource

func WriteErrorResponseWithResource(w http.ResponseWriter, r *http.Request, err error, resource string)

func WriteSuccessNoContent

func WriteSuccessNoContent(w http.ResponseWriter)

writeSuccessNoContent write success headers with http status 204

func WriteSuccessResponse

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

WriteSuccessResponse write success headers and response if any.

Types

type AccessLogHandler

type AccessLogHandler struct {
	// contains filtered or unexported fields
}

func (AccessLogHandler) ServeHTTP

func (a AccessLogHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (AccessLogHandler) SetHandler added in v1.2.3

func (a AccessLogHandler) SetHandler(handler http.Handler, _ ObjectLayer) http.Handler

type ApiErrorResponse

type ApiErrorResponse struct {
	XMLName      xml.Name `xml:"Error" json:"-"`
	AwsErrorCode string   `xml:"Code"`
	Message      string
	Key          string
	BucketName   string
	Resource     string
	RequestId    string
	HostId       string
}

APIErrorResponse - error response format

type AuthHandler added in v1.1.0

type AuthHandler struct {
	// contains filtered or unexported fields
}

authHandler - handles all the incoming authorization headers and validates them if possible.

func (AuthHandler) ServeHTTP added in v1.1.0

func (a AuthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

handler for validating incoming authorization headers.

type ContextKey added in v1.1.0

type ContextKey int
const (
	RequestId ContextKey = iota
)

type DeleteObjectsResponse

type DeleteObjectsResponse struct {
	XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ DeleteResult" json:"-"`

	// Collection of all deleted objects
	DeletedObjects []ObjectIdentifier `xml:"Deleted,omitempty"`

	// Collection of errors deleting certain objects.
	Errors []DeleteError `xml:"Error,omitempty"`
}

DeleteObjectsResponse container for multiple object deletes.

func GenerateMultiDeleteResponse

func GenerateMultiDeleteResponse(quiet bool, deletedObjects []ObjectIdentifier, errs []DeleteError) DeleteObjectsResponse

generate multi objects delete response.

type HandlerFunc

type HandlerFunc func(http.Handler, ObjectLayer) http.Handler

HandlerFunc - useful to chain different middleware http.Handler

type ObjectAPIHandlers

type ObjectAPIHandlers struct {
	ObjectAPI ObjectLayer
}

objectAPIHandler implements and provides http handlers for S3 API.

func (ObjectAPIHandlers) AbortMultipartUploadHandler

func (api ObjectAPIHandlers) AbortMultipartUploadHandler(w http.ResponseWriter, r *http.Request)

AbortMultipartUploadHandler - Abort multipart upload

func (ObjectAPIHandlers) AppendObjectHandler

func (api ObjectAPIHandlers) AppendObjectHandler(w http.ResponseWriter, r *http.Request)

AppendObjectHandler - Append Object ---------- This implementation of the POST operation append an object in a bucket.

func (ObjectAPIHandlers) CompleteMultipartUploadHandler

func (api ObjectAPIHandlers) CompleteMultipartUploadHandler(w http.ResponseWriter, r *http.Request)

CompleteMultipartUploadHandler - Complete multipart upload

func (ObjectAPIHandlers) CopyObjectHandler

func (api ObjectAPIHandlers) CopyObjectHandler(w http.ResponseWriter, r *http.Request)

CopyObjectHandler - Copy Object ---------- This implementation of the PUT operation adds an object to a bucket while reading the object from another source.

func (ObjectAPIHandlers) CopyObjectPartHandler

func (api ObjectAPIHandlers) CopyObjectPartHandler(w http.ResponseWriter, r *http.Request)

Upload part - copy

func (ObjectAPIHandlers) DelBucketLifeCycleHandler

func (api ObjectAPIHandlers) DelBucketLifeCycleHandler(w http.ResponseWriter, r *http.Request)

func (ObjectAPIHandlers) DeleteBucketCorsHandler

func (api ObjectAPIHandlers) DeleteBucketCorsHandler(w http.ResponseWriter, r *http.Request)

func (ObjectAPIHandlers) DeleteBucketHandler

func (api ObjectAPIHandlers) DeleteBucketHandler(w http.ResponseWriter, r *http.Request)

DeleteBucketHandler - Delete bucket

func (ObjectAPIHandlers) DeleteBucketPolicyHandler

func (api ObjectAPIHandlers) DeleteBucketPolicyHandler(w http.ResponseWriter, r *http.Request)

DeleteBucketPolicyHandler - This HTTP handler removes bucket policy configuration.

func (ObjectAPIHandlers) DeleteMultipleObjectsHandler

func (api ObjectAPIHandlers) DeleteMultipleObjectsHandler(w http.ResponseWriter, r *http.Request)

DeleteMultipleObjectsHandler - deletes multiple objects.

func (ObjectAPIHandlers) DeleteObjectHandler

func (api ObjectAPIHandlers) DeleteObjectHandler(w http.ResponseWriter, r *http.Request)

DeleteObjectHandler - delete an object

func (ObjectAPIHandlers) GetBucketAclHandler

func (api ObjectAPIHandlers) GetBucketAclHandler(w http.ResponseWriter, r *http.Request)

func (ObjectAPIHandlers) GetBucketCorsHandler

func (api ObjectAPIHandlers) GetBucketCorsHandler(w http.ResponseWriter, r *http.Request)

func (ObjectAPIHandlers) GetBucketLifeCycleHandler

func (api ObjectAPIHandlers) GetBucketLifeCycleHandler(w http.ResponseWriter, r *http.Request)

func (ObjectAPIHandlers) GetBucketLocationHandler

func (api ObjectAPIHandlers) GetBucketLocationHandler(w http.ResponseWriter, r *http.Request)

GetBucketLocationHandler - GET Bucket location. ------------------------- This operation returns bucket location.

func (ObjectAPIHandlers) GetBucketPolicyHandler

func (api ObjectAPIHandlers) GetBucketPolicyHandler(w http.ResponseWriter, r *http.Request)

GetBucketPolicyHandler - This HTTP handler returns bucket policy configuration.

func (ObjectAPIHandlers) GetBucketVersioningHandler

func (api ObjectAPIHandlers) GetBucketVersioningHandler(w http.ResponseWriter, r *http.Request)

func (ObjectAPIHandlers) GetObjectAclHandler

func (api ObjectAPIHandlers) GetObjectAclHandler(w http.ResponseWriter, r *http.Request)

func (ObjectAPIHandlers) GetObjectHandler

func (api ObjectAPIHandlers) GetObjectHandler(w http.ResponseWriter, r *http.Request)

GetObjectHandler - GET Object ---------- This implementation of the GET operation retrieves object. To use GET, you must have READ access to the object.

func (ObjectAPIHandlers) HeadBucketHandler

func (api ObjectAPIHandlers) HeadBucketHandler(w http.ResponseWriter, r *http.Request)

HeadBucketHandler - HEAD Bucket ---------- This operation is useful to determine if a bucket exists. The operation returns a 200 OK if the bucket exists and you have permission to access it. Otherwise, the operation might return responses such as 404 Not Found and 403 Forbidden.

func (ObjectAPIHandlers) HeadObjectHandler

func (api ObjectAPIHandlers) HeadObjectHandler(w http.ResponseWriter, r *http.Request)

HeadObjectHandler - HEAD Object ----------- The HEAD operation retrieves metadata from an object without returning the object itself. TODO refactor HEAD and GET

func (ObjectAPIHandlers) ListBucketsHandler

func (api ObjectAPIHandlers) ListBucketsHandler(w http.ResponseWriter, r *http.Request)

ListBucketsHandler - GET Service ----------- This implementation of the GET operation returns a list of all buckets owned by the authenticated sender of the request.

func (ObjectAPIHandlers) ListMultipartUploadsHandler

func (api ObjectAPIHandlers) ListMultipartUploadsHandler(w http.ResponseWriter, r *http.Request)

ListMultipartUploadsHandler - GET Bucket (List Multipart uploads) ------------------------- This operation lists in-progress multipart uploads. An in-progress multipart upload is a multipart upload that has been initiated, using the Initiate Multipart Upload request, but has not yet been completed or aborted. This operation returns at most 1,000 multipart uploads in the response.

func (ObjectAPIHandlers) ListObjectPartsHandler

func (api ObjectAPIHandlers) ListObjectPartsHandler(w http.ResponseWriter, r *http.Request)

ListObjectPartsHandler - List object parts

func (ObjectAPIHandlers) ListObjectsHandler

func (api ObjectAPIHandlers) ListObjectsHandler(w http.ResponseWriter, r *http.Request)

ListObjectsHandler - GET Bucket (List Objects) -- ----------------------- This implementation of the GET operation returns some or all (up to 1000) of the objects in a bucket. You can use the request parameters as selection criteria to return a subset of the objects in a bucket.

func (ObjectAPIHandlers) ListVersionedObjectsHandler

func (api ObjectAPIHandlers) ListVersionedObjectsHandler(w http.ResponseWriter, r *http.Request)

func (ObjectAPIHandlers) NewMultipartUploadHandler

func (api ObjectAPIHandlers) NewMultipartUploadHandler(w http.ResponseWriter, r *http.Request)

NewMultipartUploadHandler - New multipart upload

func (ObjectAPIHandlers) PostPolicyBucketHandler added in v1.1.0

func (api ObjectAPIHandlers) PostPolicyBucketHandler(w http.ResponseWriter, r *http.Request)

func (ObjectAPIHandlers) PutBucketAclHandler

func (api ObjectAPIHandlers) PutBucketAclHandler(w http.ResponseWriter, r *http.Request)

func (ObjectAPIHandlers) PutBucketCorsHandler

func (api ObjectAPIHandlers) PutBucketCorsHandler(w http.ResponseWriter, r *http.Request)

func (ObjectAPIHandlers) PutBucketHandler

func (api ObjectAPIHandlers) PutBucketHandler(w http.ResponseWriter, r *http.Request)

PutBucketHandler - PUT Bucket ---------- This implementation of the PUT operation creates a new bucket for authenticated request

func (ObjectAPIHandlers) PutBucketLifeCycleHandler

func (api ObjectAPIHandlers) PutBucketLifeCycleHandler(w http.ResponseWriter, r *http.Request)

func (ObjectAPIHandlers) PutBucketPolicyHandler

func (api ObjectAPIHandlers) PutBucketPolicyHandler(w http.ResponseWriter, r *http.Request)

PutBucketPolicyHandler - This HTTP handler stores given bucket policy configuration as per https://docs.aws.amazon.com/AmazonS3/latest/dev/access-policy-language-overview.html

func (ObjectAPIHandlers) PutBucketVersioningHandler

func (api ObjectAPIHandlers) PutBucketVersioningHandler(w http.ResponseWriter, r *http.Request)

func (ObjectAPIHandlers) PutObjectAclHandler

func (api ObjectAPIHandlers) PutObjectAclHandler(w http.ResponseWriter, r *http.Request)

func (ObjectAPIHandlers) PutObjectHandler

func (api ObjectAPIHandlers) PutObjectHandler(w http.ResponseWriter, r *http.Request)

PutObjectHandler - PUT Object ---------- This implementation of the PUT operation adds an object to a bucket.

func (ObjectAPIHandlers) PutObjectPartHandler

func (api ObjectAPIHandlers) PutObjectPartHandler(w http.ResponseWriter, r *http.Request)

PutObjectPartHandler - Upload part

type ObjectLayer

type ObjectLayer interface {
	// Bucket operations.
	MakeBucket(bucket string, acl datatype.Acl, credential common.Credential) error
	SetBucketLc(bucket string, config datatype.Lc,
		credential common.Credential) error
	GetBucketLc(bucket string, credential common.Credential) (datatype.Lc, error)
	DelBucketLc(bucket string, credential common.Credential) error
	SetBucketAcl(bucket string, policy datatype.AccessControlPolicy, acl datatype.Acl,
		credential common.Credential) error
	GetBucketAcl(bucket string, credential common.Credential) (datatype.AccessControlPolicyResponse, error)
	SetBucketCors(bucket string, cors datatype.Cors, credential common.Credential) error
	SetBucketVersioning(bucket string, versioning datatype.Versioning, credential common.Credential) error
	DeleteBucketCors(bucket string, credential common.Credential) error
	GetBucketVersioning(bucket string, credential common.Credential) (datatype.Versioning, error)
	GetBucketCors(bucket string, credential common.Credential) (datatype.Cors, error)
	GetBucket(bucketName string) (bucket meta.Bucket, err error) // For INTERNAL USE ONLY
	GetBucketInfo(bucket string, credential common.Credential) (bucketInfo meta.Bucket, err error)
	ListBuckets(credential common.Credential) (buckets []meta.Bucket, err error)
	DeleteBucket(bucket string, credential common.Credential) error
	ListObjects(credential common.Credential, bucket string,
		request datatype.ListObjectsRequest) (result meta.ListObjectsInfo, err error)
	ListVersionedObjects(credential common.Credential, bucket string,
		request datatype.ListObjectsRequest) (result meta.VersionedListObjectsInfo, err error)

	SetBucketPolicy(credential common.Credential, bucket string, policy policy.Policy) error
	// Policy operations
	GetBucketPolicy(credential common.Credential, bucket string) (policy.Policy, error)
	DeleteBucketPolicy(credential common.Credential, bucket string) error

	// Object operations.
	GetObject(object *meta.Object, startOffset int64, length int64, writer io.Writer,
		sse datatype.SseRequest) (err error)
	GetObjectInfo(bucket, object, version string, credential common.Credential) (objInfo *meta.Object,
		err error)
	PutObject(bucket, object string, credential common.Credential, size int64, data io.Reader,
		metadata map[string]string, acl datatype.Acl,
		sse datatype.SseRequest) (result datatype.PutObjectResult, err error)
	AppendObject(bucket, object string, credential common.Credential, offset uint64, size int64, data io.Reader,
		metadata map[string]string, acl datatype.Acl,
		sse datatype.SseRequest, objInfo *meta.Object) (result datatype.AppendObjectResult, err error)

	CopyObject(targetObject *meta.Object, source io.Reader, credential common.Credential,
		sse datatype.SseRequest) (result datatype.PutObjectResult, err error)
	UpdateObjectAttrs(targetObject *meta.Object, credential common.Credential) (result datatype.PutObjectResult, err error)
	SetObjectAcl(bucket string, object string, version string, policy datatype.AccessControlPolicy,
		acl datatype.Acl, credential common.Credential) error
	GetObjectAcl(bucket string, object string, version string, credential common.Credential) (
		policy datatype.AccessControlPolicyResponse, err error)
	DeleteObject(bucket, object, version string, credential common.Credential) (datatype.DeleteObjectResult,
		error)

	// Multipart operations.
	ListMultipartUploads(credential common.Credential, bucket string,
		request datatype.ListUploadsRequest) (result datatype.ListMultipartUploadsResponse, err error)
	NewMultipartUpload(credential common.Credential, bucket, object string,
		metadata map[string]string, acl datatype.Acl,
		sse datatype.SseRequest) (uploadID string, err error)
	PutObjectPart(bucket, object string, credential common.Credential, uploadID string, partID int,
		size int64, data io.Reader, md5Hex string,
		sse datatype.SseRequest) (result datatype.PutObjectPartResult, err error)
	CopyObjectPart(bucketName, objectName, uploadId string, partId int, size int64, data io.Reader,
		credential common.Credential, sse datatype.SseRequest) (result datatype.PutObjectResult,
		err error)
	ListObjectParts(credential common.Credential, bucket, object string,
		request datatype.ListPartsRequest) (result datatype.ListPartsResponse, err error)
	AbortMultipartUpload(credential common.Credential, bucket, object, uploadID string) error
	CompleteMultipartUpload(credential common.Credential, bucket, object, uploadID string,
		uploadedParts []meta.CompletePart) (result datatype.CompleteMultipartResult, err error)
}

ObjectLayer implements primitives for object API layer.

type Replacer

type Replacer interface {
	Replace(string) string
	Set(key, value string)
}

Replacer is a type which can replace placeholder substrings in a string with actual values from a http.Request and ResponseRecorder. Always use NewReplacer to get one of these. Any placeholders made with Set() should overwrite existing values if the key is already used.

func NewReplacer

func NewReplacer(r *http.Request, rr *ResponseRecorder, emptyValue string) Replacer

NewReplacer makes a new replacer based on r and rr which are used for request and response placeholders, respectively. Request placeholders are created immediately, whereas response placeholders are not created until Replace() is invoked. rr may be nil if it is not available. emptyValue should be the string that is used in place of empty string (can still be empty string).

type ResponseRecorder

type ResponseRecorder struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

func NewResponseRecorder

func NewResponseRecorder(w http.ResponseWriter) *ResponseRecorder

func (*ResponseRecorder) Flush

func (r *ResponseRecorder) Flush()

type Server

type Server struct {
	Server *http.Server
}

func (*Server) Stop

func (s *Server) Stop()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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