Skip to content

Commit

Permalink
fix: Change orm name to catalog
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajat Venkatesh authored and vrajat committed Jan 21, 2020
1 parent 11c32f6 commit 2ce1e98
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 53 deletions.
25 changes: 14 additions & 11 deletions piicatcher/command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,24 @@
@click.version_option(__version__)
@click_config_file.configuration_option()
@click.option("-l", "--log-level", help="Logging Level", default="WARNING")
@click.option("--orm-host", help="Hostname of the database. Use if output is a db")
@click.option("--orm-port", help="Port of database. Use if output is a db")
@click.option("--orm-user", help="Username to connect database. Use if output is a db")
@click.option("--orm-password", help="Password of the user. Use if output is a db")
def cli(ctx, log_level, orm_host, orm_port, orm_user, orm_password):
@click.option("--catalog-host", help="Hostname of the database. Use if output is a db")
@click.option("--catalog-port", help="Port of database. Use if output is a db")
@click.option("--catalog-user", help="Username to connect database. Use if output is a db")
@click.option("--catalog-password", help="Password of the user. Use if output is a db")
def cli(ctx, log_level, catalog_host, catalog_port, catalog_user, catalog_password):
logging.basicConfig(level=getattr(logging, log_level.upper()))
logging.debug("ORM - host: %s, port: %s, user: %s, password: %s" % (orm_host, orm_port, orm_user, orm_password))
logging.debug("Catalog - host: %s, port: %s, user: %s, password: %s" % (catalog_host,
catalog_port,
catalog_user,
catalog_password))

ctx.ensure_object(dict)

ctx.obj['orm'] = {
'host': orm_host,
'port': orm_port,
'user': orm_user,
'password': orm_password,
ctx.obj['catalog'] = {
'host': catalog_host,
'port': catalog_port,
'user': catalog_user,
'password': catalog_password,
}


Expand Down
2 changes: 1 addition & 1 deletion piicatcher/explorer/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def cli(cxt, access_key, secret_key, staging_dir, region, output_format, scan_ty
scan_type=scan_type,
output=output,
list_all=list_all,
orm=cxt.obj['orm'])
catalog=cxt.obj['catalog'])
logging.debug(vars(ns))
AthenaExplorer.dispatch(ns)

Expand Down
2 changes: 1 addition & 1 deletion piicatcher/explorer/databases.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def cli(cxt, host, port, user, password, database, connection_type, output_forma
scan_type=scan_type,
output=output,
list_all=list_all,
orm=cxt.obj['orm'])
catalog=cxt.obj['catalog'])

logging.debug(vars(ns))
RelDbExplorer.dispatch(ns)
Expand Down
2 changes: 1 addition & 1 deletion piicatcher/explorer/explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, ns):
self._connection = None
self._schemas = None
self._cache_ts = None
self.orm = ns.orm
self.catalog = ns.catalog

def __enter__(self):
return self
Expand Down
2 changes: 1 addition & 1 deletion piicatcher/explorer/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def cli(cxt, path, output_format, scan_type, output, list_all):
scan_type=scan_type,
output=output,
list_all=list_all,
orm=cxt.obj['orm'])
catalog=cxt.obj['catalog'])

SqliteExplorer.dispatch(ns)

Expand Down
14 changes: 7 additions & 7 deletions piicatcher/store/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,20 @@ def model_db_close():

class DbStore(Store):
@classmethod
def setup_database(cls, orm):
if orm is not None:
def setup_database(cls, catalog):
if catalog is not None:
database = MySQLDatabase('tokern',
host=orm['host'],
port=int(orm['port']),
user=orm['user'],
password=orm['password'])
host=catalog['host'],
port=int(catalog['port']),
user=catalog['user'],
password=catalog['password'])
database_proxy.initialize(database)
database_proxy.connect()
database_proxy.create_tables([DbSchemas, DbTables, DbColumns, DbFile])

