Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK Migration #132

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/containerapp/azext_containerapp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@
from azure.cli.core import AzCommandsLoader

from azext_containerapp._help import helps # pylint: disable=unused-import

from azext_containerapp._client_factory import app_client_factory

class ContainerappCommandsLoader(AzCommandsLoader):

def __init__(self, cli_ctx=None):
from azure.cli.core.commands import CliCommandType
from azure.cli.core.profiles import ResourceType

containerapp_custom = CliCommandType(
operations_tmpl='azext_containerapp.custom#{}',
client_factory=None)
client_factory=app_client_factory)
super(ContainerappCommandsLoader, self).__init__(cli_ctx=cli_ctx,
custom_command_type=containerapp_custom)
custom_command_type=containerapp_custom,
resource_type=ResourceType.MGMT_APPCONTAINERS)

def load_command_table(self, args):
from azext_containerapp.commands import load_command_table
Expand All @@ -29,4 +32,4 @@ def load_arguments(self, command):
load_arguments(self, command)


COMMAND_LOADER_CLS = ContainerappCommandsLoader
COMMAND_LOADER_CLS = ContainerappCommandsLoader
41 changes: 39 additions & 2 deletions src/containerapp/azext_containerapp/_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def handle_raw_exception(e):
import json

stringErr = str(e)
if "response" in stringErr.lower():
stringErr = stringErr[stringErr.lower().rindex("response"):]

if "{" in stringErr and "}" in stringErr:
jsonError = stringErr[stringErr.index("{"):stringErr.rindex("}") + 1]
Expand Down Expand Up @@ -65,11 +67,46 @@ def cf_resource_groups(cli_ctx, subscription_id=None):

def log_analytics_client_factory(cli_ctx):
from azure.mgmt.loganalytics import LogAnalyticsManagementClient

return get_mgmt_service_client(cli_ctx, LogAnalyticsManagementClient).workspaces


def log_analytics_shared_key_client_factory(cli_ctx):
from azure.mgmt.loganalytics import LogAnalyticsManagementClient

return get_mgmt_service_client(cli_ctx, LogAnalyticsManagementClient).shared_keys


def app_client_factory(cli_ctx, *_):
from azure.mgmt.appcontainers import ContainerAppsAPIClient
from azure.cli.core.commands.client_factory import get_mgmt_service_client
return get_mgmt_service_client(cli_ctx, ContainerAppsAPIClient)


def cf_containerapps(cli_ctx, *_):
return app_client_factory(cli_ctx).container_apps


def cf_managedenvs(cli_ctx, *_):
return app_client_factory(cli_ctx).managed_environments


def cf_revisions(cli_ctx, *_):
return app_client_factory(cli_ctx).container_apps_revisions


def cf_replicas(cli_ctx, *_):
return app_client_factory(cli_ctx).container_apps_revision_replicas


def cf_dapr_components(cli_ctx, *_):
return app_client_factory(cli_ctx).dapr_components


def cf_certificates(cli_ctx, *_):
return app_client_factory(cli_ctx).certificates


def cf_namespaces(cli_ctx, *_):
return app_client_factory(cli_ctx).namespaces

def cf_storages(cli_ctx, *_):
return app_client_factory(cli_ctx).managed_environments_storages
10 changes: 6 additions & 4 deletions src/containerapp/azext_containerapp/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1287,11 +1287,13 @@ def load_cert_file(file_path, cert_password=None):


def check_cert_name_availability(cmd, resource_group_name, name, cert_name):
name_availability_request = {}
name_availability_request["name"] = cert_name
name_availability_request["type"] = CHECK_CERTIFICATE_NAME_AVAILABILITY_TYPE
from ._client_factory import cf_namespaces
from azure.mgmt.appcontainers.models import CheckNameAvailabilityRequest
client = cf_namespaces(cmd.cli_ctx)

