mirror of https://github.com/zulip/zulip.git
db: Combine the `if "host" in pg_args` stanza with earlier clause.
The only way in which "host" could be set is in cases (1) or (2), when it was potentially read from Django's settings. In case (3), we already know we are on the same host as the PostgreSQL server. This unifies the two separated checks, which are actually the same check. Co-authored-by: Adam Birds <adam.birds@adbwebdesigns.co.uk>
This commit is contained in:
parent
67fc8e84ea
commit
75bf19c9d9
|
@ -108,10 +108,21 @@ try:
|
||||||
if settings.REMOTE_POSTGRES_PORT != "":
|
if settings.REMOTE_POSTGRES_PORT != "":
|
||||||
pg_args["port"] = settings.REMOTE_POSTGRES_PORT
|
pg_args["port"] = settings.REMOTE_POSTGRES_PORT
|
||||||
USING_PGROONGA = settings.USING_PGROONGA
|
USING_PGROONGA = settings.USING_PGROONGA
|
||||||
|
pg_args["password"] = ""
|
||||||
|
if settings.DATABASES["default"]["PASSWORD"] is not None:
|
||||||
|
pg_args["password"] = settings.DATABASES["default"]["PASSWORD"]
|
||||||
|
pg_args["user"] = settings.DATABASES["default"]["USER"]
|
||||||
|
pg_args["dbname"] = settings.DATABASES["default"]["NAME"]
|
||||||
|
if settings.REMOTE_POSTGRES_SSLMODE != "":
|
||||||
|
pg_args["sslmode"] = settings.REMOTE_POSTGRES_SSLMODE
|
||||||
|
else:
|
||||||
|
pg_args["sslmode"] = "verify-full"
|
||||||
|
pg_args["connect_timeout"] = "600"
|
||||||
except ImportError:
|
except ImportError:
|
||||||
# Case (3); we know that the PostgreSQL server is on this
|
# Case (3); we know that the PostgreSQL server is on this
|
||||||
# host.
|
# host.
|
||||||
USING_PGROONGA = False
|
USING_PGROONGA = False
|
||||||
|
pg_args["user"] = "zulip"
|
||||||
|
|
||||||
# Since we don't want a hard dependency on being able to access the
|
# Since we don't want a hard dependency on being able to access the
|
||||||
# Zulip settings (as we may not be running on a server that has that
|
# Zulip settings (as we may not be running on a server that has that
|
||||||
|
@ -125,20 +136,6 @@ config_file.read("/etc/zulip/zulip.conf")
|
||||||
if config_file.has_option("machine", "pgroonga"):
|
if config_file.has_option("machine", "pgroonga"):
|
||||||
USING_PGROONGA = True
|
USING_PGROONGA = True
|
||||||
|
|
||||||
if "host" in pg_args:
|
|
||||||
pg_args["password"] = ""
|
|
||||||
if settings.DATABASES["default"]["PASSWORD"] is not None:
|
|
||||||
pg_args["password"] = settings.DATABASES["default"]["PASSWORD"]
|
|
||||||
pg_args["user"] = settings.DATABASES["default"]["USER"]
|
|
||||||
pg_args["dbname"] = settings.DATABASES["default"]["NAME"]
|
|
||||||
if settings.REMOTE_POSTGRES_SSLMODE != "":
|
|
||||||
pg_args["sslmode"] = settings.REMOTE_POSTGRES_SSLMODE
|
|
||||||
else:
|
|
||||||
pg_args["sslmode"] = "verify-full"
|
|
||||||
pg_args["connect_timeout"] = "600"
|
|
||||||
else:
|
|
||||||
pg_args["user"] = "zulip"
|
|
||||||
|
|
||||||
conn = None
|
conn = None
|
||||||
|
|
||||||
retries = 1
|
retries = 1
|
||||||
|
|
Loading…
Reference in New Issue