-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Convert config template to pydantic model
- Loading branch information
1 parent
ed6613c
commit dccc22e
Showing
37 changed files
with
341 additions
and
274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
|
||
.idea | ||
config/* | ||
!config/config_template.yaml | ||
.history | ||
**/__pycache__/ | ||
.vscode | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,18 @@ | ||
# SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
|
||
import logging | ||
|
||
import jsonschema | ||
import jsonschema.exceptions | ||
|
||
from . import exceptions, loader | ||
from . import generate, loader, models | ||
|
||
log = logging.getLogger(__name__) | ||
config = loader.load_yaml() | ||
|
||
if not loader.does_config_exist(): | ||
log.warning( | ||
"No configuration file found. Generating default configuration at backend/capellacollab/config/config.yaml" | ||
) | ||
generate.write_config() | ||
|
||
|
||
def validate_schema(): | ||
config_schema = loader.load_config_schema() | ||
try: | ||
jsonschema.validate(config, config_schema) | ||
except jsonschema.exceptions.ValidationError as error: | ||
raise exceptions.InvalidConfigurationError( | ||
f"{error.__class__.__name__}: {error.message}", | ||
) from None | ||
config_data = loader.load_yaml() | ||
config = models.AppConfig(**config_data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import os | ||
|
||
import yaml | ||
|
||
from . import models | ||
|
||
|
||
def write_config(): | ||
current_dir = os.path.dirname(os.path.realpath(__file__)) | ||
config_path = os.path.join(current_dir, "config.yaml") | ||
|
||
app_config = models.AppConfig() | ||
config_dict = app_config.model_dump() | ||
yaml_str = yaml.dump(config_dict, sort_keys=False) | ||
|
||
with open(config_path, "w", encoding="utf-8") as yaml_file: | ||
yaml_file.write(yaml_str) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
# SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import pydantic | ||
|
||
|
||
class DockerConfig(pydantic.BaseModel): | ||
registry: str = "k3d-myregistry.localhost:12345" | ||
externalRegistry: str = "docker.io" | ||
|
||
|
||
class K8sPodSecurityContext(pydantic.BaseModel): | ||
runAsUser: int = 1004370000 | ||
runAsGroup: int = 1004370000 | ||
fsGroup: int = 1004370000 | ||
runAsNonRoot: bool = True | ||
|
||
|
||
class K8sClusterConfig(pydantic.BaseModel): | ||
imagePullPolicy: str = "Always" | ||
podSecurityContext: K8sPodSecurityContext = K8sPodSecurityContext() | ||
|
||
|
||
class K8sPromtailConfig(pydantic.BaseModel): | ||
lokiEnabled: bool = True | ||
lokiUrl: str = "http://localhost:30001/loki/api/v1/push" | ||
lokiUsername: str = "localLokiUser" | ||
lokiPassword: str = "localLokiPassword" | ||
serverPort: int = 3101 | ||
|
||
|
||
# Only required when using operator k8s | ||
|
||
|
||
class K8sConfig(pydantic.BaseModel): | ||
# Only required, if you'd like to use a local k3d environment | ||
context: str = "k3d-collab-cluster" | ||
namespace: str = "collab-sessions" | ||
storageClassName: str = "local-path" | ||
storageAccessMode: str = "ReadWriteOnce" | ||
cluster: K8sClusterConfig = K8sClusterConfig() | ||
promtail: K8sPromtailConfig = K8sPromtailConfig() | ||
ingressClassName: str = "traefik" | ||
# Only required when no kubectl context is available | ||
# apiURL: str | None = None | ||
# token: str | None = None | ||
|
||
|
||
class GeneralConfig(pydantic.BaseModel): | ||
host: str = "localhost" | ||
port: int = 8000 | ||
scheme: str = "http" | ||
wildcardHost: bool = False | ||
|
||
|
||
class ExtensionGuacamoleConfig(pydantic.BaseModel): | ||
baseURI: str = "http://localhost:8080/guacamole" | ||
publicURI: str = "http://localhost:8080/guacamole" | ||
username: str = "guacadmin" | ||
password: str = "guacadmin" | ||
|
||
|
||
class ExtensionJupyterConfig(pydantic.BaseModel): | ||
publicURI: str = "http://localhost:8080/jupyter" | ||
|
||
|
||
class ExtensionsConfig(pydantic.BaseModel): | ||
guacamole: ExtensionGuacamoleConfig = ExtensionGuacamoleConfig() | ||
jupyter: ExtensionJupyterConfig = ExtensionJupyterConfig() | ||
|
||
|
||
class AuthOauthClientConfig(pydantic.BaseModel): | ||
id: str = "default" | ||
secret: str | None = None | ||
|
||
|
||
# Only required when using provider oauth | ||
|
||
|
||
class AuthOathEndpointsConfig(pydantic.BaseModel): | ||
wellKnown: str = ( | ||
"http://localhost:8083/default/.well-known/openid-configuration" | ||
) | ||
tokenIssuance: str | None = None | ||
authorization: str | None = None | ||
|
||
|
||
class AuthOauthConfig(pydantic.BaseModel): | ||
# Only required when using provider oauth | ||
endpoints: AuthOathEndpointsConfig = AuthOathEndpointsConfig() | ||
audience: str = "default" | ||
scopes: list[str] = ["openid"] | ||
client: AuthOauthClientConfig = AuthOauthClientConfig() | ||
redirectURI: str = "http://localhost:4200/oauth2/callback" | ||
|
||
|
||
class JWTConfig(pydantic.BaseModel): | ||
usernameClaim: str = "sub" # preferred_username | ||
|
||
|
||
class AzureClientConfig(pydantic.BaseModel): | ||
id: str = "tbd" | ||
secret: str = "tbd" | ||
|
||
|
||
class AzureConfig(pydantic.BaseModel): | ||
authorizationEndpoint: str = "tbd" | ||
audience: str = "tbd" | ||
client: AzureClientConfig = AzureClientConfig() | ||
redirectURI: str = "http://localhost:4200/oauth2/callback" | ||
|
||
|
||
class AuthenticationConfig(pydantic.BaseModel): | ||
provider: str = "oauth" # oauth | azure | ||
jwt: JWTConfig = JWTConfig() | ||
oauth: AuthOauthConfig = AuthOauthConfig() | ||
azure: AzureConfig = ( | ||
AzureConfig() | ||
) # Only required when using provider azure | ||
|
||
|
||
class PipelineConfig(pydantic.BaseModel): | ||
timeout: int = 60 | ||
|
||
|
||
class DatabaseConfig(pydantic.BaseModel): | ||
url: str = "postgresql://dev:dev@localhost:5432/dev" | ||
|
||
|
||
class InitialConfig(pydantic.BaseModel): | ||
admin: str = "admin" | ||
|
||
|
||
class LoggingConfig(pydantic.BaseModel): | ||
level: str = "DEBUG" | ||
logPath: str = "logs/" | ||
|
||
|
||
class RequestsConfig(pydantic.BaseModel): | ||
timeout: int = 2 | ||
|
||
|
||
class PrometheusConfig(pydantic.BaseModel): | ||
url: str = "http://localhost:8080/prometheus/" | ||
|
||
|
||
class AppConfig(pydantic.BaseModel): | ||
docker: DockerConfig = DockerConfig() | ||
k8s: K8sConfig = K8sConfig() | ||
general: GeneralConfig = GeneralConfig() | ||
extensions: ExtensionsConfig = ExtensionsConfig() | ||
authentication: AuthenticationConfig = AuthenticationConfig() | ||
pipelines: PipelineConfig = PipelineConfig() | ||
database: DatabaseConfig = DatabaseConfig() | ||
initial: InitialConfig = InitialConfig() | ||
logging: LoggingConfig = LoggingConfig() | ||
requests: RequestsConfig = RequestsConfig() | ||
prometheus: PrometheusConfig = PrometheusConfig() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.