From 6a79054677982d79b4e904c8612c5eac30c3f394 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Fredrik=20Ki=C3=A6r?= <31612826+anders-kiaer@users.noreply.github.com> Date: Fri, 23 Jun 2023 13:49:39 +0200 Subject: [PATCH] Fix: Adjust to recent Radix changes (#670) --- webviz_config/_deployment/github_cli.py | 7 +++++++ webviz_config/_deployment/radix.py | 11 ++++++++--- webviz_config/_deployment/radix_cli.py | 16 ++++++++++------ webviz_config/_deployment/radix_configuration.py | 7 +++++++ 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/webviz_config/_deployment/github_cli.py b/webviz_config/_deployment/github_cli.py index b8142ce9..928d7718 100644 --- a/webviz_config/_deployment/github_cli.py +++ b/webviz_config/_deployment/github_cli.py @@ -56,6 +56,13 @@ def create_github_repository(github_slug: str, directory: Path) -> Path: cwd=directory, ) + subprocess.run( + ["gh", "repo", "clone", github_slug], + capture_output=True, + check=True, + cwd=directory, + ) + return directory / github_slug.split("/")[1] diff --git a/webviz_config/_deployment/radix.py b/webviz_config/_deployment/radix.py index ae14a72c..ead88025 100644 --- a/webviz_config/_deployment/radix.py +++ b/webviz_config/_deployment/radix.py @@ -165,6 +165,7 @@ def radix_initial_deployment(github_slug: str, build_directory: pathlib.Path) -> repository_url=repository_url, shared_secret=webhook_secret, context=radix_config["context"], + ad_group=radix_config["ad_group"], ) progress_bar.update() @@ -182,9 +183,13 @@ def radix_initial_deployment(github_slug: str, build_directory: pathlib.Path) -> progress_bar.update() progress_bar.write("✓ Adding Radix deploy key to GitHub repository.") - github_cli.add_deploy_key( - directory=cloned_path, title="Radix deploy key", key=public_key - ) + + # gh api currently fails - add manually: + # https://github.com/equinor/radix-cli/issues/48 + progress_bar.write(f"Add following deploy key: {public_key}") + # github_cli.add_deploy_key( + # directory=cloned_path, title="Radix deploy key", key=public_key + # ) progress_bar.update() # Wait for application to be reconciled diff --git a/webviz_config/_deployment/radix_cli.py b/webviz_config/_deployment/radix_cli.py index 3a7d2caa..ac50585d 100644 --- a/webviz_config/_deployment/radix_cli.py +++ b/webviz_config/_deployment/radix_cli.py @@ -71,6 +71,7 @@ def create_application( repository_url: str, shared_secret: str, context: str, + ad_group: str, ) -> str: result = subprocess.run( [ @@ -89,6 +90,8 @@ def create_application( shared_secret, "--context", context, + "--ad-groups", + ad_group, ], capture_output=True, check=True, @@ -96,12 +99,13 @@ def create_application( stderr = result.stderr.decode() if not stderr.startswith("ssh-rsa"): - error_message = stderr - if "registerApplicationBadRequest" in stderr: - error_message += ( - f"Is {repository_url} being used by another Radix application?" - ) - raise RuntimeError(error_message) + pass # https://github.com/equinor/radix-cli/issues/48 + # error_message = stderr + # if "registerApplicationBadRequest" in stderr: + # error_message += ( + # f"Is {repository_url} being used by another Radix application?" + # ) + # raise RuntimeError(error_message) return stderr diff --git a/webviz_config/_deployment/radix_configuration.py b/webviz_config/_deployment/radix_configuration.py index 24176be4..ff26e45b 100644 --- a/webviz_config/_deployment/radix_configuration.py +++ b/webviz_config/_deployment/radix_configuration.py @@ -15,6 +15,12 @@ def radix_configuration() -> Dict[str, str]: if radix_context == "playground": radix_subdomain = "playground." + radix_subdomain + interactive_terminal.terminal_title("Radix AD group") + radix_ad_group = interactive_terminal.user_input_from_stdin( + "WEBVIZ_RADIX_AD_GROUP", + "AD group object ID", + ) + interactive_terminal.terminal_title("Radix application name") radix_application_name = interactive_terminal.user_input_optional_reuse( "WEBVIZ_RADIX_APPLICATION", @@ -28,4 +34,5 @@ def radix_configuration() -> Dict[str, str]: "application_name": radix_application_name, "app_url": f"https://{radix_application_name}.app.{radix_subdomain}", "webhook_receiver_url": f"https://webhook.{radix_subdomain}/events/github", + "ad_group": radix_ad_group, }