Skip to content

Commit

Permalink
revert cert changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam-D-Lewis committed Jun 4, 2024
1 parent f4508cb commit e771897
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 33 deletions.
5 changes: 3 additions & 2 deletions src/_nebari/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
DEFAULT_GCP_NODE_GROUPS,
node_groups_to_dict,
)
from _nebari.stages.kubernetes_ingress import LetsEncryptCertificate
from _nebari.stages.kubernetes_ingress import CertificateEnum
from _nebari.stages.kubernetes_keycloak import AuthenticationEnum
from _nebari.stages.terraform_state import TerraformStateEnum
from _nebari.utils import get_latest_kubernetes_version, random_secure_string
Expand Down Expand Up @@ -194,7 +194,8 @@ def render_config(
config["theme"]["jupyterhub"]["hub_subtitle"] = WELCOME_HEADER_TEXT

if ssl_cert_email:
config["certificate"] = LetsEncryptCertificate(acme_email=ssl_cert_email)
config["certificate"] = {"type": CertificateEnum.letsencrypt.value}
config["certificate"]["acme_email"] = ssl_cert_email

# validate configuration and convert to model
from nebari.plugins import nebari_plugin_manager
Expand Down
4 changes: 2 additions & 2 deletions src/_nebari/keycloak.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import requests
import rich

from _nebari.stages.kubernetes_ingress import SelfSignedCertificate
from _nebari.stages.kubernetes_ingress import CertificateEnum
from nebari import schema

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -91,7 +91,7 @@ def get_keycloak_admin_from_config(config: schema.Main):
"KEYCLOAK_ADMIN_PASSWORD", config.security.keycloak.initial_root_password
)

should_verify_tls = not isinstance(config.certificate, SelfSignedCertificate)
should_verify_tls = config.certificate.type != CertificateEnum.selfsigned

try:
keycloak_admin = keycloak.KeycloakAdmin(
Expand Down
47 changes: 19 additions & 28 deletions src/_nebari/stages/kubernetes_ingress/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
from __future__ import annotations

import enum
import logging
import socket
import sys
import time
from typing import Any, Dict, List, Literal, Optional, Type, Union

from pydantic import Field
from typing import Any, Dict, List, Optional, Type

from _nebari import constants
from _nebari.provider.dns.cloudflare import update_record
Expand Down Expand Up @@ -115,31 +112,25 @@ def _attempt_dns_lookup(
sys.exit(1)


class SelfSignedCertificate(schema.Base):
type: Literal["self-signed"] = Field("self-signed", validate_default=True)


class LetsEncryptCertificate(schema.Base):
type: Literal["lets-encrypt"] = Field("lets-encrypt", validate_default=True)
acme_email: str
acme_server: str = "https://acme-v02.api.letsencrypt.org/directory"
@schema.yaml_object(schema.yaml)
class CertificateEnum(str, enum.Enum):
letsencrypt = "lets-encrypt"
selfsigned = "self-signed"
existing = "existing"
disabled = "disabled"

@classmethod
def to_yaml(cls, representer, node):
return representer.represent_str(node.value)

class ExistingCertificate(schema.Base):
type: Literal["existing"] = Field("existing", validate_default=True)
secret_name: str


class DisabledCertificate(schema.Base):
type: Literal["disabled"] = Field("disabled", validate_default=True)


Certificate = Union[
SelfSignedCertificate,
LetsEncryptCertificate,
ExistingCertificate,
DisabledCertificate,
]
class Certificate(schema.Base):
type: CertificateEnum = CertificateEnum.selfsigned
# existing
secret_name: Optional[str] = None
# lets-encrypt
acme_email: Optional[str] = None
acme_server: str = "https://acme-v02.api.letsencrypt.org/directory"


class DnsProvider(schema.Base):
Expand All @@ -153,7 +144,7 @@ class Ingress(schema.Base):

class InputSchema(schema.Base):
domain: Optional[str] = None
certificate: Certificate = SelfSignedCertificate()
certificate: Certificate = Certificate()
ingress: Ingress = Ingress()
dns: DnsProvider = DnsProvider()

Expand Down
2 changes: 1 addition & 1 deletion tests/tests_unit/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_nebari_init(tmp_path, namespace, auth_provider, ci_provider, ssl_cert_e
assert config.namespace == namespace
assert config.security.authentication.type.lower() == auth_provider
assert config.ci_cd.type == ci_provider
assert getattr(config.certificate, "acme_email", None) == ssl_cert_email
assert config.certificate.acme_email == ssl_cert_email


@pytest.mark.parametrize(
Expand Down

0 comments on commit e771897

Please sign in to comment.