Skip to content

Commit

Permalink
Merge pull request #23 from srntqn/feature/use-pydantic-base-setting-…
Browse files Browse the repository at this point in the history
…to-configure-application

Use pydantic BaseSettings to configure application
  • Loading branch information
srntqn authored Feb 9, 2022
2 parents 286922f + d5c94e7 commit 07376a6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 20 deletions.
2 changes: 1 addition & 1 deletion chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: v1
appVersion: "0.7.0"
appVersion: "0.8.0"
description: Harmony helm chart
name: harmony
version: 0.2.0
16 changes: 5 additions & 11 deletions harmony/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import logging
import sys

from os import getenv

from . import __version__, __module_name__
from .libs.k8s_cluster import KubernetesCluster
from .libs.serializers.project import Project
Expand All @@ -13,20 +11,16 @@
from .libs.k8s_deployment import K8sDeployment
from .libs.worker import read_projects_from_config, fetch_app_version_from_vcs, sync_versions_in_vcs_and_cluster

CONFIG = Config(**{'config_location': getenv('CONFIG_LOCATION'),
'verify_ssl': getenv('VERIFY_SSL'),
'k8s_api_server': getenv('K8S_API_SERVER_HOST'),
'k8s_api_key': getenv('K8S_API_KEY'),
'log_level': getenv('LOG_LEVEL')})

logging.basicConfig(stream=sys.stdout,
level=logging.getLevelName(CONFIG.log_level))

CONFIG = Config()
PROJECTS = read_projects_from_config(CONFIG.config_location)
CLUSTER = KubernetesCluster(CONFIG.verify_ssl,
CONFIG.k8s_api_server,
CONFIG.k8s_api_key)

logging.basicConfig(stream=sys.stdout,
level=logging.getLevelName(CONFIG.log_level))


cli = typer.Typer(name=__module_name__)


Expand Down
14 changes: 7 additions & 7 deletions harmony/libs/serializers/config.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from pydantic import BaseModel, HttpUrl
from pydantic import BaseSettings, Field, HttpUrl


class Config(BaseModel):
config_location: str
verify_ssl: bool
k8s_api_server: HttpUrl
k8s_api_key: str
log_level: str
class Config(BaseSettings):
config_location: str = Field (..., env = 'CONFIG_LOCATION')
verify_ssl: bool = Field (..., env = 'VERIFY_SSL')
k8s_api_server: HttpUrl = Field(..., env = 'K8S_API_SERVER_HOST')
k8s_api_key: str = Field(..., env = 'K8S_API_KEY')
log_level: str = Field(..., env = 'LOG_LEVEL')
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "harmony"
version = "0.7.0"
version = "0.8.0"
description = ""
authors = ["srntqn <[email protected]>"]

Expand Down

0 comments on commit 07376a6

Please sign in to comment.