def create_data_type_composite(self, DTname, datafields): """ Create a new composite Data Type. @param DTname -- name of the new composite Data Type @param datafields -- a (nested) dictionary storing the names of the data fields (as key) and their Data Type (as value) @return success status via a ReturnValue """ logmsg = "creating composite data type '%s': %s" % (DTname, datafields) try: self.logger.debug(logmsg) return ReturnValue(None) except Exception as err: self.logger.error(logmsg + " %s" % err) return ReturnValue(None, False, str(err))
def create_data_type_composite(DTname, datafields, vaultID, uid): """ Create a new composite Data Type. @param DTname -- name of the new composite Data Type @param datafields -- a (nested) dictionary storing the names of the data fields (as key) and their Data Type (as value) @param vaultID -- name of the Data Vault to which the new Data Type is being added @param uid -- ID of the user making the request """ logmsg = "'%s' on vault '%s'] create composite data type '%s': %s" % (uid, vaultID, DTname, datafields) try: retval = _authorize_request("create_data_type_composite", uid) if not retval.ok: logger_data.info(logmsg + " [FAILED: can't authorize, %s]" % retval.errmsg) return ReturnValue(None, False, retval.errmsg) if not vaults.has_key(vaultID): raise Exception("vault '%s' not found" % vaultID) vault = vaults[vaultID] vault.create_data_type_composite(DTname, datafields) logger_data.info(logmsg + " [OK]") except Exception as err: logger_data.info(logmsg + " [FAILED: %s]" % err)
def create_data_type_scalar(DTname, DTbase_name, DTCname, DTCvalue, vaultID, uid): """ Create a new scalar Data Type. @param DTname -- name of the new scalar Data Type @param DTbase_name -- name of the built-in scalar Data Type on which the new Data Type is based @param DTCname -- name of the Data Type Constraint attached to the new Data Type @param vaultID -- name of the Data Vault to which the new Data Type is being added @param uid -- ID of the user making the request """ s = "" for i in range(len(DTCname)): s += (" and %s(%s)" if i > 0 else "%s(%s)") % (DTCname[i], DTCvalue[i]) logmsg = "'%s' on vault '%s'] create scalar data type '%s': %s with constraints %s" % (uid, vaultID, DTname, DTbase_name, s) try: retval = _authorize_request("create_data_type_scalar", uid) if not retval.ok: logger_data.info(logmsg + " [FAILED: can't authorize, %s]" % retval.errmsg) return ReturnValue(None, False, retval.errmsg) if not vaults.has_key(vaultID): raise Exception("vault '%s' not found" % vaultID) vault = vaults[vaultID] vault.create_data_type_scalar(DTname, DTbase_name, DTCname, DTCvalue) logger_data.info(logmsg + " [OK]") except Exception as err: logger_data.info(logmsg + " [FAILED: %s]" % err)
def update_incarnation(DIname, key, value, vaultID, uid): """ Updates the value of an existing Data Item incarnation. @param DIname -- the Data Item name @param key -- unique (among incarnations of the same Data Item) incarnation ID @param value -- the updated value of the incarnation @param vaultID -- name of the Data Vault storing the incarnation @param uid -- ID of the user making the request """ logmsg = "'%s' on vault '%s'] update incarnation of '%s' with key='%s' to value='%s'" % (uid, vaultID, DIname, key, value) try: retval = _authorize_request("update_incarnation", uid) if not retval.ok: logger_data.info(logmsg + " [FAILED: can't authorize, %s]" % retval.errmsg) return ReturnValue(None, False, retval.errmsg) if not vaults.has_key(vaultID): raise Exception("vault '%s' not found" % vaultID) vault = vaults[vaultID] vault.update_incarnation(DIname, key, value) logger_data.info(logmsg + " [OK]") except Exception as err: logger_data.info(logmsg + " [FAILED: %s]" % err)
def create_incarnation(DIname, key, value, vaultID, uid): """ Create a new incarnation (managed instance) of a Data Item. @param DIname -- the Data Item name @param key -- unique (among incarnations of the same Data Item) incarnation ID @param value -- the initial value of the incarnation @param vaultID -- name of the Data Vault to which the new incarnation is being added @param uid -- ID of the user making the request """ logmsg = "'%s' on vault '%s'] create incarnation of '%s' with key='%s' & value='%s'" % (uid, vaultID, DIname, key, value) try: retval = _authorize_request("create_incarnation", uid) if not retval.ok: logger_data.info(logmsg + " [FAILED: can't authorize, %s]" % retval.errmsg) return ReturnValue(None, False, retval.errmsg) if not vaults.has_key(vaultID): raise Exception("vault '%s' not found" % vaultID) vault = vaults[vaultID] vault.create_data_item_incarnation(DIname, key, value) logger_data.info(logmsg + " [OK]") except Exception as err: logger_data.info(logmsg + " [FAILED: %s]" % err)
def create_data_item(DIname, DTname, vaultID, uid): """ Create a new Data Item. @param DIname -- name of the new Data Item being created @param DTname -- name of the Data Type associated with the new Data Item. @param vaultID -- name of the Data Vault to which the new Data Item is being added @param uid -- ID of the user making the request """ logmsg = "'%s' on vault '%s'] create data item '%s' of type '%s'" % (uid, vaultID, DIname, DTname) try: retval = _authorize_request("create_data_item", uid) if not retval.ok: logger_data.info(logmsg + " [FAILED: can't authorize, %s]" % retval.errmsg) return ReturnValue(None, False, retval.errmsg) if not vaults.has_key(vaultID): raise Exception("vault '%s' not found" % vaultID) vault = vaults[vaultID] vault.create_data_item(DIname, DTname) logger_data.info(logmsg + " [OK]") except Exception as err: logger_data.info(logmsg + " [FAILED: %s]" % err)
def create_data_item(self, DIname, DTname): """ Create a new Data Item. @param DIname -- name of the new Data Item being created @param DTname -- name of the Data Type associated with the new Data Item. @return success status via a ReturnValue """ logmsg = "creating data item '%s' of type '%s'" % (DIname, DTname) try: 1 / 0 self.logger.debug(logmsg) return ReturnValue(None) except Exception as err: self.logger.error(logmsg + " %s" % err) return ReturnValue(None, False, str(err))
def create_data_item_incarnation(self, DIname, key, value): """ Create a new incarnation (managed instance) of a Data Item. @param DIname -- the Data Item name @param key -- unique (among incarnations of the same Data Item) incarnation ID @param value -- the initial value of the incarnation @return success status via a ReturnValue """ logmsg = "creating incarnation of '%s' with key='%s' & value='%s'" % ( DIname, key, value) try: self.logger.debug(logmsg) return ReturnValue(None) except Exception as err: self.logger.error(logmsg + " %s" % err) return ReturnValue(None, False, str(err))
def update_incarnation(self, DIname, key, value): """ Updates the value of an existing Data Item incarnation. @param DIname -- the Data Item name @param key -- unique (among incarnations of the same Data Item) incarnation ID @param value -- the updated value of the incarnation @return success status via a ReturnValue """ logmsg = "updating incarnation of '%s' with key='%s' to value='%s'" % ( DIname, key, value) try: self.logger.debug(logmsg) return ReturnValue(None) except Exception as err: self.logger.error(logmsg + " %s" % err) return ReturnValue(None, False, str(err))
def _authorize_request(action, uid): """ Check whether a given user can perform a given action. @param action -- the name of the action the user would like to perform @param uid -- ID of the user being authenticated @return """ actions = ["create_vault", "delete_vault", "create_data_type_scalar", "create_data_type_composite", "create_data_item", "create_incarnation", "update_incarnation"] try: if action not in actions: return ReturnValue(None, False, "unknown request type '%s'" % action) else: return ReturnValue(None, True) except: pass
def create_data_type_scalar(self, DTname, DTbase_name, DTCname, DTCvalue): """ Create a new scalar Data Type. @param DTname -- name of the new scalar Data Type @param DTbase_name -- name of the built-in scalar Data Type on which the new Data Type is based @param DTCname -- name of the Data Type Constraint attached to the new Data Type @return success status via a ReturnValue """ s = "" for i in range(len(DTCname)): s += (" and %s(%s)" if i > 0 else "%s(%s)") % (DTCname[i], DTCvalue[i]) logmsg = "creating scalar data type '%s': %s with constraints %s" % ( DTname, DTbase_name, s) try: self.logger.debug(logmsg) return ReturnValue(None) except Exception as err: self.logger.error(logmsg + " %s" % err) return ReturnValue(None, False, str(err))
def create_vault(vaultID, uid): """ Create a new Data Vault. @param vaultID -- name of the new Data Vault @uid -- ID of the user making the request """ logmsg = "'%s' on vault '%s'] create vault" % (uid, vaultID) try: retval = _authorize_request("create_vault", uid) if not retval.ok: logger_data.info(logmsg + " [FAILED: can't authorize, %s]" % retval.errmsg) return ReturnValue(None, False, retval.errmsg) vaults[vaultID] = DataVault(vaultID) logger_data.info(logmsg + " [OK]") except Exception as err: logger_data.info(logmsg + " [FAILED: %s]" % err)
def delete_vault(vaultID, uid): """ Delete an existing Data Vault. All data stored inside the vault is lost. @param vaultID -- name of the Data Vault to be deleted @uid -- ID of the user making the request """ logmsg = "'%s' on vault '%s'] delete vault" % (uid, vaultID) try: retval = _authorize_request("delete_vault", uid) if not retval.ok: logger_data.info(logmsg + " [FAILED: can't authorize, %s]" % retval.errmsg) return ReturnValue(None, False, retval.errmsg) if not vaults.has_key(vaultID): raise Exception("vault '%s' not found" % vaultID) del vaults[vaultID] logger_data.info(logmsg + " [OK]") except Exception as err: logger_data.info(logmsg + " [FAILED: %s]" % err)