Beispiel #1
0
func (self *restContext) ReadBucketId(value *httpserver.Values, key string, optional bool) (
	bucketId bucket.Id,
	bucketIdAsString string,
	status retcode.Status) {

	if optional {
		bucketIdAsString = value.OptionalString(key)
		if bucketIdAsString == "" {
			return
		}
	} else {
		bucketIdAsString, status = value.NonEmptyString(key)
		if !status.IsOk() {
			return
		}
	}

	bucketIdBytes, err := encoding.Base32Decode(bucketIdAsString)
	if err != nil {
		status = retcode.NewStatusFmt(retcode.ErrorClient, "Invalid bucket id given. The id "+
			"has to be base32 without padding. Err: %v", err)
		return
	}
	bucketId = bucket.Id(bucketIdBytes)
	status = retcode.NewStatusOk()
	return
}
Beispiel #2
0
func (self *Converter) ReadBucketId(input interface{}) bucket.Id {
	if input == nil {
		panic("Expecting a bucket id but value is missing")
	}
	switch input := input.(type) {
	case string:
		bucketIdBinary, err := strencoding.Encode(input, strencoding.Base32)
		if err != nil {
			panic(err)
		}
		return bucket.Id(bucketIdBinary)
	case []byte:
		return bucket.Id(self.ReadBinary(input))
	case bucket.Id:
		return input
	default:
		panic(fmt.Sprintf("Expecting a string or a binary but got a %T", input))
	}
}
Beispiel #3
0
func (self *capricaStruct) initializeGlobalDirectoryStore() (err error) {
	sysstorage := self.buran.SystemStorage()
	valuePtr, err := sysstorage.Get(globaldirectory_key)
	if err != nil {
		return
	}
	if valuePtr == nil {
		// First get the global blob
		globalBlobId := self.globalBlobStoreId
		if globalBlobId == nil || len(globalBlobId) == 0 {
			err = errors.New("The global directory depends on the global blob store. So need " +
				"to create that first.")
			return
		}

		var globalBlobIdCbor []byte
		globalBlobIdCbor, err = encoding.Cbor().Encode(globalBlobId)
		if err != nil {
			return
		}

		// Need to create the global blob store
		operation := operations.CreateBucket{
			TypeId: bucket.TypeId_Directory,
			Metadata: metadata.MemoryMetadata{
				"const.forwarder.blob": globalBlobIdCbor,
			},
		}
		// TODO: Real context
		context := ares.Context{
			UserId: user.Id([]byte("Test")),
		}
		ret := self.buran.Perform(&context, &operation)
		if !ret.GetCode().IsOk() {
			// Error
			err = errors.New(fmt.Sprintf("Error creating "+
				"the global directory: %v", ret.GetText()))
			return
		}
		retCast := ret.(*operations.CreateBucketReturn)
		self.globalDirectoryId = retCast.Id

		// Store it - so we have the same on next start
		err = self.buran.SystemStorage().Put(globaldirectory_key, retCast.Id)
		if err != nil {
			return
		}
	} else {
		// Already have a global blob store
		self.globalDirectoryId = bucket.Id(*valuePtr)
	}
	return
}
Beispiel #4
0
func (self *TypedGetterSetter) Forwarder(constant bool,
	key string) (bucketId bucket.Id, exists bool, err error) {

	binaryValue, err := self.Get(generateKeyForForwarder(constant, key))
	if err != nil {
		return
	}
	if binaryValue == nil || len(binaryValue) == 0 {
		return
	}
	exists = true

	var bucketIdAsBinary []byte
	err = encoding.Cbor().Decode(binaryValue, &bucketIdAsBinary)
	if err != nil {
		err = errors.New(fmt.Sprintf("Error cbor decoding: %v\n", err))
		return
	}

	bucketId = bucket.Id(bucketIdAsBinary)
	return
}
Beispiel #5
0
func createBucket(t *testing.T, typeId int) (bucketIdAsString string) {
	test := &testframework.JsonTest{
		Input: fmt.Sprintf(`{
			"Operation" : "CreateBucket",
			"Data" : {
				"TypeId" : %v
			}}`, typeId),
		Expect: `{
			"Code" : 0,
			"Data" : {
				"Id" : "!(bucket_id:id)!"
			}
		}`,
	}
	runner().Run(t, test)
	if t.Failed() {
		return
	}
	bucketIdAsBytes := test.Arguments["id"].([]byte)
	// TODO: Remove dependencies to buran
	bucketId := bucket.Id(bucketIdAsBytes)
	return bucketId.ToString()
}
Beispiel #6
0
func (self *capricaStruct) initializeGlobalBlobStore() (err error) {
	sysstorage := self.buran.SystemStorage()
	valuePtr, err := sysstorage.Get(globalblobstore_key)
	if err != nil {
		return
	}
	if valuePtr == nil {
		// Need to create the global blob store
		operation := operations.CreateBucket{
			TypeId: bucket.TypeId_BlobStore,
		}
		// TODO: Real context
		context := ares.Context{
			UserId: user.Id([]byte("Test")),
		}
		ret := self.buran.Perform(&context, &operation)
		if !ret.GetCode().IsOk() {
			// Error
			err = errors.New(fmt.Sprintf("Error creating "+
				"the global blob store: %v", ret.GetText()))
			return
		}
		retCast := ret.(*operations.CreateBucketReturn)
		self.globalBlobStoreId = retCast.Id

		// Store it - so we have the same on next start
		err = self.buran.SystemStorage().Put(globalblobstore_key, retCast.Id)
		if err != nil {
			return
		}
	} else {
		// Already have a global blob store
		self.globalBlobStoreId = bucket.Id(*valuePtr)
	}
	return
}