From b588e44cd23e8fb448ef263858d8111b1f258907 Mon Sep 17 00:00:00 2001 From: Tom Haddon Date: Tue, 17 Sep 2024 09:56:43 +0200 Subject: [PATCH] Change config options to use dashes rather than underscores for consistency with framework-added options (#71) * Change config options to use dashes rather than underscores for consistency with framework-added options * Fix tests * Update code to deal with new config items * dashes are converted to underscores for env variables --- charm/charmcraft.yaml | 4 ++-- charm/docs/tutorials/getting-started.md | 10 +++++----- charm/src/charm.py | 14 +++++++------- charm/tests/integration/test_charm.py | 4 ++-- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/charm/charmcraft.yaml b/charm/charmcraft.yaml index cbedf4a..047315a 100644 --- a/charm/charmcraft.yaml +++ b/charm/charmcraft.yaml @@ -42,12 +42,12 @@ requires: config: options: - git_repo: + git-repo: type: string description: > The repository URL where the DNS records are stored. The username has to be provided as in git+ssh://username@repository@branch, where the branch is optional. - git_ssh_key: + git-ssh-key: type: string description: The private key for SSH authentication. diff --git a/charm/docs/tutorials/getting-started.md b/charm/docs/tutorials/getting-started.md index cde53a4..2927475 100644 --- a/charm/docs/tutorials/getting-started.md +++ b/charm/docs/tutorials/getting-started.md @@ -37,17 +37,17 @@ httprequest-lego-provider-0 2/2 Running 0 9m36s Run [`juju status`](https://juju.is/docs/olm/juju-status) to see the current status of the deployment. In the Unit list, you can see that the charm is waiting: ```bash -httprequest-lego-provider/0* waiting idle 10.1.180.77 Config git_repo is required +httprequest-lego-provider/0* waiting idle 10.1.180.77 Config git-repo is required ``` This means the required configurations have not been set yet. ## Configure the Httprequest Lego Provider charm - Provide the configurations `git_repo` and `git_ssh_key` required by the charm: + Provide the configurations `git-repo` and `git-ssh-key` required by the charm: ```bash -juju config httprequest-lego-provider git_repo=git+ssh://username@host/repo@branch -juju config httprequest-lego-provider git_ssh_key=**REDACTED** +juju config httprequest-lego-provider git-repo=git+ssh://username@host/repo@branch +juju config httprequest-lego-provider git-ssh-key=**REDACTED** ``` You can see the message has changed: @@ -73,7 +73,7 @@ httprequest-lego-provider active 1 httprequest-lego-provider l In order to access the HTTP endpoints, you'll need configure a hostname and add it to Django's allow list and configure the path routes that will be accessible: ```bash juju config nginx-ingress-integrator service-hostname=lego.local -juju config httprequest-lego-provider django_allowed_hosts=localhost,127.0.0.1,lego.local +juju config httprequest-lego-provider django-allowed-hosts=localhost,127.0.0.1,lego.local juju config nginx-ingress-integrator path-routes="/admin,/present,/cleanup" ``` diff --git a/charm/src/charm.py b/charm/src/charm.py index d339744..50604f2 100755 --- a/charm/src/charm.py +++ b/charm/src/charm.py @@ -55,9 +55,9 @@ def _copy_files(self) -> None: """Copy files needed by git.""" if not self._container.can_connect(): return - if not self.config.get("git_repo") or not self.config.get("git_ssh_key"): + if not self.config.get("git-repo") or not self.config.get("git-ssh-key"): return - hostname = self.config.get("git_repo").split("@")[1].split("/")[0] + hostname = self.config.get("git-repo").split("@")[1].split("/")[0] process = self._container.exec(["ssh-keyscan", "-t", "rsa", hostname]) output, _ = process.wait_output() self._container.push( @@ -71,7 +71,7 @@ def _copy_files(self) -> None: ) self._container.push( RSA_PATH, - self.config.get("git_ssh_key"), + self.config.get("git-ssh-key"), encoding="utf-8", make_dirs=True, user=DJANGO_USER, @@ -81,11 +81,11 @@ def _copy_files(self) -> None: def _on_collect_app_status(self, _: ops.CollectStatusEvent) -> None: """Handle the status changes.""" - if not self.config.get("git_repo"): - self.unit.status = ops.WaitingStatus("Config git_repo is required") + if not self.config.get("git-repo"): + self.unit.status = ops.WaitingStatus("Config git-repo is required") return - if not self.config.get("git_ssh_key"): - self.unit.status = ops.WaitingStatus("Config git_ssh_key is required") + if not self.config.get("git-ssh-key"): + self.unit.status = ops.WaitingStatus("Config git-ssh-key is required") return diff --git a/charm/tests/integration/test_charm.py b/charm/tests/integration/test_charm.py index bfbad50..f3b2f34 100644 --- a/charm/tests/integration/test_charm.py +++ b/charm/tests/integration/test_charm.py @@ -28,8 +28,8 @@ async def test_build_and_deploy(ops_test: OpsTest, pytestconfig: pytest.Config): await ops_test.model.deploy( os.path.abspath(charm), config={ - "git_repo": "git+ssh://git@github.com/canonical/httprequest-lego-provider.git@main", - "git_ssh_key": textwrap.dedent( + "git-repo": "git+ssh://git@github.com/canonical/httprequest-lego-provider.git@main", + "git-ssh-key": textwrap.dedent( """\ -----BEGIN OPENSSH PRIVATE KEY----- b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW