예제 #1
0
 def save_value(self, app_id, key, subkey, value):
     '''
     Saves a value in the database.
     Creates the needed references of key and app if needed.
     
     @param app_id: string The identification of the requesting app
     @param key: string The key that will identify all given values
     @param subkey: string The subkey that identifies this specific value
     @param value: string Value to store
     
     @raise TypeProviderError: Notifies that the given key matches with another ResourceType
     '''
     app = App.get_by(name=app_id)
     if app == None:
         app = App(name=app_id)
     key_db = Key.get_by(name=key,app_name=app_id)
     if key_db == None:
         key_db = Key(name=key,app=app, type_name=self.providerType)
     if key_db.type_name != self.providerType:
         raise TypeProviderError(self.providerType, key_db.type_name)
         
     value_db = Value()
     value_db.key = key_db
     value_db.subkey = subkey
     value_db.value = value
     session.commit()
예제 #2
0
def get_provider_name(app, key):
    '''
    Gets the Provider id from an app key
    '''
    key_stored = Key.get_by(app_name = app, name = key)
    if key_stored == None:
        raise NotExistingProviderError()
    return key_stored.type_name
예제 #3
0
 def get_key(self, app, key):
     '''
     Gets a model.Key object from the database.
     
     @param app: string App id
     @param key: string Key name
     @return: model.Key
     '''
     return Key.get_by(app_name = app, name = key)
예제 #4
0
 def remove_key(self, app_id, key):
     '''
     Removes a key and all their values stored in the database.
     
     @param app_id: string The identification of the requesting app_id
     @param key: string The key that is going to be erased
     '''
     key_db = Key.get_by(name = key, app_name = app_id)
     for value in key_db.values:
         value.delete()
     key_db.delete()
     session.commit()