Skip to content

Commit

Permalink
move temporary files to conf folde
Browse files Browse the repository at this point in the history
  • Loading branch information
zmraul committed Dec 11, 2024
1 parent 4349a7b commit b616601
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions lib/charms/opensearch/v0/opensearch_tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ def store_new_ca(self, secrets: Dict[str, Any]) -> bool: # noqa: C901
raise

with tempfile.NamedTemporaryFile(
mode="w+t", dir=self.charm.opensearch.paths.tmp
mode="w+t", dir=self.charm.opensearch.paths.conf
) as ca_tmp_file:
ca_tmp_file.write(secrets.get("ca-cert"))
ca_tmp_file.flush()
Expand Down Expand Up @@ -672,14 +672,14 @@ def store_new_tls_resources(self, cert_type: CertType, secrets: Dict[str, Any]):
pass

tmp_key = tempfile.NamedTemporaryFile(
mode="w+t", suffix=".pem", dir=self.charm.opensearch.paths.tmp
mode="w+t", suffix=".pem", dir=self.charm.opensearch.paths.conf
)
tmp_key.write(secrets.get("key"))
tmp_key.flush()
tmp_key.seek(0)

tmp_cert = tempfile.NamedTemporaryFile(
mode="w+t", suffix=".cert", dir=self.charm.opensearch.paths.tmp
mode="w+t", suffix=".cert", dir=self.charm.opensearch.paths.conf
)
tmp_cert.write(secrets.get("cert"))
tmp_cert.flush()
Expand Down Expand Up @@ -717,7 +717,7 @@ def all_tls_resources_stored(self, only_unit_resources: bool = False) -> bool:
return False

# to make sure the content is processed correctly by openssl, temporary store it in a file
tmp_ca_file = tempfile.NamedTemporaryFile(mode="w+t", dir=self.charm.opensearch.paths.tmp)
tmp_ca_file = tempfile.NamedTemporaryFile(mode="w+t", dir=self.charm.opensearch.paths.conf)
tmp_ca_file.write(current_ca)
tmp_ca_file.flush()
tmp_ca_file.seek(0)
Expand Down Expand Up @@ -822,12 +822,12 @@ def reload_tls_certificates(self):
# using the SSL API requires authentication with app-admin cert and key
admin_secret = self.charm.secrets.get_object(Scope.APP, CertType.APP_ADMIN.val)

tmp_cert = tempfile.NamedTemporaryFile(mode="w+t", dir=self.charm.opensearch.paths.tmp)
tmp_cert = tempfile.NamedTemporaryFile(mode="w+t", dir=self.charm.opensearch.paths.conf)
tmp_cert.write(admin_secret["cert"])
tmp_cert.flush()
tmp_cert.seek(0)

tmp_key = tempfile.NamedTemporaryFile(mode="w+t", dir=self.charm.opensearch.paths.tmp)
tmp_key = tempfile.NamedTemporaryFile(mode="w+t", dir=self.charm.opensearch.paths.conf)
tmp_key.write(admin_secret["key"])
tmp_key.flush()
tmp_key.seek(0)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_store_tls_resources(self, grp_getgrnam, pwd_getpwnam, os_chown):
"""Test the storing of TLS resources."""
self.charm.tls.certs_path = MagicMock()
self.charm.tls.jdk_path = MagicMock()
self.charm.opensearch.paths.tmp = "tests/unit/"
self.charm.opensearch.paths.conf = "tests/unit/"

with tempfile.TemporaryDirectory() as tmp_dir:
self.charm.tls.certs_path = tmp_dir
Expand Down

0 comments on commit b616601

Please sign in to comment.