Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

[+] allow .pgpass lookup for web UI #646

Merged
merged 3 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 1 addition & 4 deletions ENV_VARIABLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ NB! Some variables influence multiple components. Command line parameters overri
- **PW2_NO_HELPER_FUNCTIONS** Ignore metric definitions using helper functions (in form get_smth()) and don't also roll out any helpers automatically. Default: false
- **PW2_TRY_CREATE_LISTED_EXTS_IF_MISSING** Try creating the listed extensions (comma sep.) on first connect for all monitored DBs when missing. Main usage - pg_stat_statements. Default: ""


## Web UI

- **PW2_WEBHOST** Network interface to listen on. Default: 0.0.0.0
Expand All @@ -89,7 +88,7 @@ NB! Some variables influence multiple components. Command line parameters overri
- **PW2_PGPORT** Config DB port. Default: 5432
- **PW2_PGDATABASE** Config DB name. Default: pgwatch2
- **PW2_PGUSER** Config DB user. Default: pgwatch2
- **PW2_PGPASSWORD** Config DB password. Default: pgwatch2admin
- **PW2_PGPASSWORD** Config DB password. Default: -
- **PW2_PGSSL** Config DB SSL connection only. Default: False
- **PW2_IHOST** InfluxDB host. Default: localhost
- **PW2_IPORT** InfluxDB port. Default: 8086
Expand All @@ -103,7 +102,6 @@ NB! Some variables influence multiple components. Command line parameters overri
- **PW2_DATASTORE** Backend for metric storage - [influx|postgres|graphite]. Default: influx
- **PW2_PG_METRIC_STORE_CONN_STR** Postgres metric store connection string. Required when PW2_DATASTORE=postgres. Default: -


## Grafana

- **PW2_GRAFANANOANONYMOUS** Can be set to require login even for viewing dashboards. Default: -
Expand All @@ -112,7 +110,6 @@ NB! Some variables influence multiple components. Command line parameters overri
- **PW2_GRAFANASSL** Use SSL. Default: -
- **PW2_GRAFANA_BASEURL** For linking to Grafana "Query details" dashboard from "Stat_stmt. overview". Default: http://0.0.0.0:3000


## InfluxDB

None. NB! InfluxDB built into the pgwatch2 Docker image provides no security (setting up a custom user/password requires
Expand Down
8 changes: 6 additions & 2 deletions webpy/datadb.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ def setConnectionStringForMetrics(conn_string):

def setConnectionString(host, port, dbname, username, password, require_ssl=False, connect_timeout=10):
global connection_string
connection_string = 'host={} port={} dbname={} user={} password={} connect_timeout={} {}'.format(
host, port, dbname, username, password, connect_timeout, '' if not require_ssl else 'sslmode=require')
if password == '': # In case of empty password .pgpass lookup will be used
connection_string = 'host={} port={} dbname={} user={} connect_timeout={} {}'.format(
host, port, dbname, username, connect_timeout, '' if not require_ssl else 'sslmode=require')
else:
connection_string = 'host={} port={} dbname={} user={} password={} connect_timeout={} {}'.format(
host, port, dbname, username, password, connect_timeout, '' if not require_ssl else 'sslmode=require')


def getConnection(conn_str=None, autocommit=True):
Expand Down
2 changes: 1 addition & 1 deletion webpy/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def stats_summary(self, **params):
parser.add_argument('-U', '--user', help='Pgwatch2 Config DB username',
default=(os.getenv('PW2_PGUSER') or 'pgwatch2'))
parser.add_argument('--password', help='Pgwatch2 Config DB password',
default=(os.getenv('PW2_PGPASSWORD') or 'pgwatch2admin'))
default=(os.getenv('PW2_PGPASSWORD') or ''))
parser.add_argument('--pg-require-ssl', help='Pgwatch2 Config DB SSL connection only', action='store_true',
default=(str_to_bool_or_fail(os.getenv('PW2_PGSSL')) or False))

Expand Down