@classmethod
def save_schemas(cls, explorer):
cls.setup_database(explorer.orm)
cls.setup_database(explorer.catalog)
with database_proxy.atomic():
schemas = explorer.get_schemas()
for s in schemas:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_awsexplorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_aws_dispath(self):
region='us-east-1',
scan_type=None,
output_format="ascii_table",
orm=None,
catalog=None,
list_all=False))
mock_scan_method.assert_called_once()
mock_tabular_method.assert_called_once()
Expand Down
24 changes: 12 additions & 12 deletions tests/test_command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def test_host(self, explorer):
port=None,
scan_type='shallow',
user=None,
orm={'host': None, 'port': None,
'user': None, 'password': None}))
catalog={'host': None, 'port': None,
'user': None, 'password': None}))

@patch('piicatcher.explorer.databases.RelDbExplorer')
def test_port(self, explorer):
Expand All @@ -49,8 +49,8 @@ def test_port(self, explorer):
port=6032,
scan_type='shallow',
user=None,
orm={'host': None, 'port': None,
'user': None, 'password': None}))
catalog={'host': None, 'port': None,
'user': None, 'password': None}))

@patch('piicatcher.explorer.databases.RelDbExplorer')
def test_host_user_password(self, explorer):
Expand All @@ -68,8 +68,8 @@ def test_host_user_password(self, explorer):
port=None,
scan_type='shallow',
user='user',
orm={'host': None, 'port': None,
'user': None, 'password': None}))
catalog={'host': None, 'port': None,
'user': None, 'password': None}))

@patch('piicatcher.explorer.databases.RelDbExplorer')
def test_deep_scan_type(self, explorer):
Expand All @@ -87,8 +87,8 @@ def test_deep_scan_type(self, explorer):
port=None,
scan_type='deep',
user=None,
orm={'host': None, 'port': None,
'user': None, 'password': None}))
catalog={'host': None, 'port': None,
'user': None, 'password': None}))

@patch('piicatcher.explorer.databases.RelDbExplorer')
def test_deep_scan_type(self, explorer):
Expand All @@ -106,8 +106,8 @@ def test_deep_scan_type(self, explorer):
port=None,
scan_type='shallow',
user=None,
orm={'host': None, 'port': None,
'user': None, 'password': None}))
catalog={'host': None, 'port': None,
'user': None, 'password': None}))


class TestSqliteParser(TestCase):
Expand All @@ -131,7 +131,7 @@ def test_host(self, explorer):
output_format='ascii_table',
path='connection_string',
scan_type='shallow',
orm={'host': None, 'port': None, 'user': None, 'password': None}))
catalog={'host': None, 'port': None, 'user': None, 'password': None}))


class TestAWSParser(TestCase):
Expand All @@ -151,5 +151,5 @@ def test_host_user_password(self, explorer):
scan_type='shallow',
secret_key='SSSS',
staging_dir='s3://dir',
orm={'host': None, 'port': None, 'user': None, 'password': None}))
catalog={'host': None, 'port': None, 'user': None, 'password': None}))

9 changes: 4 additions & 5 deletions tests/test_config_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ def test_db(tmp_path, mocker, caplog):
port=6032,
scan_type='deep',
user='user',
orm={'host': None, 'port': None,
'user': None, 'password': None})
catalog={'host': None, 'port': None, 'user': None, 'password': None})
rel.dispatch.assert_called_once_with(ns)


Expand Down Expand Up @@ -70,8 +69,8 @@ def test_sqlite(tmp_path, mocker, caplog):
output=None,
output_format='json',
scan_type='deep',
orm={'host': None, 'port': None,
'user': None, 'password': None}))
catalog={'host': None, 'port': None,
'user': None, 'password': None}))


