コード例 #1
0
ファイル: outputconverter.go プロジェクト: cronosun/buranv1
func (self *Converter) WriteBucketId(input bucket.Id) interface{} {
	if input == nil {
		panic("Expecting a bucket id but value is missing")
	}
	if self.TypeIdAsBinary {
		return []byte(input)
	} else {
		return encoding.Base32Encode([]byte(input))
	}
}
コード例 #2
0
ファイル: outputconverter.go プロジェクト: cronosun/buranv1
func (self *Converter) WriteKeyElement(input []byte) interface{} {
	if input == nil {
		panic("Expecting key but value is missing")
	}
	if self.KeyElementsAsBinary {
		return []byte(input)
	} else {
		return encoding.Base32Encode(input)
	}
}
コード例 #3
0
ファイル: outputconverter.go プロジェクト: cronosun/buranv1
func (self *Converter) WriteSha256Hash(input []byte) interface{} {
	if input == nil {
		panic("Expecting a hash but value is missing")
	}
	if self.HashAsBinary {
		return input
	} else {
		return encoding.Base32Encode([]byte(input))
	}
}
コード例 #4
0
ファイル: outputconverter.go プロジェクト: cronosun/buranv1
func (self *Converter) WriteSubscriptionId(
	input operations.SubscriptionId) interface{} {

	if input == nil {
		panic("Expecting a subscription ID but value is missing")
	}
	if self.SubscriptionIdAsBinary {
		return []byte(input)
	} else {
		return encoding.Base32Encode([]byte(input))
	}
}
コード例 #5
0
ファイル: incubator.go プロジェクト: cronosun/buranv1
func (self *incubator) incubationFilePath(state *minos.OperationState,
	id string) (fname string, ret retcode.Status) {

	clientIdAsBase32 := encoding.Base32Encode([]byte(state.Context.ClientId))
	fname, err := state.Files.Filename(self.bucketId, "_"+clientIdAsBase32, id)
	if err != nil {
		ret = retcode.NewStatusError(retcode.ErrorServer, err)
		return
	}
	ret = retcode.NewStatusOk()
	return
}
コード例 #6
0
ファイル: public.go プロジェクト: cronosun/buranv1
func (self *public) publicFilePath(state *minos.OperationState,
	hash []byte) (fname string, ret retcode.Status) {

	hashAsBase32 := encoding.Base32Encode(hash)
	firstBytesAsDirectory := hashAsBase32[:6]
	fname, err := state.Files.Filename(self.bucketId,
		firstBytesAsDirectory, hashAsBase32)
	if err != nil {
		ret = retcode.NewStatusError(retcode.ErrorServer, err)
		return
	}
	ret = retcode.NewStatusOk()
	return
}
コード例 #7
0
ファイル: files.go プロジェクト: cronosun/buranv1
func (self *files) Filename(bucketId bucket.Id, discrimintor string,
	name string) (
	path string, err error) {

	typeIdPath := encoding.Base32Encode([]byte(bucketId))
	subPath := pathInclude.Join(self.storagePath, typeIdPath, discrimintor)

	err = os.MkdirAll(subPath, os.ModeDir|0777)
	if err != nil {
		return
	}

	path = pathInclude.Join(subPath, name)
	return
}
コード例 #8
0
ファイル: dirget.go プロジェクト: cronosun/buranv1
func (self *restServer) directoryGet(ctx *restContext) {
	var status retcode.Status

	hashAsString, status := ctx.UrlParams.NonEmptyString("hash")
	if !status.IsOk() {
		ctx.WriteErrorStatus(status)
		return
	}
	hash, err := encoding.Base32Decode(hashAsString)
	if err != nil {
		status = retcode.NewStatusFmt(retcode.ErrorClient, "Hash does not seem to be a base32 hash")
		ctx.WriteErrorStatus(status)
		return
	}

	filenames := directorySubPath(ctx.UrlParams, ctx)

	curEntry := &directoryEntry{
		isDirectory: true,
		targetHash:  hash,
	}
	finalEntry, found, status := directoryGetMultiple(ctx, curEntry, filenames)
	if !found {
		status = retcode.NewStatusFmt(retcode.OkNotFound, "Entry not found")
		ctx.WriteErrorStatus(status)
		return
	}

	if finalEntry.isDirectory {
		// Output all files from directory as json
		directoryOutputAsJson(ctx, finalEntry)
	} else {
		// Redirect to blobget
		hash := finalEntry.targetHash
		hashAsString := encoding.Base32Encode(hash)
		mime := finalEntry.mimeType
		self.blobGetWithParams(ctx, hash, hashAsString, nil, mime)
	}
}
コード例 #9
0
ファイル: bucket_id.go プロジェクト: cronosun/buranv1
func (self Id) ToString() string {
	return encoding.Base32Encode([]byte(self))
}
コード例 #10
0
ファイル: userid.go プロジェクト: cronosun/buranv1
func (self *Id) ToString() string {
	userIdBytes := []byte(*self)
	return encoding.Base32Encode(userIdBytes)
}
コード例 #11
0
ファイル: blobpost.go プロジェクト: cronosun/buranv1
func (self *restServer) blobPost(ctx *restContext) {
	var status retcode.Status

	var isGlobalBlobStore bool
	bucketId, bucketIdAsString, status := ctx.ReadBucketId(&ctx.UrlParams, "bucketId", true)
	if !status.IsOk() {
		ctx.WriteErrorStatus(status)
		return
	}
	if len(bucketId) == 0 {
		// Take the global blob store if no bucket id is supplied
		bucketId = self.caprica.GlobalBlobStoreId()
		isGlobalBlobStore = true
	}

	var out interface{}

	// Begin
	beginUpload := &operations.BucketPutIn{
		BucketOperation: operations.BucketOperation{
			BucketId: bucketId,
		},
		Key:   "incubation/from_rest_api/new",
		Value: [][]byte{},
	}
	out, status = ctx.execute(beginUpload, operations.BucketPut)
	if !status.IsOk() {
		ctx.WriteErrorStatus(status)
		return
	}

	// Now put the entire payload
	for true {
		readBuffer := make([]byte, maxReadPerElement)
		numReadFromBody, err := ctx.Request.Body.Read(readBuffer)
		defer ctx.Request.Body.Close()

		if err != nil && err != io.EOF {
			status = retcode.NewStatusFmt(retcode.ErrorClient, "Could not read body from client: "+
				"%v.", err)
			ctx.WriteErrorStatus(status)
			return
		}

		if numReadFromBody > 0 {
			uploadOneElement := &operations.BucketPutIn{
				BucketOperation: operations.BucketOperation{
					BucketId: bucketId,
				},
				Key:   "incubation/from_rest_api/append",
				Value: [][]byte{readBuffer[:numReadFromBody]},
			}
			out, status = ctx.execute(uploadOneElement, operations.BucketPut)
			if !status.IsOk() {
				ctx.WriteErrorStatus(status)
				return
			}
		}
		if err == io.EOF {
			// End, have read everything
			break
		}
	}

	// Now read the hash code
	readHashCode := &operations.BucketGetIn{
		BucketOperation: operations.BucketOperation{
			BucketId: bucketId,
		},
		Key: "incubation/from_rest_api/sum",
	}
	out, status = ctx.execute(readHashCode, operations.BucketGet)
	if !status.IsOk() {
		ctx.WriteErrorStatus(status)
		return
	}
	readHashCodeRet := out.(operations.BucketGetOut)
	hashCodeValues := readHashCodeRet.Value.([][]byte)
	if len(hashCodeValues) < 2 {
		status = retcode.NewStatusFmt(retcode.ErrorServer, "Could not get calculated hash value."+
			" Blob bucket returned less than 2 value elements.")
		ctx.WriteErrorStatus(status)
		return
	}
	var hashAsBinary []byte
	err := encoding.Cbor().Decode(hashCodeValues[0], &hashAsBinary)
	if err != nil {
		status = retcode.NewStatusFmt(retcode.ErrorServer, "Cbor decoding of hash code "+
			"failed: %v.", err)
		ctx.WriteErrorStatus(status)
		return
	}
	hashAsBase32 := encoding.Base32Encode(hashAsBinary)
	var location string
	if isGlobalBlobStore {
		location = fmt.Sprintf("/data/%v", hashAsBase32)
	} else {
		location = fmt.Sprintf("/data/%v/%v", bucketIdAsString, hashAsBase32)
	}

	// And now commit that thing
	commit := &operations.BucketPutIn{
		BucketOperation: operations.BucketOperation{
			BucketId: bucketId,
		},
		Key:   "incubation/from_rest_api/finish",
		Value: [][]byte{},
	}
	out, status = ctx.execute(commit, operations.BucketPut)
	if !status.IsOk() {
		ctx.WriteErrorStatus(status)
		return
	}

	// Ok, everything ok
	ctx.WriteLocation(location)
	ctx.Writer.WriteHeader(201)
}