diff --git a/src/azure-cli/azure/cli/command_modules/util/_help.py b/src/azure-cli/azure/cli/command_modules/util/_help.py index 84c2a529b68..98fafb04f5e 100644 --- a/src/azure-cli/azure/cli/command_modules/util/_help.py +++ b/src/azure-cli/azure/cli/command_modules/util/_help.py @@ -56,39 +56,3 @@ type: command short-summary: Upgrade Azure CLI and extensions """ - -helps['demo'] = """ -type: group -short-summary: Demos for designing, developing and demonstrating Azure CLI. -""" - -helps['demo style'] = """ -type: command -short-summary: A demo showing supported text styles. -""" - -helps['demo secret-store'] = """ -type: group -short-summary: A demo showing how to use secret store. -""" - -helps['demo secret-store save'] = """ -type: command -short-summary: Save custom data to secret store. -examples: -- name: Save data to secret store. - text: az demo secret-store save "name=Johann Sebastian Bach" job=musician -""" - -helps['demo secret-store load'] = """ -type: command -short-summary: Load custom data from secret store. -""" - -helps['demo byo-access-token'] = """ -type: command -short-summary: List resource groups by bringing your own access token -examples: -- name: List resource groups by bringing your own access token - text: az demo byo-access-token --access-token "eyJ0eXAiO..." --subscription-id 00000000-0000-0000-0000-000000000000 -""" diff --git a/src/azure-cli/azure/cli/command_modules/util/_params.py b/src/azure-cli/azure/cli/command_modules/util/_params.py index 3e0aae88cd1..0c045a7f6ee 100644 --- a/src/azure-cli/azure/cli/command_modules/util/_params.py +++ b/src/azure-cli/azure/cli/command_modules/util/_params.py @@ -40,14 +40,3 @@ def load_arguments(self, _): c.argument('yes', options_list=['--yes', '-y'], action='store_true', help='Do not prompt for checking release notes.') c.argument('allow_preview', options_list=['--allow-preview-extensions', '--allow-preview'], arg_type=get_three_state_flag(), help="Include preview packages for extension installation, if exists") - - with self.argument_context('demo style') as c: - c.argument('theme', arg_type=get_enum_type(Theme), - help='The theme to format styled text. If unspecified, the default theme is used.') - - with self.argument_context('demo secret-store save') as c: - c.positional('key_value', nargs='+', help="Space-separated data: `= [= ...]`") - - with self.argument_context('demo byo-access-token') as c: - c.argument('access_token', help="Your own access token") - c.argument('subscription_id', help="Subscription ID under which to list resource groups") diff --git a/src/azure-cli/azure/cli/command_modules/util/commands.py b/src/azure-cli/azure/cli/command_modules/util/commands.py index 6f0c14030fc..b3a36e0dd77 100644 --- a/src/azure-cli/azure/cli/command_modules/util/commands.py +++ b/src/azure-cli/azure/cli/command_modules/util/commands.py @@ -14,11 +14,3 @@ def load_command_table(self, _): with self.command_group('') as g: g.custom_command('upgrade', 'upgrade_version', is_preview=True) - - with self.command_group('demo', deprecate_info=g.deprecate(hide=True)) as g: - g.custom_command('style', 'demo_style') - g.custom_command('byo-access-token', 'byo_access_token') - - with self.command_group('demo secret-store') as g: - g.custom_command('save', 'secret_store_save') - g.custom_command('load', 'secret_store_load') diff --git a/src/azure-cli/azure/cli/command_modules/util/custom.py b/src/azure-cli/azure/cli/command_modules/util/custom.py index ca71e1bcaf2..ce8766770d8 100644 --- a/src/azure-cli/azure/cli/command_modules/util/custom.py +++ b/src/azure-cli/azure/cli/command_modules/util/custom.py @@ -11,7 +11,6 @@ logger = get_logger(__name__) UPGRADE_MSG = 'Not able to upgrade automatically. Instructions can be found at https://aka.ms/doc/InstallAzureCli' -SECRET_STORE_DEMO = "secret_store_demo" def rest_call(cmd, url, method=None, headers=None, uri_parameters=None, @@ -240,140 +239,3 @@ def _download_from_url(url, target_dir): f.write(chunk) return msi_path - - -def demo_style(cmd, theme=None): # pylint: disable=unused-argument - from azure.cli.core.style import Style, print_styled_text, format_styled_text - if theme: - format_styled_text.theme = theme - print_styled_text("[How to call print_styled_text]") - # Print an empty line - print_styled_text() - # Various methods to print - print_styled_text("- Print using a str") - print_styled_text("- Print using multiple", "strs") - print_styled_text((Style.PRIMARY, "- Print using a tuple")) - print_styled_text((Style.PRIMARY, "- Print using multiple"), (Style.IMPORTANT, "tuples")) - print_styled_text([(Style.PRIMARY, "- Print using a "), (Style.IMPORTANT, "list")]) - print_styled_text([(Style.PRIMARY, "- Print using multiple")], [(Style.IMPORTANT, "lists")]) - print_styled_text() - - print_styled_text("[Available styles]\n") - placeholder = '████ {:8s}: {}\n' - styled_text = [ - (Style.PRIMARY, placeholder.format("White", "Primary text color")), - (Style.SECONDARY, placeholder.format("Grey", "Secondary text color")), - (Style.HIGHLIGHT, placeholder.format("Cyan", "Highlight text color")), - (Style.IMPORTANT, placeholder.format("Magenta", "Important text color")), - (Style.ACTION, placeholder.format( - "Blue", "Commands, parameters, and system inputs (White in legacy powershell terminal)")), - (Style.HYPERLINK, placeholder.format("Cyan", "Hyperlink")), - (Style.ERROR, placeholder.format("Red", "Error message indicator")), - (Style.SUCCESS, placeholder.format("Green", "Success message indicator")), - (Style.WARNING, placeholder.format("Yellow", "Warning message indicator")), - ] - print_styled_text(styled_text) - - print_styled_text("[interactive]\n") - # NOTE! Unicode character ⦾ ⦿ will most likely not be displayed correctly - styled_text = [ - (Style.ACTION, "?"), - (Style.PRIMARY, " Select a SKU for your app:\n"), - (Style.PRIMARY, "⦾ Free "), - (Style.SECONDARY, "Dev/Test workloads: 1 GB memory, 60 minutes/day compute\n"), - (Style.PRIMARY, "⦾ Basic "), - (Style.SECONDARY, "Dev/Test workloads: 1.75 GB memory, monthly charges apply\n"), - (Style.PRIMARY, "⦾ Standard "), - (Style.SECONDARY, "Production workloads: 1.75 GB memory, monthly charges apply\n"), - (Style.ACTION, "⦿ Premium "), - (Style.SECONDARY, "Production workloads: 3.5 GB memory, monthly charges apply\n"), - ] - print_styled_text(styled_text) - - print_styled_text("[progress report]\n") - # NOTE! Unicode character ✓ will most likely not be displayed correctly - styled_text = [ - (Style.SUCCESS, '(✓) Done: '), - (Style.PRIMARY, "Creating a resource group for myfancyapp\n"), - (Style.SUCCESS, '(✓) Done: '), - (Style.PRIMARY, "Creating an App Service Plan for myfancyappplan on a "), - (Style.IMPORTANT, "premium instance"), - (Style.PRIMARY, " that has a "), - (Style.IMPORTANT, "monthly charge"), - (Style.PRIMARY, "\n"), - (Style.SUCCESS, '(✓) Done: '), - (Style.PRIMARY, "Creating a webapp named myfancyapp\n"), - ] - print_styled_text(styled_text) - - print_styled_text("[error handing]\n") - styled_text = [ - (Style.ERROR, "ERROR: Command not found: az storage create\n"), - (Style.PRIMARY, "TRY\n"), - (Style.ACTION, "az storage account create --name"), - (Style.PRIMARY, " mystorageaccount "), - (Style.ACTION, "--resource-group"), - (Style.PRIMARY, " MyResourceGroup\n"), - (Style.SECONDARY, "Create a storage account. For more detail, see "), - (Style.HYPERLINK, "https://learn.microsoft.com/azure/storage/common/storage-account-create?" - "tabs=azure-cli#create-a-storage-account-1"), - (Style.SECONDARY, "\n"), - ] - print_styled_text(styled_text) - - print_styled_text("[post-output hint]\n") - styled_text = [ - (Style.PRIMARY, "The default subscription is "), - (Style.IMPORTANT, "AzureSDKTest (0b1f6471-1bf0-4dda-aec3-cb9272f09590)"), - (Style.PRIMARY, ". To switch to another subscription, run "), - (Style.ACTION, "az account set --subscription"), - (Style.PRIMARY, " \n"), - (Style.WARNING, "WARNING: The subscription has been disabled!\n") - ] - print_styled_text(styled_text) - - print_styled_text("[logs]\n") - - # Print logs - logger.debug("This is a debug log entry.") - logger.info("This is a info log entry.") - logger.warning("This is a warning log entry.") - logger.error("This is a error log entry.") - logger.critical("This is a critical log entry.") - - -def secret_store_save(cmd, key_value): - data = dict(kv.split('=', 1) for kv in key_value) - from azure.cli.core.util import get_secret_store - store = get_secret_store(cmd.cli_ctx, SECRET_STORE_DEMO) - store.save(data) - logger.warning("Data written to %s: %s", - store._persistence.get_location(), data) # pylint: disable=protected-access - - -def secret_store_load(cmd): - from azure.cli.core.util import get_secret_store - store = get_secret_store(cmd.cli_ctx, SECRET_STORE_DEMO) - return store.load() - - -def byo_access_token(cmd, access_token, subscription_id): - from azure.cli.core.commands.client_factory import get_mgmt_service_client - from azure.cli.core.profiles import ResourceType - credential = AccessTokenCredential(access_token) - client = get_mgmt_service_client(cmd.cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES, - subscription_id=subscription_id, credential=credential) - return client.resource_groups.list() - - -class AccessTokenCredential: # pylint: disable=too-few-public-methods - """Simple access token authentication. Return the access token as-is. - """ - def __init__(self, access_token): - self.access_token = access_token - - def get_token(self, *scopes, **kwargs): # pylint: disable=unused-argument - import time - from azure.cli.core.auth.util import AccessToken - # Assume the access token expires in 1 year / 31536000 seconds - return AccessToken(self.access_token, int(time.time()) + 31536000)