name_availability_request = CheckNameAvailabilityRequest(name=cert_name, type=CHECK_CERTIFICATE_NAME_AVAILABILITY_TYPE)
try:
r = ManagedEnvironmentClient.check_name_availability(cmd, resource_group_name, name, name_availability_request)
r = client.check_name_availability(resource_group_name=resource_group_name, environment_name=name, check_name_availability_request=name_availability_request)
except CLIError as e:
handle_raw_exception(e)
return r
Expand Down
48 changes: 24 additions & 24 deletions src/containerapp/azext_containerapp/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# pylint: disable=line-too-long, too-many-statements, bare-except
# from azure.cli.core.commands import CliCommandType
# from msrestazure.tools import is_valid_resource_id, parse_resource_id
from azext_containerapp._client_factory import ex_handler_factory
from azext_containerapp._client_factory import ex_handler_factory, cf_containerapps, cf_managedenvs, cf_revisions, cf_replicas, cf_dapr_components, cf_certificates, cf_storages
from ._validators import validate_ssh


Expand Down Expand Up @@ -44,86 +44,86 @@ def transform_revision_list_output(revs):


def load_command_table(self, _):
with self.command_group('containerapp') as g:
with self.command_group('containerapp', client_factory=cf_containerapps) as g:
g.custom_show_command('show', 'show_containerapp', table_transformer=transform_containerapp_output)
g.custom_command('list', 'list_containerapp', table_transformer=transform_containerapp_list_output)
g.custom_command('create', 'create_containerapp', supports_no_wait=True, exception_handler=ex_handler_factory(), table_transformer=transform_containerapp_output)
g.custom_command('update', 'update_containerapp', supports_no_wait=True, exception_handler=ex_handler_factory(), table_transformer=transform_containerapp_output)
g.custom_command('delete', 'delete_containerapp', supports_no_wait=True, confirmation=True, exception_handler=ex_handler_factory())
g.custom_command('exec', 'containerapp_ssh', validator=validate_ssh)
g.custom_command('up', 'containerapp_up', supports_no_wait=False, exception_handler=ex_handler_factory())
g.custom_command('exec', 'containerapp_ssh', validator=validate_ssh) # TODO: Silas
g.custom_command('up', 'containerapp_up', supports_no_wait=False, exception_handler=ex_handler_factory()) # TODO
g.custom_command('browse', 'open_containerapp_in_browser')

with self.command_group('containerapp replica') as g:
with self.command_group('containerapp replica', client_factory=cf_replicas) as g: # TODO: Test
g.custom_show_command('show', 'get_replica') # TODO implement the table transformer
g.custom_command('list', 'list_replicas')

with self.command_group('containerapp logs') as g:
g.custom_show_command('show', 'stream_containerapp_logs', validator=validate_ssh)
g.custom_show_command('show', 'stream_containerapp_logs', validator=validate_ssh) # TODO: Silas

with self.command_group('containerapp env') as g:
with self.command_group('containerapp env', client_factory=cf_managedenvs) as g: # TODO: no_wait support
g.custom_show_command('show', 'show_managed_environment')
g.custom_command('list', 'list_managed_environments')
g.custom_command('create', 'create_managed_environment', supports_no_wait=True, exception_handler=ex_handler_factory())
g.custom_command('delete', 'delete_managed_environment', supports_no_wait=True, confirmation=True, exception_handler=ex_handler_factory())

with self.command_group('containerapp env dapr-component') as g:
with self.command_group('containerapp env dapr-component', client_factory=cf_dapr_components) as g:
g.custom_command('list', 'list_dapr_components')
g.custom_show_command('show', 'show_dapr_component')
g.custom_command('set', 'create_or_update_dapr_component')
g.custom_command('remove', 'remove_dapr_component')

with self.command_group('containerapp env certificate') as g:
g.custom_command('list', 'list_certificates')
g.custom_command('upload', 'upload_certificate')
g.custom_command('delete', 'delete_certificate', confirmation=True, exception_handler=ex_handler_factory())
with self.command_group('containerapp env certificate', client_factory=cf_certificates) as g:
g.custom_command('list', 'list_certificates') # TODO: Testing - Silas
g.custom_command('upload', 'upload_certificate') # TODO: Testing - Silas
g.custom_command('delete', 'delete_certificate', confirmation=True, exception_handler=ex_handler_factory()) # TODO: Testing - Silas

