def wrap(*args, **kwargs): self = args[0] driver = get_driver(PG_DEFAULT_DRIVER) self.manager = driver.connection_manager(kwargs['sid']) # Get database connection self.conn = self.manager.connection(did=kwargs['did']) self.qtIdent = driver.qtIdent self.qtLiteral = driver.qtLiteral if not self.conn.connected(): return precondition_required( gettext( "Connection to the server has been lost." ) ) # Set template path for sql scripts depending # on the server version. self.sql_template_path = "/".join([ self.node_type, self.manager.server_type, '#{0}#' ]).format(self.manager.version) return f(*args, **kwargs)
def BackendSupported(self, manager, **kwargs): """ Load this module if vid is view, we will not load it under material view """ if super(TriggerModule, self).BackendSupported(manager, **kwargs): conn = manager.connection(did=kwargs['did']) # If DB is not connected then return error to browser if not conn.connected(): return precondition_required( gettext( "Connection to the server has been lost!" ) ) if 'vid' not in kwargs: return True template_path = 'trigger/sql/9.1_plus' SQL = render_template("/".join( [template_path, 'backend_support.sql']), vid=kwargs['vid']) status, res = conn.execute_scalar(SQL) # check if any errors if not status: return internal_server_error(errormsg=res) # Check vid is view not material view # then true, othewise false return res
def wrap(*args, **kwargs): self = args[0] driver = get_driver(PG_DEFAULT_DRIVER) self.manager = driver.connection_manager(kwargs['sid']) # Get database connection self.conn = self.manager.connection(did=kwargs['did']) self.qtIdent = driver.qtIdent self.qtLiteral = driver.qtLiteral if not self.conn.connected(): return precondition_required( gettext( "Connection to the server has been lost!" ) ) ver = self.manager.version # Set template path for sql scripts depending # on the server version. self.template_path = "/".join([ self.node_type ]) self.sql_template_path = "/".join([ self.template_path, self.manager.server_type, 'sql', '9.5_plus' if ver >= 90500 else '9.2_plus' if ver >= 90200 else '9.1_plus' ]) return f(*args, **kwargs)
def wrap(*args, **kwargs): # Here args[0] will hold self & kwargs will hold sid,did server_info.clear() server_info['manager'] = get_driver(PG_DEFAULT_DRIVER)\ .connection_manager(kwargs['sid']) server_info['conn'] = server_info['manager'].connection( did=kwargs['did'] ) # If DB not connected then return error to browser if not server_info['conn'].connected(): return precondition_required( gettext("Connection to the server has been lost.") ) # Set template path for sql scripts server_info['server_type'] = server_info['manager'].server_type server_info['version'] = server_info['manager'].version if server_info['server_type'] == 'pg': server_info['template_path'] = 'grant_wizard/pg/#{0}#'.format( server_info['version']) elif server_info['server_type'] == 'ppas': server_info['template_path'] = 'grant_wizard/ppas/#{0}#'.format( server_info['version']) return f(*args, **kwargs)
def wrap(*args, **kwargs): # Here args[0] will hold self & kwargs will hold gid,sid,did self = args[0] self.manager = get_driver(PG_DEFAULT_DRIVER).connection_manager( kwargs['sid'] ) self.conn = self.manager.connection(did=kwargs['did']) # If DB not connected then return error to browser if not self.conn.connected(): return precondition_required( _( "Connection to the server has been lost!" ) ) self.template_path = 'index_constraint/sql' # We need parent's name eg table name and schema name SQL = render_template("/".join([self.template_path, 'get_parent.sql']), tid=kwargs['tid']) status, rset = self.conn.execute_2darray(SQL) if not status: return internal_server_error(errormsg=rset) for row in rset['rows']: self.schema = row['schema'] self.table = row['table'] return f(*args, **kwargs)
def wrap(*args, **kwargs): self = args[0] driver = get_driver(PG_DEFAULT_DRIVER) self.manager = driver.connection_manager(kwargs['sid']) self.conn = self.manager.connection(did=kwargs['did']) self.qtIdent = driver.qtIdent # If DB not connected then return error to browser if not self.conn.connected(): return precondition_required( _("Connection to the server has been lost!") ) ver = self.manager.version # we will set template path for sql scripts if ver >= 90200: self.template_path = 'check_constraint/sql/9.2_plus' elif ver >= 90100: self.template_path = 'check_constraint/sql/9.1_plus' SQL = render_template("/".join([self.template_path, 'get_parent.sql']), tid=kwargs['tid']) status, rset = self.conn.execute_2darray(SQL) if not status: return internal_server_error(errormsg=rset) self.schema = rset['rows'][0]['schema'] self.table = rset['rows'][0]['table'] return f(*args, **kwargs)
def wrap(*args, **kwargs): self = args[0] driver = get_driver(PG_DEFAULT_DRIVER) self.manager = driver.connection_manager(kwargs['sid']) # Get database connection self.conn = self.manager.connection(did=kwargs['did']) self.qtIdent = driver.qtIdent if not self.conn.connected(): return precondition_required( gettext( "Connection to the server has been lost!" ) ) ver = self.manager.version server_type = self.manager.server_type # Set template path for sql scripts depending # on the server version. if ver >= 90500: self.template_path = 'foreign_tables/sql/9.5_plus' elif ver >= 90200: self.template_path = 'foreign_tables/sql/9.2_plus' else: self.template_path = 'foreign_tables/sql/9.1_plus' return f(*args, **kwargs)
def wrapped(self, *args, **kwargs): driver = get_driver(PG_DEFAULT_DRIVER) self.manager = driver.connection_manager(kwargs['sid']) self.qtIdent = driver.qtIdent if 'did' in kwargs: self.conn = self.manager.connection(did=kwargs['did']) else: self.conn = self.manager.connection() # If DB not connected then return error to browser if not self.conn.connected(): return precondition_required( _( "Connection to the server has been lost." ) ) self.template_path = 'package/ppas/#{0}#'.format( self.manager.version) SQL = render_template( "/".join([self.template_path, 'get_schema.sql']), scid=kwargs['scid'] ) status, rset = self.conn.execute_scalar(SQL) if not status: return internal_server_error(errormsg=rset) self.schema = rset # Allowed ACL on package self.acl = ['X'] return f(self, *args, **kwargs)
def wrap(*args, **kwargs): # Here args[0] will hold self & kwargs will hold gid,sid,tsid self = args[0] self.manager = get_driver( PG_DEFAULT_DRIVER ).connection_manager( kwargs['sid'] ) self.conn = self.manager.connection() # If DB not connected then return error to browser if not self.conn.connected(): current_app.logger.warning( "Connection to the server has been lost." ) return precondition_required( gettext( "Connection to the server has been lost." ) ) self.template_path = 'tablespaces/sql/#{0}#'.format( self.manager.version ) current_app.logger.debug( "Using the template path: %s", self.template_path ) # Allowed ACL on tablespace self.acl = ['C'] return f(*args, **kwargs)
def children(self, **kwargs): """Build a list of treeview nodes from the child nodes.""" if 'sid' not in kwargs: return precondition_required( gettext('Required properties are missing.') ) from pgadmin.utils.driver import get_driver manager = get_driver(PG_DEFAULT_DRIVER).connection_manager( sid=kwargs['sid'] ) did = None if 'did' in kwargs: did = kwargs['did'] conn = manager.connection(did=did) if not conn.connected(): return precondition_required( gettext( "Connection to the server has been lost." ) ) nodes = [] for module in self.blueprint.submodules: if isinstance(module, PGChildModule): if manager is not None and \ module.BackendSupported(manager, **kwargs): # treat partition table as normal table. # replace tid with ptid and pop ptid from kwargs if 'ptid' in kwargs: ptid = kwargs.pop('ptid') kwargs['tid'] = ptid nodes.extend(module.get_nodes(**kwargs)) else: nodes.extend(module.get_nodes(**kwargs)) # Return sorted nodes based on label return make_json_response( data=sorted( nodes, key=lambda c: c['label'] ) )
def wrap(*args, **kwargs): # Here args[0] will hold self & kwargs will hold gid,sid,did g.manager = get_driver(PG_DEFAULT_DRIVER).connection_manager( kwargs['sid']) stats_type = ('activity', 'prepared', 'locks', 'config') # Below check handle the case where existing server is deleted # by user and python server will raise exception if this check # is not introduce. if g.manager is None: if f.__name__ in stats_type: return precondition_required( gettext("Please connect to the selected server" " to view the table.")) else: return precondition_required( gettext("Please connect to the selected server" " to view the graph.")) if 'did' in kwargs: g.conn = g.manager.connection(did=kwargs['did']) # If the selected DB not connected then return error to browser if not g.conn.connected(): if f.__name__ in stats_type: return precondition_required( gettext("Please connect to the selected database" " to view the table.")) else: return precondition_required( gettext("Please connect to the selected database to" " view the graph.")) else: g.conn = g.manager.connection() # If DB not connected then return error to browser if not g.conn.connected(): if f.__name__ in stats_type: return precondition_required( gettext("Please connect to the selected server" " to view the table.")) else: return precondition_required( gettext("Please connect to the selected server" " to view the graph.")) # Set template path for sql scripts g.server_type = g.manager.server_type g.version = g.manager.version # Include server_type in template_path when server_type is gpdb g.template_path = 'dashboard/sql/' + ('#{0}#{1}#'.format( g.server_type, g.version) if g.server_type == 'gpdb' else '#{0}#'.format(g.version)) return f(*args, **kwargs)
def children(self, **kwargs): """Build a list of treeview nodes from the child nodes.""" if 'sid' not in kwargs: return precondition_required( gettext('Required properties are missing.')) from pgadmin.utils.driver import get_driver manager = get_driver(PG_DEFAULT_DRIVER).connection_manager( sid=kwargs['sid']) did = None if 'did' in kwargs: did = kwargs['did'] conn = manager.connection(did=did) if not conn.connected(): return precondition_required( gettext("Connection to the server has been lost.")) nodes = [] for module in self.blueprint.submodules: if isinstance(module, PGChildModule): if manager is not None and \ module.BackendSupported(manager, **kwargs): # treat partition table as normal table. # replace tid with ptid and pop ptid from kwargs if 'ptid' in kwargs: ptid = kwargs.pop('ptid') kwargs['tid'] = ptid nodes.extend(module.get_nodes(**kwargs)) else: nodes.extend(module.get_nodes(**kwargs)) # Return sorted nodes based on label return make_json_response(data=sorted(nodes, key=lambda c: c['label']))
def wrap(*args, **kwargs): # Here args[0] will hold self & kwargs will hold gid,sid,did self = args[0] self.manager = get_driver(PG_DEFAULT_DRIVER).connection_manager( kwargs['sid'] ) self.conn = self.manager.connection(did=kwargs['did']) # If DB not connected then return error to browser if not self.conn.connected(): return precondition_required( gettext( "Connection to the server has been lost!" ) ) # We need datlastsysoid to check if current trigger is system trigger self.datlastsysoid = self.manager.db_info[kwargs['did']]['datlastsysoid'] # we will set template path for sql scripts self.template_path = 'trigger/sql/9.1_plus' # Store server type self.server_type = self.manager.server_type # We need parent's name eg table name and schema name # when we create new trigger in update we can fetch it using # property sql SQL = render_template("/".join([self.template_path, 'get_parent.sql']), tid=kwargs['tid']) status, rset = self.conn.execute_2darray(SQL) if not status: return internal_server_error(errormsg=rset) for row in rset['rows']: self.schema = row['schema'] self.table = row['table'] # Here we are storing trigger definition # We will use it to check trigger type definition self.trigger_definition = { 'TRIGGER_TYPE_ROW': (1 << 0), 'TRIGGER_TYPE_BEFORE': (1 << 1), 'TRIGGER_TYPE_INSERT': (1 << 2), 'TRIGGER_TYPE_DELETE': (1 << 3), 'TRIGGER_TYPE_UPDATE': (1 << 4), 'TRIGGER_TYPE_TRUNCATE': (1 << 5), 'TRIGGER_TYPE_INSTEAD': (1 << 6) } return f(*args, **kwargs)
def children(self, **kwargs): """Build a list of treeview nodes from the child nodes.""" if 'sid' not in kwargs: return precondition_required( gettext('Required properties are missing!') ) from pgadmin.utils.driver import get_driver manager = get_driver(PG_DEFAULT_DRIVER).connection_manager( sid=kwargs['sid'] ) did = None if 'did' in kwargs: did = kwargs['did'] conn = manager.connection(did=did) if not conn.connected(): return precondition_required( gettext( "Connection has been lost with the server!" ) ) nodes = [] for module in self.blueprint.submodules: if isinstance(module, PGChildModule): if manager is not None and \ module.BackendSupported(manager, **kwargs): nodes.extend(module.get_nodes(**kwargs)) else: nodes.extend(module.get_nodes(**kwargs)) return make_json_response(data=nodes)
def wrap(*args, **kwargs): # Here args[0] will hold self & kwargs will hold gid,sid,did self = args[0] self.manager = get_driver(PG_DEFAULT_DRIVER).connection_manager( kwargs['sid']) self.conn = self.manager.connection(did=kwargs['did']) # If DB not connected then return error to browser if not self.conn.connected(): return precondition_required( _("Connection to the server has been lost!")) # we will set template path for sql scripts depending upon server version ver = self.manager.version if ver >= 90100: self.template_path = 'fts_configuration/sql/9.1_plus' return f(*args, **kwargs)
def wrap(*args, **kwargs): # Here args[0] will hold self & kwargs will hold gid,sid,did self = args[0] self.manager = get_driver(PG_DEFAULT_DRIVER).connection_manager( kwargs['sid']) self.conn = self.manager.connection(did=kwargs['did']) # If DB not connected then return error to browser if not self.conn.connected(): return precondition_required( gettext("Connection to the server has been lost!")) self.template_path = 'catalog_object/sql/{0}/9.1_plus'.format( 'ppas' if self.manager.server_type == 'ppas' else 'pg') return f(*args, **kwargs)
def wrap(**kwargs): # Here args[0] will hold self & kwargs will hold gid,sid,did manager = get_driver(PG_DEFAULT_DRIVER).connection_manager( kwargs['sid'] ) conn = manager.connection(did=kwargs['did'] if 'did' in kwargs and kwargs['did'] != 0 else None) # If DB not connected then return error to browser if not conn.connected(): return precondition_required( gettext( "Connection to the server has been lost!" ) ) return f(obj, **kwargs)
def wrap(*args, **kwargs): # Here args[0] will hold self & kwargs will hold gid,sid,did self = args[0] self.manager = get_driver(PG_DEFAULT_DRIVER).connection_manager( kwargs['sid']) self.conn = self.manager.connection(did=kwargs['did']) # If DB not connected then return error to browser if not self.conn.connected(): return precondition_required( _("Connection to the server has been lost!") ) # we will set template path for sql scripts depending upon server version ver = self.manager.version if ver >= 90100: self.template_path = 'fts_configuration/sql/9.1_plus' return f(*args, **kwargs)
def wrap(*args, **kwargs): # Here args[0] will hold self & kwargs will hold gid,sid,did self = args[0] self.manager = get_driver(PG_DEFAULT_DRIVER).connection_manager( kwargs['sid']) self.conn = self.manager.connection(did=kwargs['did']) # If DB not connected then return error to browser if not self.conn.connected(): return precondition_required( gettext("Connection to the server has been lost!")) # we will set template path for sql scripts self.template_path = 'synonym/sql/#{0}#'.format( self.manager.version) return f(*args, **kwargs)
def wrapped(self, **kwargs): self.manager = get_driver( PG_DEFAULT_DRIVER ).connection_manager( kwargs['sid'] ) self.conn = self.manager.connection() driver = get_driver(PG_DEFAULT_DRIVER) self.qtIdent = driver.qtIdent if not self.conn.connected(): return precondition_required( _("Connection to the server has been lost.") ) self.datlastsysoid = \ self.manager.db_info[self.manager.did]['datlastsysoid'] \ if self.manager.db_info is not None and \ self.manager.did in self.manager.db_info else 0 self.sql_path = 'roles/sql/#{0}#'.format(self.manager.version) self.alterKeys = [ 'rolcanlogin', 'rolsuper', 'rolcreatedb', 'rolcreaterole', 'rolinherit', 'rolreplication', 'rolconnlimit', 'rolvaliduntil', 'rolpassword' ] if self.manager.version >= 90200 else [ 'rolcanlogin', 'rolsuper', 'rolcreatedb', 'rolcreaterole', 'rolinherit', 'rolconnlimit', 'rolvaliduntil', 'rolpassword' ] fetch_name, check_permission, \ forbidden_msg = RoleView._check_action(action, kwargs) is_permission_error = self._check_permission(check_permission, action, kwargs) if is_permission_error: return forbidden(forbidden_msg) is_error, errmsg = self._check_and_fetch_name(fetch_name, kwargs) if is_error: return errmsg return f(self, **kwargs)
def wrap(*args, **kwargs): # Here args[0] will hold self & kwargs will hold gid,sid,did self = args[0] self.driver = get_driver(PG_DEFAULT_DRIVER) self.manager = self.driver.connection_manager(kwargs['sid']) self.conn = self.manager.connection() # If DB not connected then return error to browser if not self.conn.connected(): return precondition_required( gettext( "Connection to the server has been lost!" ) ) self.template_path = 'resource_groups/sql' return f(*args, **kwargs)
def wrap(*args, **kwargs): # Here args[0] will hold self & kwargs will hold gid,sid,did self = args[0] self.driver = get_driver(PG_DEFAULT_DRIVER) self.manager = self.driver.connection_manager(kwargs['sid']) self.conn = self.manager.connection() # If DB not connected then return error to browser if not self.conn.connected(): return precondition_required( gettext( "Connection to the server has been lost." ) ) self.template_path = 'resource_groups/sql' return f(*args, **kwargs)
def wrap(*args, **kwargs): # Here args[0] will hold self & kwargs will hold gid,sid,did self = args[0] self.manager = get_driver(PG_DEFAULT_DRIVER).connection_manager( kwargs['sid']) self.conn = self.manager.connection(did=kwargs['did']) # If DB not connected then return error to browser if not self.conn.connected(): return precondition_required( gettext("Connection to the server has been lost!")) # We need datlastsysoid to check if current trigger is system trigger self.datlastsysoid = self.manager.db_info[ kwargs['did']]['datlastsysoid'] # we will set template path for sql scripts self.template_path = 'trigger/sql/9.1_plus' # Store server type self.server_type = self.manager.server_type # We need parent's name eg table name and schema name # when we create new trigger in update we can fetch it using # property sql SQL = render_template("/".join( [self.template_path, 'get_parent.sql']), tid=kwargs['tid']) status, rset = self.conn.execute_2darray(SQL) if not status: return internal_server_error(errormsg=rset) for row in rset['rows']: self.schema = row['schema'] self.table = row['table'] # Here we are storing trigger definition # We will use it to check trigger type definition self.trigger_definition = { 'TRIGGER_TYPE_ROW': (1 << 0), 'TRIGGER_TYPE_BEFORE': (1 << 1), 'TRIGGER_TYPE_INSERT': (1 << 2), 'TRIGGER_TYPE_DELETE': (1 << 3), 'TRIGGER_TYPE_UPDATE': (1 << 4), 'TRIGGER_TYPE_TRUNCATE': (1 << 5), 'TRIGGER_TYPE_INSTEAD': (1 << 6) } return f(*args, **kwargs)
def wrap(*args, **kwargs): # Here args[0] will hold self & kwargs will hold gid,sid,did self = args[0] self.manager = get_driver(PG_DEFAULT_DRIVER).connection_manager( kwargs['sid']) self.conn = self.manager.connection(did=kwargs['did']) # If DB not connected then return error to browser if not self.conn.connected(): return precondition_required( gettext("Connection to the server has been lost!")) ver = self.manager.version if ver >= 90300: self.template_path = 'event_triggers/sql/9.3_plus' return f(*args, **kwargs)
def wrapped(self, *args, **kwargs): self.manager = get_driver( PG_DEFAULT_DRIVER).connection_manager(kwargs['sid']) if action and action in ["drop"]: self.conn = self.manager.connection() elif 'did' in kwargs: self.conn = self.manager.connection(did=kwargs['did']) else: self.conn = self.manager.connection() # If DB not connected then return error to browser if not self.conn.connected(): return precondition_required( _("Connection to the server has been lost!")) self.template_path = 'sequence/sql/9.1_plus' return f(self, *args, **kwargs)
def wrap(*args, **kwargs): # Here args[0] will hold self & kwargs will hold gid,sid,did self = args[0] self.manager = get_driver(PG_DEFAULT_DRIVER).connection_manager( kwargs['sid']) self.conn = self.manager.connection(did=kwargs['did']) # If DB not connected then return error to browser if not self.conn.connected(): return precondition_required( gettext("Connection to the server has been lost!")) # Set template path for sql scripts self.template_path = self.template_initial + '/' + ( self.ppas_template_path(self.manager.version) if self.manager.server_type == 'ppas' else self.pg_template_path( self.manager.version)) return f(*args, **kwargs)
def wrap(*args, **kwargs): # Here args[0] will hold self & kwargs will hold gid,sid,did self = args[0] self.manager = get_driver( PG_DEFAULT_DRIVER).connection_manager(kwargs['sid']) self.conn = self.manager.connection(did=kwargs['did']) # If DB not connected then return error to browser if not self.conn.connected(): return precondition_required( gettext( "Connection to the server has been lost!" ) ) self.datlastsysoid = self.manager.db_info[kwargs['did']]['datlastsysoid'] self.template_path = 'rules/sql' return f(*args, **kwargs)
def wrap(*args, **kwargs): # Here args[0] will hold self & kwargs will hold gid,sid,did self = args[0] self.manager = get_driver(PG_DEFAULT_DRIVER).connection_manager( kwargs['sid'] ) self.conn = self.manager.connection(did=kwargs['did']) # If DB not connected then return error to browser if not self.conn.connected(): return precondition_required( gettext( "Connection to the server has been lost!" ) ) self.template_path = 'catalog_object_column/sql/9.1_plus' return f(*args, **kwargs)
def wrap(*args, **kwargs): # Here args[0] will hold self & kwargs will hold gid,sid,did g.manager = get_driver(PG_DEFAULT_DRIVER).connection_manager( kwargs['sid']) g.conn = g.manager.connection() # If DB not connected then return error to browser if not g.conn.connected(): return precondition_required( gettext("Connection to the server has been lost.")) # Set template path for sql scripts g.server_type = g.manager.server_type g.version = g.manager.version g.template_path = 'dashboard/sql/9.1_plus' return f(*args, **kwargs)
def wrap(*args, **kwargs): # Here args[0] will hold self & kwargs will hold gid,sid,did self = args[0] self.driver = get_driver(PG_DEFAULT_DRIVER) self.manager = self.driver.connection_manager(kwargs['sid']) self.conn = self.manager.connection() self.datlastsysoid = \ self.manager.db_info[self.manager.did]['datlastsysoid'] \ if self.manager.db_info is not None and \ self.manager.did in self.manager.db_info else 0 if not self.conn.connected(): return precondition_required( gettext("Connection to the server has been lost.")) self.sql_path = 'resource_groups/sql/#{0}#'.format( self.manager.version) return f(*args, **kwargs)
def wrap(*args, **kwargs): self = args[0] driver = get_driver(PG_DEFAULT_DRIVER) self.manager = driver.connection_manager(kwargs['sid']) # Get database connection self.conn = self.manager.connection(did=kwargs['did']) self.qtIdent = driver.qtIdent self.qtLiteral = driver.qtLiteral if not self.conn.connected(): return precondition_required( gettext("Connection to the server has been lost.")) self.sql_template_path = "/edbvar/ppas" return f(*args, **kwargs)
def wrap(*args, **kwargs): # Here args[0] will hold self & kwargs will hold gid,sid,tsid self = args[0] self.manager = get_driver( PG_DEFAULT_DRIVER ).connection_manager( kwargs['sid'] ) self.conn = self.manager.connection() self.datlastsysoid = \ self.manager.db_info[self.manager.did]['datlastsysoid'] \ if self.manager.db_info is not None and \ self.manager.did in self.manager.db_info else 0 self.datistemplate = False if ( self.manager.db_info is not None and self.manager.did in self.manager.db_info and 'datistemplate' in self.manager.db_info[self.manager.did] ): self.datistemplate = self.manager.db_info[ self.manager.did]['datistemplate'] # If DB not connected then return error to browser if not self.conn.connected(): current_app.logger.warning( "Connection to the server has been lost." ) return precondition_required( gettext( "Connection to the server has been lost." ) ) self.template_path = 'tablespaces/sql/#{0}#'.format( self.manager.version ) current_app.logger.debug( "Using the template path: %s", self.template_path ) # Allowed ACL on tablespace self.acl = ['C'] return f(*args, **kwargs)
def wrap(self, **kwargs): if request.data: data = json.loads(request.data, encoding='utf-8') else: data = dict() req = request.args or request.form for key in req: val = req[key] if key in [ 'rolcanlogin', 'rolsuper', 'rolcreatedb', 'rolcreaterole', 'rolinherit', 'rolreplication', 'rolcatupdate', 'variables', 'rolmembership', 'seclabels' ]: data[key] = json.loads(val, encoding='utf-8') else: data[key] = val invalid_msg = self._validate_rolname(kwargs.get('rid', -1), data) if invalid_msg is not None: return precondition_required(invalid_msg) invalid_msg = self._validate_rolvaliduntil(data) if invalid_msg is not None: return precondition_required(invalid_msg) invalid_msg = self._validate_rolconnlimit(data) if invalid_msg is not None: return precondition_required(invalid_msg) invalid_msg = self._validate_rolemembership( kwargs.get('rid', -1), data) if invalid_msg is not None: return precondition_required(invalid_msg) invalid_msg = self._validate_seclabels( kwargs.get('rid', -1), data) if invalid_msg is not None: return precondition_required(invalid_msg) invalid_msg = self._validate_variables( kwargs.get('rid', -1), data) if invalid_msg is not None: return precondition_required(invalid_msg) self.request = data return f(self, **kwargs)
def validate_binary_path(): """ This function is used to validate the specified utilities path by running the utilities with there versions. """ data = None if hasattr(request.data, 'decode'): data = request.data.decode('utf-8') if data != '': data = json.loads(data) version_str = '' if 'utility_path' in data and data['utility_path'] is not None: # Check if "$DIR" present in binary path binary_path = replace_binary_path(data['utility_path']) for utility in UTILITIES_ARRAY: full_path = os.path.abspath( os.path.join(binary_path, (utility if os.name != 'nt' else (utility + '.exe')))) try: # Get the output of the '--version' command version_string = \ subprocess.getoutput('"{0}" --version'.format(full_path)) # Get the version number by splitting the result string version_string.split(") ", 1)[1].split('.', 1)[0] except Exception: version_str += "<b>" + utility + ":</b> " + \ "not found on the specified binary path.<br/>" continue # Replace the name of the utility from the result to avoid # duplicate name. result_str = version_string.replace(utility, '') version_str += "<b>" + utility + ":</b> " + result_str + "<br/>" else: return precondition_required(gettext('Invalid binary path.')) return make_json_response(data=gettext(version_str), status=200)
def wrap(*args, **kwargs): # Here args[0] will hold self & kwargs will hold gid,sid,did self = args[0] self.manager = get_driver(PG_DEFAULT_DRIVER).connection_manager( kwargs['sid'] ) self.conn = self.manager.connection(did=kwargs['did']) # If DB not connected then return error to browser if not self.conn.connected(): return precondition_required( gettext( "Connection to the server has been lost." ) ) # we will set template path for sql scripts self.template_path = 'synonym/sql/#{0}#'.format( self.manager.version) return f(*args, **kwargs)
def wrapped(self, *args, **kwargs): self.manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(kwargs['sid']) if action and action in ["drop"]: self.conn = self.manager.connection() elif 'did' in kwargs: self.conn = self.manager.connection(did=kwargs['did']) else: self.conn = self.manager.connection() # If DB not connected then return error to browser if not self.conn.connected(): return precondition_required( _( "Connection to the server has been lost!" ) ) self.template_path = 'sequence/sql/9.1_plus' self.acl = ['r', 'w', 'U'] return f(self, *args, **kwargs)
def wrap(*args, **kwargs): self = args[0] driver = get_driver(PG_DEFAULT_DRIVER) self.manager = driver.connection_manager(kwargs['sid']) self.conn = self.manager.connection(did=kwargs['did']) self.qtIdent = driver.qtIdent # If DB not connected then return error to browser if not self.conn.connected(): return precondition_required( gettext("Connection to the server has been lost!")) ver = self.manager.version # we will set template path for sql scripts if ver >= 90200: self.template_path = 'domain_constraints/sql/9.2_plus' elif ver >= 90100: self.template_path = 'domain_constraints/sql/9.1_plus' return f(*args, **kwargs)
def wrap(*args, **kwargs): # Here args[0] will hold self & kwargs will hold gid,sid,did self = args[0] self.manager = get_driver(PG_DEFAULT_DRIVER).connection_manager( kwargs['sid'] ) self.conn = self.manager.connection(did=kwargs['did']) # If DB not connected then return error to browser if not self.conn.connected(): return precondition_required( gettext("Connection to the server has been lost!") ) # Set template path for sql scripts self.template_path = self.template_initial + '/' + ( self.ppas_template_path(self.manager.version) if self.manager.server_type == 'ppas' else self.pg_template_path(self.manager.version) ) return f(*args, **kwargs)
def wrap(*args, **kwargs): # Here args[0] will hold self & kwargs will hold gid,sid,did g.manager = get_driver( PG_DEFAULT_DRIVER).connection_manager( kwargs['sid'] ) g.conn = g.manager.connection() # If DB not connected then return error to browser if not g.conn.connected(): return precondition_required( gettext("Connection to the server has been lost.") ) # Set template path for sql scripts g.server_type = g.manager.server_type g.version = g.manager.version g.template_path = 'dashboard/sql/9.1_plus' return f(*args, **kwargs)
def wrap(*args, **kwargs): self = args[0] driver = get_driver(PG_DEFAULT_DRIVER) self.manager = driver.connection_manager(kwargs['sid']) # Get database connection self.conn = self.manager.connection(did=kwargs['did']) self.qtIdent = driver.qtIdent self.qtLiteral = driver.qtLiteral if not self.conn.connected(): return precondition_required( gettext( "Connection to the server has been lost." ) ) self.sql_template_path = "/edbvar/ppas" return f(*args, **kwargs)
def wrap(*args, **kwargs): # Here args[0] will hold self & kwargs will hold gid,sid,did self = args[0] self.manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(kwargs['sid']) self.conn = self.manager.connection(did=kwargs['did']) # If DB not connected then return error to browser if not self.conn.connected(): return precondition_required( gettext( "Connection to the server has been lost!" ) ) ver = self.manager.version # we will set template path for sql scripts if ver >= 90300: self.template_path = 'foreign_data_wrappers/sql/9.3_plus' else: self.template_path = 'foreign_data_wrappers/sql/9.1_plus' return f(*args, **kwargs)
def wrap(*args, **kwargs): # Here args[0] will hold self & kwargs will hold gid,sid,tsid self = args[0] self.manager = get_driver(PG_DEFAULT_DRIVER).connection_manager( kwargs['sid']) self.conn = self.manager.connection() # If DB not connected then return error to browser if not self.conn.connected(): current_app.logger.warning( "Connection to the server has been lost!") return precondition_required( gettext("Connection to the server has been lost!")) self.template_path = 'tablespaces/sql/#{0}#'.format( self.manager.version) current_app.logger.debug("Using the template path: %s", self.template_path) # Allowed ACL on tablespace self.acl = ['C'] return f(*args, **kwargs)
def wrap(*args, **kwargs): # Here args[0] will hold self & kwargs will hold gid,sid,did server_info.clear() server_info['manager'] = get_driver( PG_DEFAULT_DRIVER).connection_manager(kwargs['sid']) server_info['conn'] = server_info['manager'].connection( did=kwargs['did']) # If DB not connected then return error to browser if not server_info['conn'].connected(): return precondition_required( gettext("Connection to the server has been lost!")) # Set template path for sql scripts server_info['server_type'] = server_info['manager'].server_type server_info['version'] = server_info['manager'].version if server_info['server_type'] == 'pg': server_info['template_path'] = 'grant_wizard/pg/9.1_plus' elif server_info['server_type'] == 'ppas': server_info['template_path'] = 'grant_wizard/ppas/9.1_plus' return f(*args, **kwargs)
def wrap(*args, **kwargs): self = args[0] driver = get_driver(PG_DEFAULT_DRIVER) self.manager = driver.connection_manager(kwargs['sid']) self.conn = self.manager.connection(did=kwargs['did']) self.qtIdent = driver.qtIdent # If DB not connected then return error to browser if not self.conn.connected(): return precondition_required( gettext("Connection to the server has been lost!") ) ver = self.manager.version # we will set template path for sql scripts if ver >= 90200: self.template_path = 'domain_constraints/sql/9.2_plus' elif ver >= 90100: self.template_path = 'domain_constraints/sql/9.1_plus' return f(*args, **kwargs)
def wrap(*args, **kwargs): self = args[0] driver = get_driver(PG_DEFAULT_DRIVER) self.manager = driver.connection_manager(kwargs['sid']) # Get database connection self.conn = self.manager.connection(did=kwargs['did']) self.qtIdent = driver.qtIdent self.qtLiteral = driver.qtLiteral if not self.conn.connected(): return precondition_required( gettext("Connection to the server has been lost!")) # Set template path for sql scripts depending # on the server version. self.sql_template_path = "/".join( [self.node_type, self.manager.server_type, '#{0}#']).format(self.manager.version) return f(*args, **kwargs)
def wrap(*args, **kwargs): # Here args[0] will hold self & kwargs will hold gid,sid,did self = args[0] self.manager = get_driver(PG_DEFAULT_DRIVER).connection_manager( kwargs['sid']) self.conn = self.manager.connection(did=kwargs['did']) # We need datlastsysoid to check if current type is system type self.datlastsysoid = self.manager.db_info[ kwargs['did']]['datlastsysoid'] # If DB not connected then return error to browser if not self.conn.connected(): return precondition_required( gettext("Connection to the server has been lost!")) # Declare allows acl on type self.acl = ['U'] # we will set template path for sql scripts self.template_path = 'type/sql/9.1_plus' return f(*args, **kwargs)
def wrap(*args, **kwargs): # Here args[0] will hold self & kwargs will hold gid,sid,did self = args[0] self.manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(kwargs['sid']) self.conn = self.manager.connection(did=kwargs['did']) # We need datlastsysoid to check if current type is system type self.datlastsysoid = self.manager.db_info[kwargs['did']]['datlastsysoid'] # If DB not connected then return error to browser if not self.conn.connected(): return precondition_required( gettext( "Connection to the server has been lost!" ) ) # Declare allows acl on type self.acl = ['U'] # we will set template path for sql scripts self.template_path = 'type/sql/9.1_plus' return f(*args, **kwargs)
def wrapped(self, *args, **kwargs): self.manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(kwargs['sid']) if action and action in ["drop"]: self.conn = self.manager.connection() elif 'did' in kwargs: self.conn = self.manager.connection(did=kwargs['did']) else: self.conn = self.manager.connection() # If DB not connected then return error to browser if not self.conn.connected(): return precondition_required( _("Connection to the server has been lost!") ) ver = self.manager.version # we will set template path for sql scripts if ver >= 90300: self.template_path = 'databases/sql/9.3_plus' elif ver >= 90200: self.template_path = 'databases/sql/9.2_plus' else: self.template_path = 'databases/sql/9.1_plus' return f(self, *args, **kwargs)
def wrapped(self, *args, **kwargs): self.manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(kwargs['sid']) if action and action in ["drop"]: self.conn = self.manager.connection() elif 'did' in kwargs: self.conn = self.manager.connection(did=kwargs['did']) else: self.conn = self.manager.connection() # If DB not connected then return error to browser if not self.conn.connected(): return precondition_required( _("Connection to the server has been lost!") ) ver = self.manager.version # we will set template path for sql scripts if ver >= 90300: self.template_path = 'databases/sql/9.3_plus' elif ver >= 90200: self.template_path = 'databases/sql/9.2_plus' else: self.template_path = 'databases/sql/9.1_plus' return f(self, *args, **kwargs)
def wrap(self, **kwargs): data = None if request.data: data = json.loads(request.data, encoding='utf-8') else: data = dict() req = request.args or request.form for key in req: val = req[key] if key in [ u'rolcanlogin', u'rolsuper', u'rolcreatedb', u'rolcreaterole', u'rolinherit', u'rolreplication', u'rolcatupdate', u'variables', u'rolmembership', u'seclabels' ]: data[key] = json.loads(val, encoding='utf-8') else: data[key] = val if u'rid' not in kwargs or kwargs['rid'] == -1: if u'rolname' not in data: return precondition_required(_("Name must be specified.")) if u'rolvaliduntil' in data: # Make date explicit so that it works with every # postgres database datestyle format try: if data[u'rolvaliduntil'] is not None and \ data[u'rolvaliduntil'] != '' and \ len(data[u'rolvaliduntil']) > 0: data[u'rolvaliduntil'] = dateutil_parser.parse( data[u'rolvaliduntil']).isoformat() except Exception: return precondition_required(_("Date format is invalid.")) if u'rolconnlimit' in data: if data[u'rolconnlimit'] is not None: data[u'rolconnlimit'] = int(data[u'rolconnlimit']) if type(data[u'rolconnlimit'] ) != int or data[u'rolconnlimit'] < -1: return precondition_required( _("Connection limit must be an integer value or equal to -1." )) if u'rolmembership' in data: if u'rid' not in kwargs or kwargs['rid'] == -1: msg = _(""" Role membership information must be passed as an array of JSON object in the following format: rolmembership:[{ role: [rolename], admin: True/False }, ... ]""") if type(data[u'rolmembership']) != list: return precondition_required(msg) data[u'members'] = [] data[u'admins'] = [] for r in data[u'rolmembership']: if type( r ) != dict or u'role' not in r or u'admin' not in r: return precondition_required(msg) else: if r[u'admin']: data[u'admins'].append(r[u'role']) else: data[u'members'].append(r[u'role']) else: msg = _(""" Role membership information must be passed a string representing an array of JSON object in the following format: rolmembership:{ 'added': [{ role: [rolename], admin: True/False }, ... ], 'deleted': [{ role: [rolename], admin: True/False }, ... ], 'updated': [{ role: [rolename], admin: True/False }, ... ] """) if type(data[u'rolmembership']) != dict: return precondition_required(msg) data[u'members'] = [] data[u'admins'] = [] data[u'revoked_admins'] = [] data[u'revoked'] = [] if u'added' in data[u'rolmembership']: roles = (data[u'rolmembership'])[u'added'] if type(roles) != list: return precondition_required(msg) for r in roles: if (type(r) != dict or u'role' not in r or u'admin' not in r): return precondition_required(msg) if r[u'admin']: data[u'admins'].append(r[u'role']) else: data[u'members'].append(r[u'role']) if u'deleted' in data[u'rolmembership']: roles = (data[u'rolmembership'])[u'deleted'] if type(roles) != list: return precondition_required(msg) for r in roles: if type(r) != dict or u'role' not in r: return precondition_required(msg) data[u'revoked'].append(r[u'role']) if u'changed' in data[u'rolmembership']: roles = (data[u'rolmembership'])[u'changed'] if type(roles) != list: return precondition_required(msg) for r in roles: if (type(r) != dict or u'role' not in r or u'admin' not in r): return precondition_required(msg) if not r[u'admin']: data[u'revoked_admins'].append(r[u'role']) else: data[u'admins'].append(r[u'role']) if self.manager.version >= 90200: if u'seclabels' in data: if u'rid' not in kwargs or kwargs['rid'] == -1: msg = _(""" Security Label must be passed as an array of JSON object in the following format: seclabels:[{ provider: <provider>, label: <label> }, ... ]""") if type(data[u'seclabels']) != list: return precondition_required(msg) for s in data[u'seclabels']: if (type(s) != dict or u'provider' not in s or u'label' not in s): return precondition_required(msg) else: msg = _(""" Security Label must be passed as an array of JSON object in the following format: seclabels:{ 'added': [{ provider: <provider>, label: <label> }, ... ], 'deleted': [{ provider: <provider>, label: <label> }, ... ], 'updated': [{ provider: <provider>, label: <label> }, ... ] """) seclabels = data[u'seclabels'] if type(seclabels) != dict: return precondition_required(msg) if u'added' in seclabels: new_seclabels = seclabels[u'added'] if type(new_seclabels) != list: return precondition_required(msg) for s in new_seclabels: if (type(s) != dict or u'provider' not in s or u'label' not in s): return precondition_required(msg) if u'deleted' in seclabels: removed_seclabels = seclabels[u'deleted'] if type(removed_seclabels) != list: return precondition_required(msg) for s in removed_seclabels: if (type(s) != dict or u'provider' not in s): return precondition_required(msg) if u'changed' in seclabels: changed_seclabels = seclabels[u'deleted'] if type(changed_seclabels) != list: return precondition_required(msg) for s in changed_seclabels: if (type(s) != dict or u'provider' not in s and u'label' not in s): return precondition_required(msg) if u'variables' in data: if u'rid' not in kwargs or kwargs['rid'] == -1: msg = _(""" Configuration parameters/variables must be passed as an array of JSON object in the following format (create mode): variables:[{ database: <database> or null, name: <configuration>, value: <value> }, ... ]""") if type(data[u'variables']) != list: return precondition_required(msg) for r in data[u'variables']: if (type(r) != dict or u'name' not in r or u'value' not in r): return precondition_required(msg) else: msg = _(""" Configuration parameters/variables must be passed as an array of JSON object in the following format (update mode): rolmembership:{ 'added': [{ database: <database> or null, name: <configuration>, value: <value> }, ... ], 'deleted': [{ database: <database> or null, name: <configuration>, value: <value> }, ... ], 'updated': [{ database: <database> or null, name: <configuration>, value: <value> }, ... ] """) variables = data[u'variables'] if type(variables) != dict: return precondition_required(msg) if u'added' in variables: new_vars = variables[u'added'] if type(new_vars) != list: return precondition_required(msg) for v in new_vars: if (type(v) != dict or u'name' not in v or u'value' not in v): return precondition_required(msg) if u'deleted' in variables: delete_vars = variables[u'deleted'] if type(delete_vars) != list: return precondition_required(msg) for v in delete_vars: if type(v) != dict or u'name' not in v: return precondition_required(msg) if u'changed' in variables: new_vars = variables[u'changed'] if type(new_vars) != list: return precondition_required(msg) for v in new_vars: if (type(v) != dict or u'name' not in v or u'value' not in v): return precondition_required(msg) self.request = data return f(self, **kwargs)
def wrap(*args, **kwargs): # Here args[0] will hold self & kwargs will hold gid,sid,did g.manager = get_driver( PG_DEFAULT_DRIVER).connection_manager( kwargs['sid'] ) stats_type = ('activity', 'prepared', 'locks', 'config') # Below check handle the case where existing server is deleted # by user and python server will raise exception if this check # is not introduce. if g.manager is None: if f.__name__ in stats_type: return precondition_required( gettext("Please connect to the selected server" " to view the table.") ) else: return precondition_required( gettext("Please connect to the selected server" " to view the graph.") ) g.conn = g.manager.connection() # If DB not connected then return error to browser if not g.conn.connected(): if f.__name__ in stats_type: return precondition_required( gettext("Please connect to the selected server" " to view the table.") ) else: return precondition_required( gettext("Please connect to the selected server" " to view the graph.") ) if 'did' in kwargs: db_conn = g.manager.connection(did=kwargs['did']) # If the selected DB not connected then return error to browser if not db_conn.connected(): if f.__name__ in stats_type: return precondition_required( gettext("Please connect to the selected database" " to view the table.") ) else: return precondition_required( gettext("Please connect to the selected database to" " view the graph.") ) # Set template path for sql scripts g.server_type = g.manager.server_type g.version = g.manager.version # Include server_type in template_path when server_type is gpdb g.template_path = 'dashboard/sql/' + ( '#{0}#{1}#'.format(g.server_type, g.version) if g.server_type == 'gpdb' else '#{0}#'.format(g.version) ) return f(*args, **kwargs)
def wrapped(self, **kwargs): self.manager = get_driver( PG_DEFAULT_DRIVER ).connection_manager( kwargs['sid'] ) self.conn = self.manager.connection() driver = get_driver(PG_DEFAULT_DRIVER) self.qtIdent = driver.qtIdent if not self.conn.connected(): return precondition_required( _("Connection to the server has been lost!") ) ver = self.manager.version self.sql_path = 'role/sql/{0}/'.format( 'post9_4' if ver >= 90500 else \ 'post9_1' if ver >= 90200 else \ 'post9_0' if ver >= 90100 else \ 'post8_4' ) self.alterKeys = [ u'rolcanlogin', u'rolsuper', u'rolcreatedb', u'rolcreaterole', u'rolinherit', u'rolreplication', u'rolconnlimit', u'rolvaliduntil', u'rolpassword' ] if ver >= 90200 else [ u'rolcanlogin', u'rolsuper', u'rolcreatedb', u'rolcreaterole', u'rolinherit', u'rolconnlimit', u'rolvaliduntil', u'rolpassword' ] check_permission = False fetch_name = False forbidden_msg = None if action in ['drop', 'update']: check_permission = True fetch_name = True if action == 'drop': forbidden_msg = _( "The current user does not have permission to drop the role." ) else: forbidden_msg = _( "The current user does not have permission to update the role." ) elif action == 'create': check_permission = True forbidden_msg = _( "The current user does not have permission to create the role." ) elif (action == 'msql' and 'rid' in kwargs and kwargs['rid'] != -1): fetch_name = True if check_permission: user = self.manager.user_info if not user['is_superuser'] and \ not user['can_create_role']: if (action != 'update' or 'rid' in kwargs and kwargs['rid'] != -1 and user['id'] != kwargs['rid']): return forbidden(forbidden_msg) if fetch_name: status, res = self.conn.execute_dict( render_template( self.sql_path + 'permission.sql', rid=kwargs['rid'], conn=self.conn ) ) if not status: return internal_server_error( _( "Error retrieving the role information.\n{0}" ).format(res) ) if len(res['rows']) == 0: return gone( _("Couldn't find the role on the database server.") ) row = res['rows'][0] self.role = row['rolname'] self.rolCanLogin = row['rolcanlogin'] self.rolCatUpdate = row['rolcatupdate'] self.rolSuper = row['rolsuper'] return f(self, **kwargs)
def wrapped(self, **kwargs): self.manager = get_driver( PG_DEFAULT_DRIVER).connection_manager(kwargs['sid']) self.conn = self.manager.connection() driver = get_driver(PG_DEFAULT_DRIVER) self.qtIdent = driver.qtIdent if not self.conn.connected(): return precondition_required( _("Connection to the server has been lost!")) ver = self.manager.version self.sql_path = 'role/sql/{0}/'.format( 'post9_4' if ver >= 90500 else \ 'post9_1' if ver >= 90200 else \ 'post9_0' if ver >= 90100 else \ 'post8_4' ) self.alterKeys = [ u'rolcanlogin', u'rolsuper', u'rolcreatedb', u'rolcreaterole', u'rolinherit', u'rolreplication', u'rolconnlimit', u'rolvaliduntil', u'rolpassword' ] if ver >= 90200 else [ u'rolcanlogin', u'rolsuper', u'rolcreatedb', u'rolcreaterole', u'rolinherit', u'rolconnlimit', u'rolvaliduntil', u'rolpassword' ] check_permission = False fetch_name = False forbidden_msg = None if action in ['drop', 'update']: check_permission = True fetch_name = True if action == 'drop': forbidden_msg = _( "The current user does not have permission to drop the role." ) else: forbidden_msg = _( "The current user does not have permission to update the role." ) elif action == 'create': check_permission = True forbidden_msg = _( "The current user does not have permission to create the role." ) elif (action == 'msql' and 'rid' in kwargs and kwargs['rid'] != -1): fetch_name = True if check_permission: user = self.manager.user_info if not user['is_superuser'] and \ not user['can_create_role']: if (action != 'update' or 'rid' in kwargs and kwargs['rid'] != -1 and user['id'] != kwargs['rid']): return forbidden(forbidden_msg) if fetch_name: status, res = self.conn.execute_dict( render_template(self.sql_path + 'permission.sql', rid=kwargs['rid'], conn=self.conn)) if not status: return internal_server_error( _("Error retrieving the role information.\n{0}"). format(res)) if len(res['rows']) == 0: return gone( _("Could not find the role on the database server." )) row = res['rows'][0] self.role = row['rolname'] self.rolCanLogin = row['rolcanlogin'] self.rolCatUpdate = row['rolcatupdate'] self.rolSuper = row['rolsuper'] return f(self, **kwargs)
def wrap(self, **kwargs): data = None if request.data: data = json.loads(request.data) else: data = dict() req = request.args or request.form for key in req: val = req[key] if key in [ u'rolcanlogin', u'rolsuper', u'rolcreatedb', u'rolcreaterole', u'rolinherit', u'rolreplication', u'rolcatupdate', u'variables', u'rolmembership', u'seclabels' ]: data[key] = json.loads(val) else: data[key] = val if u'rid' not in kwargs or kwargs['rid'] == -1: if u'rolname' not in data: return precondition_required( _("Name must be specified.") ) if u'rolvaliduntil' in data: # Make date explicit so that it works with every # postgres database datestyle format try: if data[u'rolvaliduntil'] is not None and \ data[u'rolvaliduntil'] != '' and \ len(data[u'rolvaliduntil']) > 0: date = datetime.datetime.strptime( data[u'rolvaliduntil'], '%m/%d/%Y' ) data[u'rolvaliduntil'] = date.strftime("%d-%B-%Y") except Exception as e: return precondition_required( _("Date format is invalid.") ) if u'rolconnlimit' in data: if data[u'rolconnlimit'] is not None: data[u'rolconnlimit'] = int(data[u'rolconnlimit']) if type(data[u'rolconnlimit']) != int or data[u'rolconnlimit'] < -1: return precondition_required( _("Connection limit must be an integer value or equal to -1.") ) if u'rolmembership' in data: if u'rid' not in kwargs or kwargs['rid'] == -1: msg = _(""" Role membership information must be passed as an array of JSON object in the following format: rolmembership:[{ role: [rolename], admin: True/False }, ... ]""") if type(data[u'rolmembership']) != list: return precondition_required(msg) data[u'members'] = [] data[u'admins'] = [] for r in data[u'rolmembership']: if type(r) != dict or u'role' not in r or u'admin' not in r: return precondition_required(msg) else: if r[u'admin']: data[u'admins'].append(r[u'role']) else: data[u'members'].append(r[u'role']) else: msg = _(""" Role membership information must be passed a string representing an array of JSON object in the following format: rolmembership:{ 'added': [{ role: [rolename], admin: True/False }, ... ], 'deleted': [{ role: [rolename], admin: True/False }, ... ], 'updated': [{ role: [rolename], admin: True/False }, ... ] """) if type(data[u'rolmembership']) != dict: return precondition_required(msg) data[u'members'] = [] data[u'admins'] = [] data[u'revoked_admins'] = [] data[u'revoked'] = [] if u'added' in data[u'rolmembership']: roles = (data[u'rolmembership'])[u'added'] if type(roles) != list: return precondition_required(msg) for r in roles: if (type(r) != dict or u'role' not in r or u'admin' not in r): return precondition_required(msg) if r[u'admin']: data[u'admins'].append(r[u'role']) else: data[u'members'].append(r[u'role']) if u'deleted' in data[u'rolmembership']: roles = (data[u'rolmembership'])[u'deleted'] if type(roles) != list: return precondition_required(msg) for r in roles: if type(r) != dict or u'role' not in r: return precondition_required(msg) data[u'revoked'].append(r[u'role']) if u'changed' in data[u'rolmembership']: roles = (data[u'rolmembership'])[u'changed'] if type(roles) != list: return precondition_required(msg) for r in roles: if (type(r) != dict or u'role' not in r or u'admin' not in r): return precondition_required(msg) if not r[u'admin']: data[u'revoked_admins'].append(r[u'role']) else: data[u'admins'].append(r[u'role']) if self.manager.version >= 90200: if u'seclabels' in data: if u'rid' not in kwargs or kwargs['rid'] == -1: msg = _(""" Security Label must be passed as an array of JSON object in the following format: seclabels:[{ provider: <provider>, label: <label> }, ... ]""") if type(data[u'seclabels']) != list: return precondition_required(msg) for s in data[u'seclabels']: if (type(s) != dict or u'provider' not in s or u'label' not in s): return precondition_required(msg) else: msg = _(""" Security Label must be passed as an array of JSON object in the following format: seclabels:{ 'added': [{ provider: <provider>, label: <label> }, ... ], 'deleted': [{ provider: <provider>, label: <label> }, ... ], 'updated': [{ provider: <provider>, label: <label> }, ... ] """) seclabels = data[u'seclabels'] if type(seclabels) != dict: return precondition_required(msg) if u'added' in seclabels: new_seclabels = seclabels[u'added'] if type(new_seclabels) != list: return precondition_required(msg) for s in new_seclabels: if (type(s) != dict or u'provider' not in s or u'label' not in s): return precondition_required(msg) if u'deleted' in seclabels: removed_seclabels = seclabels[u'deleted'] if type(removed_seclabels) != list: return precondition_required(msg) for s in removed_seclabels: if (type(s) != dict or u'provider' not in s): return precondition_required(msg) if u'changed' in seclabels: changed_seclabels = seclabels[u'deleted'] if type(changed_seclabels) != list: return precondition_required(msg) for s in changed_seclabels: if (type(s) != dict or u'provider' not in s and u'label' not in s): return precondition_required(msg) if u'variables' in data: if u'rid' not in kwargs or kwargs['rid'] == -1: msg = _(""" Configuration parameters/variables must be passed as an array of JSON object in the following format (create mode): variables:[{ database: <database> or null, name: <configuration>, value: <value> }, ... ]""") if type(data[u'variables']) != list: return precondition_required(msg) for r in data[u'variables']: if (type(r) != dict or u'name' not in r or u'value' not in r): return precondition_required(msg) else: msg = _(""" Configuration parameters/variables must be passed as an array of JSON object in the following format (update mode): rolmembership:{ 'added': [{ database: <database> or null, name: <configuration>, value: <value> }, ... ], 'deleted': [{ database: <database> or null, name: <configuration>, value: <value> }, ... ], 'updated': [{ database: <database> or null, name: <configuration>, value: <value> }, ... ] """) variables = data[u'variables'] if type(variables) != dict: return precondition_required(msg) if u'added' in variables: new_vars = variables[u'added'] if type(new_vars) != list: return precondition_required(msg) for v in new_vars: if (type(v) != dict or u'name' not in v or u'value' not in v): return precondition_required(msg) if u'deleted' in variables: delete_vars = variables[u'deleted'] if type(delete_vars) != list: return precondition_required(msg) for v in delete_vars: if type(v) != dict or u'name' not in v: return precondition_required(msg) if u'changed' in variables: new_vars = variables[u'changed'] if type(new_vars) != list: return precondition_required(msg) for v in new_vars: if (type(v) != dict or u'name' not in v or u'value' not in v): return precondition_required(msg) self.request = data return f(self, **kwargs)