Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore fixes #64

Merged
merged 6 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ juju add-model dev
# Enable DEBUG logging
juju model-config logging-config="<root>=INFO;unit=DEBUG"
# Deploy the charm
juju deploy ./kratos-external-idp-integrator_ubuntu-22.04-amd64.charm \
--resource httpbin-image=kennethreitz/httpbin \
juju deploy ./kratos-external-idp-integrator_ubuntu-22.04-amd64.charm
```

## Canonical Contributor Agreement
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ Note that depending on the type of the provider different configurations may be

After deploying, configuring and relating the integrator charm, its status will change to active. Now you can get the redirect_uri by running:
```commandline
juju run-action {unit_name} get-redirect-uri --wait
juju run {unit_name} get-redirect-uri --wait
```

### Disable the provider

To disable provider, i.e remove it from Kratos, run:
```commandline
juju run-action {unit_name} disable --wait
juju run {unit_name} disable --wait
```

### Enable the provider

To enable a provider that has been disabled, you need to run:
```commandline
juju run-action {unit_name} enable --wait
juju run {unit_name} enable --wait
```

## Contributing
Expand Down
8 changes: 4 additions & 4 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ options:
The backend to use for passing sensitive information to Kratos.
type: string
microsoft_tenant_id:
description: The Microsoft tenant_id. To be used only with microsoft providers.
description: The Microsoft tenant_id. To be used only with Microsoft providers.
type: string
apple_team_id:
description: The Team ID provided by Apple. To be used only with apple providers.
description: The Team ID provided by Apple. To be used only with Apple providers.
type: string
apple_private_key_id:
description: The private key identifier generated by Apple. To be used only with apple providers.
description: The private key identifier generated by Apple. To be used only with Apple providers.
type: string
apple_private_key:
description: The private key downloaded from Apple. To be used only with apple providers.
description: The private key downloaded from Apple. To be used only with Apple providers.
type: string
jsonnet_mapper:
description: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"""# Interface library for Kratos external OIDC providers.

This library wraps relation endpoints using the `kratos-external-idp` interface
and provides a Python API for both requesting Kratos to register the the client credentials for
communicating with an external provider.
and provides a Python API for both requesting Kratos to register the client credentials
and for communicating with an external provider.

## Getting Started

Expand All @@ -27,9 +27,6 @@
limit: 1
```

Next add the `jsonschema` python package to your charm's `requirements.txt`, so that the
library can validate the incoming relation databags.

Then, to initialise the library:

```python
Expand Down Expand Up @@ -131,6 +128,8 @@ def _on_client_config_changed(self, event):
# to 0 if you are raising the major API version
LIBPATCH = 7

PYDEPS = ["jsonschema"]

DEFAULT_RELATION_NAME = "kratos-external-idp"
logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -633,9 +632,11 @@ def config(self) -> Dict:
"client_secret": self.client_secret,
"issuer_url": self.issuer_url,
"scope": self.scope.split(" "),
"mapper_url": base64.b64encode(self.jsonnet_mapper.encode()).decode()
if self.jsonnet_mapper
else None,
"mapper_url": (
base64.b64encode(self.jsonnet_mapper.encode()).decode()
if self.jsonnet_mapper
else None
),
"microsoft_tenant": self.tenant_id,
"apple_team_id": self.team_id,
"apple_private_key_id": self.private_key_id,
Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
ops >= 1.2.0
jsonschema
ops >= 2.12.0
16 changes: 12 additions & 4 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,18 @@
ExternalIdpProvider,
InvalidConfigError,
)
from ops.charm import ActionEvent, CharmBase, ConfigChangedEvent, EventBase
from ops.framework import StoredState
from ops.main import main
from ops.model import ActiveStatus, BlockedStatus, MaintenanceStatus, WaitingStatus
from ops import (
ActionEvent,
ActiveStatus,
BlockedStatus,
CharmBase,
ConfigChangedEvent,
EventBase,
MaintenanceStatus,
StoredState,
WaitingStatus,
main,
)

logger = logging.getLogger(__name__)

Expand Down
25 changes: 14 additions & 11 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import pytest
from ops.model import ActiveStatus, BlockedStatus, WaitingStatus
from ops.testing import Harness
from ops.testing import ActionFailed, Harness
from utils import parse_databag # type: ignore


Expand Down Expand Up @@ -121,7 +121,6 @@ def test_invalid_provider(harness: Harness, config: Dict) -> None:
config["provider"] = "error"
harness.update_config(config)
relation_id = harness.add_relation("kratos-external-idp", "kratos-app")
# harness.update_relation_data(relation_id, "kratos-app", relation_data)

unit_data = harness.get_relation_data(relation_id, harness.charm.unit)
app_data = harness.get_relation_data(relation_id, harness.charm.app)
Expand Down Expand Up @@ -236,21 +235,23 @@ def test_get_redirect_uri(
relation_id = harness.add_relation("kratos-external-idp", "kratos-app")
harness.update_relation_data(relation_id, "kratos-app", relation_data)

harness.charm._get_redirect_uri(mock_event)
action_output = harness.run_action(
"get-redirect-uri",
)

mock_event.set_results.assert_called_once()
assert isinstance(harness.charm.unit.status, ActiveStatus)
assert mock_event.set_results.mock_calls[0].args == ({"redirect-uri": redirect_uri},)
assert action_output.results == {"redirect-uri": redirect_uri}


def test_get_redirect_uri_without_relation(
harness: Harness, config: Dict, mock_event: MagicMock
) -> None:
harness.update_config(config)

harness.charm._get_redirect_uri(mock_event)
with pytest.raises(ActionFailed) as e:
harness.run_action("get-redirect-uri")

mock_event.fail.assert_called_once_with("No redirect_uri found")
assert e.value.message == "No redirect_uri found"


def test_get_redirect_uri_without_relation_data(
Expand All @@ -259,9 +260,10 @@ def test_get_redirect_uri_without_relation_data(
harness.update_config(config)
harness.add_relation("kratos-external-idp", "kratos-app")

harness.charm._get_redirect_uri(mock_event)
with pytest.raises(ActionFailed) as e:
harness.run_action("get-redirect-uri")

mock_event.fail.assert_called_once_with("No redirect_uri found")
assert e.value.message == "No redirect_uri found"


def test_get_redirect_uri_without_leadership(
Expand All @@ -274,9 +276,10 @@ def test_get_redirect_uri_without_leadership(
relation_id = harness.add_relation("kratos-external-idp", "kratos-app")
harness.update_relation_data(relation_id, "kratos-app", relation_data)

harness.charm._get_redirect_uri(mock_event)
with pytest.raises(ActionFailed) as e:
harness.run_action("get-redirect-uri")

mock_event.fail.assert_called_once_with("No redirect_uri found")
assert e.value.message == "No redirect_uri found"


def test_disable(
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ deps =
pytest
ipdb
coverage[toml]
-r{toxinidir}/requirements.txt
-r{toxinidir}/unit-requirements.txt
commands =
coverage run --source={[vars]src_path},{[vars]lib_path} \
-m pytest --ignore={[vars]tst_path}integration -v --tb native -s {posargs}
Expand Down
2 changes: 2 additions & 0 deletions unit-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
jsonschema
-r requirements.txt