def test_files(tmp_path, mocker, caplog):
Expand Down Expand Up @@ -126,5 +125,5 @@ def test_aws(tmp_path, mocker, caplog):
scan_type='deep',
secret_key='SSSS',
staging_dir='s3://dir',
orm={'host': None, 'port': None, 'user': None, 'password': None}))
catalog={'host': None, 'port': None, 'user': None, 'password': None}))

14 changes: 7 additions & 7 deletions tests/test_databases.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def setUp(self):
user="piiuser",
password="p11secret",
database="piidb",
orm=None
catalog=None
))

def tearDown(self):
Expand Down Expand Up @@ -183,7 +183,7 @@ def setUp(self):
user="piiuser",
password="p11secret",
database="piidb",
orm=None
catalog=None
))

def tearDown(self):
Expand Down Expand Up @@ -235,7 +235,7 @@ def setUp(self):
user="piiuser",
password="p11secret",
database="piidb",
orm=None
catalog=None
))

def tearDown(self):
Expand Down Expand Up @@ -287,7 +287,7 @@ def setUp(self):
user="piiuser",
password="p11secret",
database="piidb",
orm=None
catalog=None
))

def tearDown(self):
Expand Down Expand Up @@ -357,7 +357,7 @@ def test_mysql_dispatch(self):
output_format='ascii_table',
connection_type='mysql',
scan_type='deep',
orm=None,
catalog=None,
user='user',
password='pass'))
mock_scan_method.assert_called_once()
Expand All @@ -375,7 +375,7 @@ def test_postgres_dispatch(self):
connection_type='postgres',
database='public',
scan_type=None,
orm=None,
catalog=None,
user='user',
password='pass'))
mock_scan_method.assert_called_once()
Expand All @@ -391,7 +391,7 @@ def test_mysql_shallow_scan(self):
list_all=None,
output_format='ascii_table',
connection_type='mysql',
orm=None,
catalog=None,
user='user',
password='pass',
scan_type="shallow"))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def parser(cls, sub_parsers):

class ExplorerTest(TestCase):
def setUp(self):
self.explorer = MockExplorer(Namespace(host="mock_connection", orm=None))
self.explorer = MockExplorer(Namespace(host="mock_connection", catalog=None))

col1 = Column('c1')
col2 = Column('c2')
Expand Down
2 changes: 1 addition & 1 deletion tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class TestStore(TestCase):
def setUpClass(cls):
init_test(cls.sqlite_path)

explorer = MockExplorer(Namespace(orm=None))
explorer = MockExplorer(Namespace(catalog=None))

DbStore.save_schemas(explorer)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_sample_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def namespace(self):
user="piiuser",
password="p11secret",
database="piidb",
orm=None
catalog=None
)

@classmethod
Expand Down Expand Up @@ -128,7 +128,7 @@ def namespace(self):
user="piiuser",
password="p11secret",
database="piidb",
orm=None
catalog=None
)

@classmethod
Expand Down
4 changes: 2 additions & 2 deletions tests/test_sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def temp_sqlite(request, tmpdir_factory):
sqlite_path = temp_dir.join("sqldb")

explorer = SqliteExplorer(Namespace(
path=sqlite_path, orm=None))
path=sqlite_path, catalog=None))

request.cls.explorer = explorer
request.cls.path = str(sqlite_path)
Expand Down Expand Up @@ -67,7 +67,7 @@ def test_sqlite_dispatch(self):
with mock.patch('piicatcher.explorer.sqlite.SqliteExplorer.get_tabular', autospec=True) as mock_tabular_method:
with mock.patch('piicatcher.explorer.explorer.tableprint', autospec=True) as MockTablePrint:
SqliteExplorer.dispatch(Namespace(path='connection', list_all=None, output_format='ascii_table',
scan_type=None, orm=None))
scan_type=None, catalog=None))
mock_scan_method.assert_called_once()
mock_tabular_method.assert_called_once()
MockTablePrint.table.assert_called_once()

0 comments on commit 2ce1e98

Please sign in to comment.