Skip to content

Commit 60ee4ce

Browse files
committed
[FIX] tests
1 parent dda8b4b commit 60ee4ce

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
# Build images
5656
- run: ./hooks/build
5757
# Test
58-
- run: ./tests/test.py -v
58+
- run: python -m unittest tests.test -v
5959
# Push
6060
- name: push to docker hub
6161
if: github.repository == 'Tecnativa/docker-postgres-autoconf' && github.ref == 'refs/heads/master'

autoconf-entrypoint

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ WAN_DATABASES = json.loads(os.environ["WAN_DATABASES"])
3030
WAN_HBA_TPL = os.environ["WAN_HBA_TPL"]
3131
WAN_TLS = json.loads(os.environ["WAN_TLS"])
3232
WAN_USERS = json.loads(os.environ["WAN_USERS"])
33+
PGSSLCERT = os.environ.get("PGSSLCERT")
34+
PGSSLKEY = os.environ.get("PGSSLKEY")
35+
PGSSLROOTCERT = os.environ.get("PGSSLROOTCERT")
3336

3437
# Configuration file templates
3538
CONF_FOLDER = "/etc/postgres"
@@ -56,23 +59,29 @@ hba_conf = []
5659
ssl_conf = []
5760

5861

59-
def permissions_fix(filename):
62+
def permissions_fix(filename, client=False):
6063
"""Make :param:`filename` be owned by root user and postgres group."""
6164
shutil.chown(filename, "root", "postgres")
62-
os.chmod(filename, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP)
65+
if client:
66+
os.chmod(filename, stat.S_IRUSR | stat.S_IWUSR)
67+
else:
68+
os.chmod(filename, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP)
6369

6470

6571
# Configure TLS
66-
for key, filename in SUPPORTED_CERTS.items():
67-
full_path = os.path.join(CONF_FOLDER, filename)
72+
for key, filen in SUPPORTED_CERTS.items():
73+
full_path = os.path.join(CONF_FOLDER, filen)
6874
# Write PEM file if it came from env variable
69-
if not os.path.exists(full_path) and CERTS.get(filename):
75+
if not os.path.exists(full_path) and CERTS.get(filen):
7076
with open(full_path, "w") as cert_file:
71-
cert_file.write(CERTS[filename])
77+
cert_file.write(CERTS[filen])
7278
if os.path.exists(full_path):
7379
# Enable file in postgres configuration
7480
ssl_conf.append("{} = '{}'".format(key, full_path))
7581
permissions_fix(full_path)
82+
for filen in (PGSSLCERT, PGSSLKEY, PGSSLROOTCERT):
83+
if filen and os.path.exists(filen):
84+
permissions_fix(filen, client=True)
7685

7786
if ssl_conf:
7887
ssl_conf.append("ssl = on")

tests/test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ def setUpClass(cls):
2727
with local.cwd(local.cwd / ".."):
2828
print("Building image")
2929
local["./hooks/build"] & FG
30-
cls.image = "tecnativa/postgres-autoconf:{}".format(local.env["DOCKER_TAG"])
31-
cls.cert_files = {"client.ca.cert.pem", "server.cert.pem", "server.key.pem"}
30+
cls.image = f"tecnativa/postgres-autoconf:{local.env['DOCKER_TAG']}"
31+
cls.cert_files = ("client.ca.cert.pem", "server.cert.pem", "server.key.pem")
3232
return super().setUpClass()
3333

3434
def setUp(self):

0 commit comments

Comments
 (0)