Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query db for ssl status #84

Merged
merged 4 commits into from
Mar 12, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tap_postgres/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,8 @@ def main_impl():

post_db.include_schemas_in_destination_stream_name = (args.config.get('include_schemas_in_destination_stream_name') == 'true')

post_db.get_ssl_status(conn_config)

if args.discover:
do_discovery(conn_config)
elif args.properties:
Expand Down
18 changes: 17 additions & 1 deletion tap_postgres/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@
cursor_iter_size = 20000
include_schemas_in_destination_stream_name = False

def get_ssl_status(conn_config):
try:
matching_rows = []
with open_connection(conn_config) as conn:
with conn.cursor(cursor_factory=psycopg2.extras.DictCursor, name='stitch_cursor') as cur:
select_sql = "SELECT datname,usename, ssl, client_addr FROM pg_stat_ssl JOIN pg_stat_activity ON pg_stat_ssl.pid = pg_stat_activity.pid"
cur.execute(select_sql)
for row in cur:
KAllan357 marked this conversation as resolved.
Show resolved Hide resolved
if row[0] == conn_config['dbname'] and row[1] == conn_config['user']:
matching_rows.append(row)
if len(matching_rows) == 1:
LOGGER.info('User %s connected with SSL = %s', conn_config['user'], matching_rows[0][2])
else:
LOGGER.info('Failed to retrieve SSL status')
except:
LOGGER.info('Failed to retrieve SSL status')


def calculate_destination_stream_name(stream, md_map):
if include_schemas_in_destination_stream_name:
Expand Down Expand Up @@ -44,7 +61,6 @@ def open_connection(conn_config, logical_replication=False):
cfg['connection_factory'] = psycopg2.extras.LogicalReplicationConnection

conn = psycopg2.connect(**cfg)
LOGGER.info('Connected with sslmode = %s', conn.get_dsn_parameters().get('sslmode', 'unknown'))

return conn

Expand Down