Exemplo n.º 1
0
func writeJobObject(userS3Bucket *s3.Bucket, userKeywords string) {
	timestamp := int64toString(time.Now().UnixNano())
	s := userS3Bucket.S3.Auth.AccessKey + userS3Bucket.S3.Auth.SecretKey
	h := sha1.New()
	h.Write([]byte(s))
	hString := hex.EncodeToString(h.Sum(nil))
	key := hString + "_" + userS3Bucket.Name + "." + userKeywords
	err := s3Bucket.Put(jobPrefix+"_"+key, []byte(timestamp), "text/plain", s3.ACL("bucket-owner-full-control"))
	if err != nil {
		fmt.Println("ERROR: Can't write/update the job object")
	}
}
Exemplo n.º 2
0
func Stop(w http.ResponseWriter, r *http.Request) *appError {
	decoder := json.NewDecoder(r.Body)
	var s map[string]string
	err := decoder.Decode(&s)
	if err != nil {
		fmt.Println(err)
	}
	str := s["accesskey"] + s["secretkey"]
	h := sha1.New()
	h.Write([]byte(str))
	hString := hex.EncodeToString(h.Sum(nil))
	key := hString + "_" + s["bucket"] + "." + s["keywords"]
	_, err = s3Bucket.Get(jobPrefix + "_" + key)
	if err != nil {
		return &appError{err: err, status: http.StatusForbidden, json: "Job already stopped, but you need to wait up to one hour before being able to start it again if an instance of the application has crashed"}
	} else {
		err = s3Bucket.Put(jobPrefix+"_"+key+"_"+jobStopSuffix, nil, "text/plain", s3.ACL("bucket-owner-full-control"))
		if err != nil {
			return &appError{err: err, status: http.StatusInternalServerError, json: "Can't stop the job"}
		}
	}

	return nil
}
Exemplo n.º 3
0
func writeObject(data []byte, userS3Bucket *s3.Bucket, userKeywords string) {
	timestamp := int64toString(time.Now().UnixNano())
	err := userS3Bucket.Put("/data/keywords_"+userKeywords+"_"+timestamp+".txt", data, "text/plain", s3.ACL("public-read-write"))
	if err != nil {
		fmt.Println("ERROR: Can't write the object")
	}
	writeJobObject(userS3Bucket, userKeywords)
}