api

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 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 (
	MIN_PART_SIZE = 128 << 10 // 128KB
)

Variables

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

Functions

func CheckValidBucketName added in v1.1.3

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 v1.1.3

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 added in v1.1.3

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 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

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, objectLayer 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(handler http.Handler, _ ObjectLayer) http.Handler

func SetObjectHeaders

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

Write object header

func SetRateLimitHandler

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 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

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

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

func (AuthHandler) ServeHTTP

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

handler for validating incoming authorization headers.

type ContextKey

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 added in v1.2.1

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 added in v1.1.3

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

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 added in v1.1.3

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 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