-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'stream-217.add_profile' into 'master'
[STREAM-218] CLI command for creating profile See merge request getindata/streaming-labs/streaming-cli!23
- Loading branch information
Showing
10 changed files
with
190 additions
and
62 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 |
---|---|---|
|
@@ -6,4 +6,5 @@ build/ | |
streamingcli.egg-info/ | ||
tmp_project/ | ||
requirements.txt | ||
.env | ||
.env | ||
__pycache__ |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,3 +1,5 @@ | ||
from pathlib import Path | ||
|
||
INITIAL_PROJECT_REPO = "[email protected]:getindata/streaming-labs/flink-sandbox-python.git" | ||
PROJECT_LOCAL_CONFIG_FILE_NAME = ".streaming_config.yml" | ||
PROJECT_LOCAL_TEMPLATE_DIR_NAME = ".vvp" | ||
|
@@ -6,5 +8,6 @@ | |
PLATFORM_K8S_CONFIGMAP_KEY = "platform_config.json" | ||
PLATFORM_K8S_SECRET_NAME = "streaming-platform-secret" | ||
PLATFORM_DEFAULT_DEPLOYMENT_TARGET_NAME = "default" | ||
|
||
PROFILE_ENV_VARIABLE_NAME = "SCLI_PROFILE" | ||
SCLI_CONFIG_DIR_NAME = ".scli" | ||
DEFAULT_PROFILE_DIR = f"{str(Path.home())}/{SCLI_CONFIG_DIR_NAME}/profiles.yml" |
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
Empty file.
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,74 @@ | ||
from dataclasses import asdict, dataclass, field, replace | ||
from pathlib import Path | ||
from typing import Any, Dict, Optional, Type | ||
|
||
import click | ||
from marshmallow import Schema | ||
from marshmallow_dataclass import class_schema | ||
from streamingcli.Config import DEFAULT_PROFILE_DIR | ||
from yaml import SafeLoader, load, safe_dump | ||
|
||
|
||
@dataclass(repr=True) | ||
class ScliProfile: | ||
profile_name: str | ||
ververica_url: Optional[str] = field(default=None) | ||
ververica_namespace: Optional[str] = field(default=None) | ||
ververica_deployment_target: Optional[str] = field(default=None) | ||
ververica_api_token: Optional[str] = field(default=None) | ||
docker_registry_url: Optional[str] = field(default=None) | ||
|
||
@dataclass | ||
class ScliProfiles: | ||
profiles: Dict[str, ScliProfile] = field(default_factory=dict) | ||
|
||
|
||
class ProfileCommand: | ||
|
||
@staticmethod | ||
def create_profile(profile_name: str, | ||
ververica_url: str=None, | ||
ververica_namespace: str=None, | ||
ververica_deployment_target: str=None, | ||
ververica_api_token: str=None, | ||
docker_registry_url: str=None): | ||
scli_profile = ScliProfile( | ||
profile_name=profile_name, | ||
ververica_url=ververica_url, | ||
ververica_namespace=ververica_namespace, | ||
ververica_deployment_target=ververica_deployment_target, | ||
docker_registry_url=docker_registry_url, | ||
ververica_api_token=ververica_api_token | ||
) | ||
ProfileCommand.save_profile(scli_profile=scli_profile) | ||
click.echo(f"Scli profile {profile_name} saved") | ||
|
||
@staticmethod | ||
def save_profile(scli_profile: ScliProfile): | ||
profiles = ProfileCommand.load_profiles() | ||
profiles_dict = profiles.profiles | ||
profiles_dict[scli_profile.profile_name] = scli_profile | ||
content = safe_dump(asdict(replace(profiles, profiles = profiles_dict))) | ||
with open(DEFAULT_PROFILE_DIR, "w") as file: | ||
file.write(content) | ||
|
||
@staticmethod | ||
def get_profile(profile_name: str) -> Optional[ScliProfile]: | ||
profiles_dict = ProfileCommand.load_profiles().profiles | ||
return profiles_dict.get(profile_name) | ||
|
||
@staticmethod | ||
def load_profiles() -> ScliProfiles: | ||
profiles_path = Path(DEFAULT_PROFILE_DIR) | ||
|
||
if (profiles_path.is_file() is False): | ||
return ScliProfiles | ||
|
||
with open(profiles_path, "r") as file: | ||
content = file.read() | ||
return ProfileCommand.strict_load_yaml(content, ScliProfiles) | ||
|
||
@staticmethod | ||
def strict_load_yaml(yaml: str, loaded_type: Type[Any]): | ||
schema = class_schema(loaded_type) | ||
return schema().load(load(yaml, Loader=SafeLoader)) |
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