with self.command_group('containerapp env storage', is_preview=True) as g:
with self.command_group('containerapp env storage', client_factory=cf_storages, is_preview=True) as g: # TODO: test no wait support
g.custom_show_command('show', 'show_storage')
g.custom_command('list', 'list_storage')
g.custom_command('set', 'create_or_update_storage', supports_no_wait=True, exception_handler=ex_handler_factory())
g.custom_command('remove', 'remove_storage', supports_no_wait=True, confirmation=True, exception_handler=ex_handler_factory())

with self.command_group('containerapp identity') as g:
with self.command_group('containerapp identity', client_factory=cf_containerapps) as g: # Tests pass
g.custom_command('assign', 'assign_managed_identity', supports_no_wait=True, exception_handler=ex_handler_factory())
g.custom_command('remove', 'remove_managed_identity', supports_no_wait=True, exception_handler=ex_handler_factory())
g.custom_show_command('show', 'show_managed_identity')

with self.command_group('containerapp github-action') as g:
with self.command_group('containerapp github-action') as g: # TODO: Silas
g.custom_command('add', 'create_or_update_github_action', exception_handler=ex_handler_factory())
g.custom_show_command('show', 'show_github_action', exception_handler=ex_handler_factory())
g.custom_command('delete', 'delete_github_action', exception_handler=ex_handler_factory())

with self.command_group('containerapp revision') as g:
with self.command_group('containerapp revision', client_factory=cf_revisions) as g: # TODO: Test
g.custom_command('activate', 'activate_revision')
g.custom_command('deactivate', 'deactivate_revision')
g.custom_command('list', 'list_revisions', table_transformer=transform_revision_list_output, exception_handler=ex_handler_factory())
g.custom_command('restart', 'restart_revision')
g.custom_show_command('show', 'show_revision', table_transformer=transform_revision_output, exception_handler=ex_handler_factory())
g.custom_command('copy', 'copy_revision', exception_handler=ex_handler_factory())
g.custom_command('set-mode', 'set_revision_mode', exception_handler=ex_handler_factory())
g.custom_command('copy', 'copy_revision', client_factory=cf_containerapps, supports_no_wait=True, exception_handler=ex_handler_factory())
g.custom_command('set-mode', 'set_revision_mode', client_factory=cf_containerapps, supports_no_wait=True, exception_handler=ex_handler_factory())

with self.command_group('containerapp revision label') as g:
g.custom_command('add', 'add_revision_label')
with self.command_group('containerapp revision label', client_factory=cf_containerapps) as g: # Tests
g.custom_command('add', 'add_revision_label', supports_no_wait=True)
g.custom_command('remove', 'remove_revision_label')
g.custom_command('swap', 'swap_revision_label')

with self.command_group('containerapp ingress') as g:
with self.command_group('containerapp ingress', client_factory=cf_containerapps) as g: # TODO: Test
g.custom_command('enable', 'enable_ingress', exception_handler=ex_handler_factory())
g.custom_command('disable', 'disable_ingress', exception_handler=ex_handler_factory())
g.custom_show_command('show', 'show_ingress')

with self.command_group('containerapp ingress traffic') as g:
with self.command_group('containerapp ingress traffic', client_factory=cf_containerapps) as g: # TODO: Test
g.custom_command('set', 'set_ingress_traffic', exception_handler=ex_handler_factory())
g.custom_show_command('show', 'show_ingress_traffic')

with self.command_group('containerapp registry') as g:
with self.command_group('containerapp registry', client_factory=cf_containerapps) as g: # TODO
g.custom_command('set', 'set_registry', exception_handler=ex_handler_factory())
g.custom_show_command('show', 'show_registry')
g.custom_command('list', 'list_registry')
g.custom_command('remove', 'remove_registry', exception_handler=ex_handler_factory())

with self.command_group('containerapp secret') as g:
with self.command_group('containerapp secret', client_factory=cf_containerapps) as g: # TODO
g.custom_command('list', 'list_secrets')
g.custom_show_command('show', 'show_secret')
g.custom_command('remove', 'remove_secrets', exception_handler=ex_handler_factory())
Expand Down
Loading