-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gui: add methods for reloading config files and clean up secret manag…
…ers.
- Loading branch information
Showing
7 changed files
with
144 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
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,35 +1,40 @@ | ||
import re | ||
from functools import lru_cache | ||
from typing import Iterator, List | ||
from typing import Any, Iterator, List, Literal, Union | ||
from typing_extensions import TypedDict, Required | ||
|
||
from .envvar import EnvVar | ||
from ...localenv import LocalEnv | ||
from ..serve import app | ||
|
||
from . import local_secrets | ||
from . import ufcloud_secrets | ||
|
||
|
||
@lru_cache | ||
def _get_secrets_manager(localenv): | ||
url, _ = localenv.project.localConfig.config.search_includes( | ||
pathPrefix=app.config["UNFURL_CLOUD_SERVER"] | ||
) | ||
class EnvVar(TypedDict, total=False): | ||
# see https://docs.gitlab.com/ee/api/project_level_variables.html | ||
id: Union[int, str] # ID or URL-encoded path of the project | ||
key: Required[str] | ||
masked: Required[bool] | ||
environment_scope: Required[str] | ||
value: Any | ||
secret_value: Any # ??? not sent by api | ||
_destroy: bool | ||
variable_type: Required[Union[Literal["env_var"], Literal["file"]]] | ||
raw: Literal[False] # if true value isn't expanded | ||
protected: Literal[False] | ||
|
||
gitlab_api_match = re.search( | ||
r"/api/v4/projects/(?P<project_id>(\w|%2F|[/\-_])+)/variables\?[^&]*&private_token=(?P<private_token>[^&]+)", | ||
str(url), | ||
) | ||
|
||
if gitlab_api_match: | ||
@lru_cache | ||
def _get_secrets_manager(localenv: LocalEnv): | ||
url, project_id = ufcloud_secrets.find_gitlab_endpoint(localenv) | ||
if project_id: | ||
return ufcloud_secrets | ||
else: | ||
return local_secrets | ||
return local_secrets | ||
|
||
|
||
def set_variables(localenv, env_vars: List[EnvVar]) -> LocalEnv: | ||
def set_variables(localenv: LocalEnv, env_vars: List[EnvVar]): | ||
return _get_secrets_manager(localenv).set_variables(localenv, env_vars) | ||
|
||
|
||
def yield_variables(localenv) -> Iterator[EnvVar]: | ||
def yield_variables(localenv: LocalEnv) -> Iterator[EnvVar]: | ||
return _get_secrets_manager(localenv).yield_variables(localenv) |
This file was deleted.
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
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