Beispiel #1
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 #2
0
func (self *restServer) addRestContext(original func(*restContext)) func(*httpserver.RequestContext) {
	return func(requestContext *httpserver.RequestContext) {
		rContext := new(restContext)
		rContext.RequestContext = requestContext

		// Since it's stateless, every request gets a client ID
		clientData := &caprica.ClientData{
			UserId: user.Id([]byte("TODO_READ_USER_ID_FROM_HEADE_OR_COOKIES")),
		}
		clientId := self.caprica.NewClient(restClientType, clientData)
		rContext.clientId = clientId
		rContext.caprica = self.caprica

		original(rContext)

		// Stateless: After each request, remove the client
		self.caprica.ClientClose(clientId)
	}
}
Beispiel #3
0
func (self *TypedGetterSetter) Creator() (creator user.Id, err error) {
	binaryValue, err := self.Get(creatorKey)
	if err != nil {
		return
	}
	if binaryValue == nil || len(binaryValue) == 0 {
		err = errors.New("No user ID stored in metadata")
		return
	}

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

	return user.Id(userIdAsBytes), nil
}
Beispiel #4
0
func (self *jsonWebsocketConnection) initClientData() {
	clientData := new(caprica.ClientData)
	clientData.UserId = user.Id([]byte("Demo User")) //TODO
	clientData.NotificationFunction = func(notification *caprica.Notification) {
		// Got a notification. Do not block for a long time here
		jsonMessage, err := NotificationToJson(notification)
		if err != nil {
			log.Println("Error converting notification to json. Close"+
				"connection here. Error: %v\n", err)
			self.ws.Close()
			return
		}

		// Ok, write message
		self.writeLimited(websocket.TextMessage, jsonMessage, notification.DroppingAllowed)
	}
	clientId := self.caprica.NewClient(jsonWebsocketConnectionType, clientData)

	self.clientId = clientId
}
Beispiel #5
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
}