text
stringlengths
0
828
except Exception as e:
logger.log_error(e)
continue
try:
parse_result = parser_func(
parent=parent_instance,
**parser_func_kwargs
)
parse_result.process_item(**process_item_func_kwargs)
logger.log_status(parse_result)
except Exception as e:
logger.log_error(e)
continue"
3806,"def parse_connection_string_psycopg2(connection_string):
""""""
parses psycopg2 consumable connection string
:param connection_string:
:return: return dictionary with connection string parts
""""""
conn_prepared = {}
conn_parsed = urlparse(connection_string)
if not conn_parsed.hostname:
_re_dbstr = re.compile(r'\bhost=(?P<host>[0-9a-zA-Z_.!@#$%^&*()~]+)|'
r'dbname=(?P<dbname>[0-9a-zA-Z_.!@#$%^&*()~]+)|'
r'port=(?P<port>[0-9a-zA-Z_.!@#$%^&*()~]+)|'
r'user=(?P<user>[0-9a-zA-Z_.!@#$%^&*()~]+)|'
r'password=(?P<password>[0-9a-zA-Z_.!@#$%^&*()~]+)\b', re.IGNORECASE)
for match in _re_dbstr.finditer(connection_string):
match_dict = match.groupdict()
if match_dict['host']:
conn_prepared['host'] = match_dict['host']
if match_dict['port']:
conn_prepared['port'] = match_dict['port']
if match_dict['dbname']:
conn_prepared['dbname'] = match_dict['dbname']
if match_dict['user']:
conn_prepared['user'] = match_dict['user']
if match_dict['password']:
conn_prepared['password'] = match_dict['password']
else:
conn_prepared = {
'host': conn_parsed.hostname,
'port': conn_parsed.port,
'dbname': conn_parsed.path,
'user': conn_parsed.username,
'password': conn_parsed.password
}
return conn_prepared"
3807,"def get_pgpm_db_version(cls, cur, schema_name='_pgpm'):
""""""
returns current version of pgpm schema
:return: tuple of major, minor and patch components of version
""""""
cls.set_search_path(cur, schema_name)
cur.execute(""SELECT _find_schema('{0}', '{1}')""
.format(schema_name, 'x'))
# TODO: make it work with the way it's written below. currently throws error as func returns record
# without column list
# cur.callproc('_find_schema', [schema_name, 'x'])
pgpm_v_ext = tuple(cur.fetchone()[0][1:-1].split(','))
return pgpm_v_ext[2], pgpm_v_ext[3], pgpm_v_ext[4]"
3808,"def create_db_schema(cls, cur, schema_name):
""""""
Create Postgres schema script and execute it on cursor
""""""
create_schema_script = ""CREATE SCHEMA {0} ;\n"".format(schema_name)
cur.execute(create_schema_script)"
3809,"def grant_usage_privileges(cls, cur, schema_name, roles):
""""""
Sets search path
""""""
cur.execute('GRANT USAGE ON SCHEMA {0} TO {1};'
'GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA {0} TO {1};'
.format(schema_name, roles))"
3810,"def grant_usage_install_privileges(cls, cur, schema_name, roles):
""""""
Sets search path
""""""
cur.execute('GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA {0} TO {1};'
'GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA {0} TO {1};'
'GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA {0} TO {1};'
.format(schema_name, roles))"
3811,"def grant_default_usage_install_privileges(cls, cur, schema_name, roles):
""""""
Sets search path
""""""
cur.execute('ALTER DEFAULT PRIVILEGES IN SCHEMA {0} '
'GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO {1};'
'ALTER DEFAULT PRIVILEGES IN SCHEMA {0} GRANT EXECUTE ON FUNCTIONS TO {1};'
'ALTER DEFAULT PRIVILEGES IN SCHEMA {0} '
'GRANT USAGE, SELECT ON SEQUENCES TO {1};'
.format(schema_name, roles))"
3812,"def revoke_all(cls, cur, schema_name, roles):
""""""
Revoke all privileges from schema, tables, sequences and functions for a specific role
""""""
cur.execute('REVOKE ALL ON SCHEMA {0} FROM {1};'