Skip to content
Draft
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
36 changes: 0 additions & 36 deletions src/azure-cli/azure/cli/command_modules/util/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
11 changes: 0 additions & 11 deletions src/azure-cli/azure/cli/command_modules/util/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: `<key>=<value> [<key>=<value> ...]`")

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")
8 changes: 0 additions & 8 deletions src/azure-cli/azure/cli/command_modules/util/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
138 changes: 0 additions & 138 deletions src/azure-cli/azure/cli/command_modules/util/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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, " <subscription ID>\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)
Loading