Пример #1
0
func openS3Datastore(params config.S3Datastore) (repo.Datastore, error) {
	// TODO support credentials files
	auth, err := aws.EnvAuth()
	if err != nil {
		return nil, err
	}

	region := aws.GetRegion(params.Region)
	if region.Name == "" {
		return nil, fmt.Errorf("unknown AWS region: %q", params.Region)
	}

	if params.Bucket == "" {
		return nil, fmt.Errorf("invalid S3 bucket: %q", params.Bucket)
	}

	client := s3.New(auth, region)
	// There are too many gophermucking s3datastores in my
	// gophermucking source.
	return &s3datastore.S3Datastore{
		Client: client,
		Bucket: params.Bucket,
		ACL:    s3.ACL(params.ACL),
	}, nil
}
Пример #2
0
// PUT on a bucket creates the bucket.
// http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTBucketPUT.html
func (r bucketResource) put(a *action) interface{} {
	var created bool
	if r.bucket == nil {
		if !validBucketName(r.name) {
			fatalf(400, "InvalidBucketName", "The specified bucket is not valid")
		}
		if loc := locationConstraint(a); loc == "" {
			fatalf(400, "InvalidRequets", "The unspecified location constraint is incompatible for the region specific endpoint this request was sent to.")
		}
		// TODO validate acl
		r.bucket = &bucket{
			name: r.name,
			// TODO default acl
			objects: make(map[string]*object),
		}
		a.srv.buckets[r.name] = r.bucket
		created = true
	}
	if !created && a.srv.config.send409Conflict() {
		fatalf(409, "BucketAlreadyOwnedByYou", "Your previous request to create the named bucket succeeded and you already own it.")
	}
	r.bucket.acl = s3.ACL(a.req.Header.Get("x-amz-acl"))
	return nil
}