Skip to content

Commit

Permalink
Change config options to use dashes rather than underscores for consi…
Browse files Browse the repository at this point in the history
…stency 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
  • Loading branch information
Tom Haddon authored Sep 17, 2024
1 parent f0b9f71 commit b588e44
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions charm/charmcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
10 changes: 5 additions & 5 deletions charm/docs/tutorials/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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"
```

14 changes: 7 additions & 7 deletions charm/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand All @@ -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


Expand Down
4 changes: 2 additions & 2 deletions charm/tests/integration/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b588e44

Please sign in to comment.