Skip to content

Commit

Permalink
fix: do cloud provider cli check before provider initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
all4code authored Dec 18, 2023
1 parent 2f9f181 commit 376735d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
2 changes: 0 additions & 2 deletions tools/cli/commands/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,8 +875,6 @@ def prepare_parameters(p):

@trace()
def cloud_provider_check(manager: CloudProviderManager, p: StateStore) -> None:
if not manager.detect_cli_presence():
raise click.ClickException("Cloud CLI is missing")
if not manager.evaluate_permissions():
raise click.ClickException("Insufficient IAM permission")

Expand Down
12 changes: 10 additions & 2 deletions tools/cli/common/command_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,21 @@
def init_cloud_provider(state: StateStore) -> tuple[CloudProviderManager, DNSManager]:
cloud_manager: CloudProviderManager = None
domain_manager: DNSManager = None
# init proper cloud provider

# init proper cloud provider
if state.cloud_provider == CloudProviders.AWS:
# need to check CLI dependencies before initializing cloud providers as they depend on cli tools
if not AWSManager.detect_cli_presence():
raise click.ClickException("Cloud CLI is missing")

cloud_manager: AWSManager = AWSManager(state.get_input_param(CLOUD_REGION),
state.get_input_param(CLOUD_PROFILE),
state.get_input_param(CLOUD_ACCOUNT_ACCESS_KEY),
state.get_input_param(CLOUD_ACCOUNT_ACCESS_SECRET))

# check if cloud native DNS registrar is selected
if state.dns_registrar == DnsRegistrars.Route53:
# Note!: Route53 is initialised with AWS Cloud Provider
# Note!: Route53 is initialized with AWS Cloud Provider
if state.get_input_param(DNS_REGISTRAR_ACCESS_KEY) is None and state.get_input_param(
DNS_REGISTRAR_ACCESS_SECRET) is None:
# initialize with cloud account permissions
Expand All @@ -46,6 +50,10 @@ def init_cloud_provider(state: StateStore) -> tuple[CloudProviderManager, DNSMan
secret=state.get_input_param(DNS_REGISTRAR_ACCESS_SECRET))

elif state.cloud_provider == CloudProviders.Azure:
# need to check CLI dependencies before initializing cloud providers as they depend on cli tools
if not AzureManager.detect_cli_presence():
raise click.ClickException("Cloud CLI is missing")

cloud_manager: AzureManager = AzureManager(
state.get_input_param(CLOUD_PROFILE), state.get_input_param(CLOUD_REGION)
)
Expand Down
4 changes: 2 additions & 2 deletions tools/cli/services/cloud/aws/aws_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def __init__(self, region, profile, key, secret):
def region(self):
return self.__aws_sdk.region

@trace()
def detect_cli_presence(self) -> bool:
@classmethod
def detect_cli_presence(cls) -> bool:
"""Check whether `name` is on PATH and marked as executable."""
return detect_command_presence(CLI)

Expand Down
4 changes: 2 additions & 2 deletions tools/cli/services/cloud/azure/azure_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ def get_k8s_auth_command(self) -> tuple[str, [str]]:
def get_k8s_token(self, cluster_name: str) -> str:
raise NotImplementedError()

@trace()
def detect_cli_presence(self) -> bool:
@classmethod
def detect_cli_presence(cls) -> bool:
"""Check whether dependencies are on PATH and marked as executable."""
return detect_command_presence(CLI) & detect_command_presence(K8s)

Expand Down
3 changes: 2 additions & 1 deletion tools/cli/services/cloud/cloud_provider_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ class CloudProviderManager(ABC):
def region(self) -> str:
pass

@classmethod
@abstractmethod
def detect_cli_presence(self) -> bool:
def detect_cli_presence(cls) -> bool:
"""
Check if cloud provider CLI tools are installed
:return: True or False
Expand Down

0 comments on commit 376735d

Please sign in to comment.