|
1 | 1 | #!/usr/bin/env python3 |
2 | | -import os |
3 | | -import json |
4 | | -import sys |
5 | | -import netifaces |
6 | 2 | import ipaddress |
| 3 | +import json |
| 4 | +import os |
7 | 5 | import shutil |
8 | 6 | import stat |
9 | | - |
| 7 | +import sys |
10 | 8 | from itertools import product |
11 | 9 |
|
| 10 | +import netifaces |
| 11 | + |
12 | 12 | SUPPORTED_CERTS = { |
13 | 13 | "ssl_ca_file": "client.ca.cert.pem", |
14 | 14 | "ssl_cert_file": "server.cert.pem", |
@@ -85,53 +85,50 @@ for interface in netifaces.interfaces(): |
85 | 85 | try: |
86 | 86 | # Format interface IP and netmask in common CIDR notation |
87 | 87 | cidr = ipaddress.ip_network( |
88 | | - "{addr}/{netmask}".format(**address), |
89 | | - False, |
| 88 | + "{addr}/{netmask}".format(**address), False |
90 | 89 | ) |
91 | 90 | except ValueError: |
92 | 91 | continue |
93 | 92 | # Append line to pg_hba.conf, according to template |
94 | 93 | for user, db in product(LAN_USERS, LAN_DATABASES): |
95 | | - hba_conf.append(LAN_HBA_TPL.format( |
96 | | - connection=LAN_CONNECTION, |
97 | | - db=db, |
98 | | - user=user, |
99 | | - cidr=cidr, |
100 | | - meth=LAN_AUTH_METHOD, |
101 | | - )) |
| 94 | + hba_conf.append( |
| 95 | + LAN_HBA_TPL.format( |
| 96 | + connection=LAN_CONNECTION, |
| 97 | + db=db, |
| 98 | + user=user, |
| 99 | + cidr=cidr, |
| 100 | + meth=LAN_AUTH_METHOD, |
| 101 | + ) |
| 102 | + ) |
102 | 103 |
|
103 | 104 | # Generate WAN auth configuration |
104 | 105 | if WAN_CONNECTION != "hostssl" or ssl_conf: |
105 | 106 | for user, db, cidr in product(WAN_USERS, WAN_DATABASES, WAN_CIDRS): |
106 | | - hba_conf.append(WAN_HBA_TPL.format( |
107 | | - connection=WAN_CONNECTION, |
108 | | - db=db, |
109 | | - user=user, |
110 | | - cidr=cidr, |
111 | | - meth=WAN_AUTH_METHOD, |
112 | | - )) |
| 107 | + hba_conf.append( |
| 108 | + WAN_HBA_TPL.format( |
| 109 | + connection=WAN_CONNECTION, |
| 110 | + db=db, |
| 111 | + user=user, |
| 112 | + cidr=cidr, |
| 113 | + meth=WAN_AUTH_METHOD, |
| 114 | + ) |
| 115 | + ) |
113 | 116 |
|
114 | 117 | # Write postgres configuration files |
115 | 118 | with open(CONF_FILE, "w") as conf_file: |
116 | | - conf_file.write(CONF_TPL.format( |
117 | | - conf_folder=CONF_FOLDER, |
118 | | - ssl_conf="\n".join(ssl_conf), |
119 | | - extra_conf=CONF_EXTRA, |
120 | | - )) |
| 119 | + conf_file.write( |
| 120 | + CONF_TPL.format( |
| 121 | + conf_folder=CONF_FOLDER, ssl_conf="\n".join(ssl_conf), extra_conf=CONF_EXTRA |
| 122 | + ) |
| 123 | + ) |
121 | 124 | permissions_fix(CONF_FILE) |
122 | 125 | with open(HBA_FILE, "w") as conf_file: |
123 | | - conf_file.write(HBA_TPL.format( |
124 | | - extra_conf="\n".join(hba_conf), |
125 | | - )) |
| 126 | + conf_file.write(HBA_TPL.format(extra_conf="\n".join(hba_conf))) |
126 | 127 | permissions_fix(HBA_FILE) |
127 | 128 |
|
128 | 129 | # Continue normal execution |
129 | 130 | args = sys.argv[1:] |
130 | 131 | if not args or args[0] == "postgres" or args[0].startswith("-"): |
131 | 132 | # Need to go through parent image entrypoint, and hardcode conf file |
132 | | - args = [ |
133 | | - "/docker-entrypoint.sh", |
134 | | - *args, |
135 | | - "-cconfig_file={}".format(CONF_FILE), |
136 | | - ] |
| 133 | + args = ["/docker-entrypoint.sh", *args, "-cconfig_file={}".format(CONF_FILE)] |
137 | 134 | os.execvp(args[0], args) |
0 commit comments