-
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
1dd9f84
commit 93eade4
Showing
3 changed files
with
173 additions
and
102 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
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,172 @@ | ||
# SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import dataclasses | ||
from typing import Dict | ||
|
||
import yaml | ||
|
||
|
||
@dataclasses.dataclass | ||
class DockerConfig: | ||
registry: str = "k3d-myregistry.localhost:12345" | ||
externalRegistry: str = "docker.io" | ||
|
||
|
||
@dataclasses.dataclass | ||
class K8sPodSecurityContext: | ||
runAsUser: int = 1004370000 | ||
runAsGroup: int = 1004370000 | ||
fsGroup: int = 1004370000 | ||
runAsNonRoot: bool = True | ||
|
||
|
||
@dataclasses.dataclass | ||
class K8sClusterConfig: | ||
imagePullPolicy: str = "Always" | ||
podSecurityContext: K8sPodSecurityContext = K8sPodSecurityContext | ||
|
||
|
||
@dataclasses.dataclass | ||
class K8sPromtailConfig: | ||
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 | ||
@dataclasses.dataclass | ||
class K8sConfig: | ||
# 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 | ||
# Only required when no kubectl context is available | ||
apiURL: str | None = None | ||
token: str | None = None | ||
|
||
|
||
@dataclasses.dataclass | ||
class GeneralConfig: | ||
host: str = "localhost" | ||
port: int = 8000 | ||
scheme: str = "http" | ||
wildcardHost: bool = False | ||
|
||
|
||
@dataclasses.dataclass | ||
class ExtensionGuacamoleConfig: | ||
baseURI: str = "http://localhost:8080/guacamole" | ||
publicURI: str = "http://localhost:8080/guacamole" | ||
username: str = "guacadmin" | ||
password: str = "guacadmin" | ||
|
||
|
||
@dataclasses.dataclass | ||
class ExtensionJupyterConfig: | ||
publicURI: str = "http://localhost:8080/jupyter" | ||
|
||
|
||
@dataclasses.dataclass | ||
class ExtensionsConfig: | ||
guacamole: ExtensionGuacamoleConfig = ExtensionGuacamoleConfig | ||
jupyter: ExtensionJupyterConfig = ExtensionJupyterConfig | ||
|
||
|
||
@dataclasses.dataclass | ||
class AuthOauthClientConfig: | ||
id: str = "default" | ||
secret: str | None = None | ||
|
||
|
||
# Only required when using provider oauth | ||
@dataclasses.dataclass | ||
class AuthOathEndpointsConfig: | ||
wellknown: str = ( | ||
"http://localhost:8083/default/.well-known/openid-configuration" | ||
) | ||
tokenIssuance: str | None = None | ||
authorization: str | None = None | ||
|
||
|
||
@dataclasses.dataclass | ||
class AuthOauthConfig: | ||
# Only required when using provider oauth | ||
endpoints: AuthOathEndpointsConfig | None = None | ||
audience: str = "default" | ||
scopes: list[str] = dataclasses.field(default=lambda: ["openid"]) | ||
client: AuthOauthClientConfig = AuthOauthClientConfig | ||
redirectURI: str = "http://localhost:4200/oauth2/callback" | ||
|
||
|
||
@dataclasses.dataclass | ||
class AuthenticationConfig: | ||
provider: str = "oauth" # oauth | azure | ||
jwt: dict[str, str] = dataclasses.field( | ||
default_factory={"usernameClaim": "sub"} | ||
) # preferred_username | ||
oauth: AuthOauthConfig = AuthOauthConfig | ||
|
||
|
||
@dataclasses.dataclass | ||
class PipelineConfig: | ||
timeout: int = 60 | ||
|
||
|
||
@dataclasses.dataclass | ||
class DatabaseConfig: | ||
url: str = "postgresql://dev:dev@localhost:5432/dev" | ||
Check failure Code scanning / SonarCloud PostgreSQL database passwords should not be disclosed High
Make sure this PostgreSQL database password gets changed and removed from the code. See more on SonarCloud
|
||
|
||
|
||
@dataclasses.dataclass | ||
class InitialConfig: | ||
admin: str = "admin" | ||
|
||
|
||
@dataclasses.dataclass | ||
class LoggingConfig: | ||
level: str = "DEBUG" | ||
logPath: str = "logs/" | ||
|
||
|
||
@dataclasses.dataclass | ||
class RequestsConfig: | ||
timeout: int = 2 | ||
|
||
|
||
@dataclasses.dataclass | ||
class PrometheusConfig: | ||
url: str = "http://localhost:8080/prometheus/" | ||
|
||
|
||
@dataclasses.dataclass | ||
class AppConfig: | ||
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 | ||
|
||
|
||
def generate_yaml_from_config_template(): | ||
app_config = AppConfig() | ||
config_dict = app_config.__dict__ | ||
yaml_str = yaml.dump(config_dict, sort_keys=False) | ||
|
||
with open("config.yaml", "w", encoding="utf-8") as yaml_file: | ||
yaml_file.write(yaml_str) | ||
|
||
|
||
if __name__ == "__main__": | ||
generate_yaml_from_config_template() |
This file was deleted.
Oops, something went wrong.