Example #1
0
// Goroutine for saving the state.
func saver(ticker *time.Ticker) {
	for {
		select {
		case <-ticker.C:
			println("Writing state")
			lock.Lock()
			if dirty {
				dirty = false
				state := State{folders}

				bytes, err := json.Marshal(state)
				if err != nil {
					panic(err)
				}

				// write to S3
				auth, err := aws.EnvAuth()
				if err != nil {
					panic(err)
				}
				s := s3.New(auth, aws.USEast)
				bucket := s.Bucket(s3_bucket)
				err = bucket.Put("rss.json", bytes, "application/json", s3.ACL("private"))
				if err != nil {
					panic(err)
				}
			}
			lock.Unlock()
		}
	}
}
Example #2
0
func Put(bucket *s3.Bucket, path string, file string) {
	contType := "binary/octet-stream"
	Perms := s3.ACL("private")

	data, err := ioutil.ReadFile(file)
	if err != nil {
		panic(err.Error())
	}

	err = bucket.Put(path, data, contType, Perms)
	if err != nil {
		panic(err.Error())
	}
}
Example #3
0
// PUT on a bucket creates the bucket.
// http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTBucketPUT.html
func (r bucketResource) put(a *action) interface{} {
	if r.bucket == nil {
		if !validBucketName(r.name) {
			fatalf(400, "InvalidBucketName", "The specified bucket is not valid")
		}
		// TODO parse location constraint
		// TODO validate acl
		r.bucket = &bucket{
			name: r.name,
			// TODO default acl
			objects: make(map[string]*object),
		}
		a.srv.buckets[r.name] = r.bucket
	}
	r.bucket.acl = s3.ACL(a.req.Header.Get("x-amz-acl"))
	return nil
}
Example #4
0
// PUT on a bucket creates the bucket.
// http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTBucketPUT.html
func (r bucketResource) put(a *action) interface{} {
	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
	}
	r.bucket.acl = s3.ACL(a.req.Header.Get("x-amz-acl"))
	return nil
}
Example #5
0
func syncPath(acl, localPath, path string, bucket *s3.Bucket) {
	s3Path := strings.Replace(path, localPath, "", -1)
	file, err := os.Open(path)
	if err != nil {
		fmt.Println("Error opening local file, Failed to sync '" + path + "'")
		return
	}
	info, err := file.Stat()
	if err != nil {
		fmt.Println("Error stating local file, Failed to sync '" + path + "'")
		return
	}
	length := info.Size()
	pathSplit := strings.Split(path, ".")
	ext := pathSplit[len(pathSplit)-1]
	mtype := mime.TypeByExtension(ext)
	puterr := bucket.PutReader(s3Path, file, length, mtype, s3.ACL(acl))
	if puterr != nil {
		fmt.Println("Failed to sync: " + s3Path)
		return
	}
	fmt.Println("Synced: " + s3Path)

}
Example #6
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
}