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

Fixes CI issues #13

Merged
merged 4 commits into from
Jan 19, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:

integration-test:
name: Integration tests
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ build/
.coverage
__pycache__/
*.py[cod]

.idea/

4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ allow_redefinition = true
module = ["ops.*", "kubernetes.*", "flatten_json.*", "git.*"]
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = ["charms.*"]
gruyaume marked this conversation as resolved.
Show resolved Hide resolved
follow_imports = "silent"

[tool.pytest.ini_options]
minversion = "6.0"
log_cli_level = "INFO"
6 changes: 3 additions & 3 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def __init__(self, *args):
self.tls_certificates = TLSCertificatesProvidesV1(self, "certificates")
self.vault = Vault(
url=f"http://localhost:{self.VAULT_PORT}",
role_id=self._stored.role_id,
secret_id=self._stored.secret_id,
role_id=self._stored.role_id, # type: ignore[arg-type]
secret_id=self._stored.secret_id, # type: ignore[arg-type]
)
self._service_name = self._container_name = "vault"
self._container = self.unit.get_container(self._container_name)
Expand Down Expand Up @@ -225,7 +225,7 @@ def _on_generate_certificate_action(self, event: ActionEvent) -> None:
csr = generate_csr(
private_key=private_key,
subject=event.params["cn"],
sans=event.params["sans"],
sans=event.params["sans"], # type: ignore[arg-type]
)
certificate = self.vault.issue_certificate(certificate_signing_request=csr.decode())
event.set_results(
Expand Down
6 changes: 4 additions & 2 deletions src/vault.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(self, reason):
class Vault:
"""Class to interact with Vault through its API."""

def __init__(self, url: str, role_id: str = None, secret_id: str = None):
def __init__(self, url: str, role_id: Optional[str] = None, secret_id: Optional[str] = None):
self._client = hvac.Client(url=url)
if role_id and secret_id:
self.approle_login(role_id=role_id, secret_id=secret_id)
Expand Down Expand Up @@ -209,7 +209,9 @@ def generate_root_certificate(self, ttl: str = "87599h") -> str:
logger.info("Generated root CA")
return root_certificate["data"]["certificate"]

def enable_secrets_engine(self, ttl: str = None, max_ttl: str = None) -> None:
def enable_secrets_engine(
self, ttl: Optional[str] = None, max_ttl: Optional[str] = None
) -> None:
"""Enables Vault's secret engine if the backend is mounted.

Args:
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import pytest
import requests.exceptions # type: ignore[import]
import yaml
from juju.errors import JujuError # type: ignore[import]
from juju.errors import JujuError

from tests.integration.kubernetes import Kubernetes
from tests.integration.vault import Vault
Expand Down Expand Up @@ -90,6 +90,7 @@ async def deploy_charm(ops_test, charm: Path) -> None:
resources=resources,
application_name=APPLICATION_NAME,
trust=True,
series="focal",
)

async def post_deployment_tasks(self, namespace: str) -> str:
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/certificates.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def generate_csr(
private_key: bytes,
subject: str,
add_unique_id_to_subject_name: bool = True,
email_address: str = None,
country_name: str = None,
email_address: Optional[str] = None,
country_name: Optional[str] = None,
private_key_password: Optional[bytes] = None,
sans: Optional[List[str]] = None,
additional_critical_extensions: Optional[List] = None,
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ commands =
[testenv:integration]
description = Run integration tests
deps =
git+https://github.com/juju/python-libjuju.git
juju
pytest
git+https://github.com/charmed-kubernetes/pytest-operator.git
pytest-operator
-r{toxinidir}/requirements.txt
commands =
pytest --asyncio-mode=auto -v --tb native {[vars]integration_test_path} --log-cli-level=INFO -s {posargs} --destructive-mode