Skip to content
Merged
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
1 change: 1 addition & 0 deletions scripts/ci/credscan/CredScanSuppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"src\\azure-cli\\azure\\cli\\command_modules\\appservice\\tests\\latest\\recordings\\test_webapp_e2e.yaml",
"src\\azure-cli\\azure\\cli\\command_modules\\appservice\\tests\\latest\\recordings\\test_webapp_list_deployment_logs.yaml",
"src\\azure-cli\\azure\\cli\\command_modules\\appservice\\tests\\latest\\recordings\\test_webapp_up_statichtml_e2e.yaml",
"src\\azure-cli\\azure\\cli\\command_modules\\appservice\\tests\\latest\\recordings\\test_webapp_up_generate_default_name.yaml",
"src\\azure-cli\\azure\\cli\\command_modules\\appservice\\tests\\latest\\recordings\\test_windows_to_linux_fail.yaml"
],
"_justification": "[AppService] response body contains random value recognized as secret"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,8 @@ def __init__(self):
self.FUNCTIONS_WORKER_RUNTIME = 'FUNCTIONS_WORKER_RUNTIME'


RUNTIME_STACKS = os.path.abspath(os.path.join(os.path.abspath(__file__), '../resources/WebappRuntimeStacks.json'))
RUNTIME_STACKS = os.path.abspath(os.path.join(os.path.abspath(__file__),
'../resources/WebappRuntimeStacks.json'))

GENERATE_RANDOM_APP_NAMES = os.path.abspath(os.path.join(os.path.abspath(__file__),
'../resources/GenerateRandomAppNames.json'))
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
from knack.util import CLIError
from knack.log import get_logger
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from azure.cli.core.util import get_file_json
from azure.mgmt.web.models import SkuDescription

from ._constants import (NETCORE_VERSION_DEFAULT, NETCORE_VERSIONS, NODE_VERSION_DEFAULT,
NODE_VERSIONS, NETCORE_RUNTIME_NAME, NODE_RUNTIME_NAME, ASPDOTNET_RUNTIME_NAME,
ASPDOTNET_VERSION_DEFAULT, DOTNET_VERSIONS, STATIC_RUNTIME_NAME,
PYTHON_RUNTIME_NAME, PYTHON_VERSION_DEFAULT, LINUX_SKU_DEFAULT, OS_DEFAULT,
NODE_VERSION_NEWER, DOTNET_RUNTIME_NAME, DOTNET_VERSION_DEFAULT,
DOTNET_TARGET_FRAMEWORK_STRING)
DOTNET_TARGET_FRAMEWORK_STRING, GENERATE_RANDOM_APP_NAMES)

logger = get_logger(__name__)

Expand Down Expand Up @@ -431,3 +432,30 @@ def should_create_new_app(cmd, rg_name, app_name): # this is currently referenc
if item.name.lower() == app_name.lower():
return False
return True


def generate_default_app_name(cmd):
def generate_name(cmd):
import uuid
from random import choice

noun = choice(get_file_json(GENERATE_RANDOM_APP_NAMES)['APP_NAME_NOUNS'])
adjective = choice(get_file_json(GENERATE_RANDOM_APP_NAMES)['APP_NAME_ADJECTIVES'])
random_uuid = str(uuid.uuid4().hex)

name = '{}-{}-{}'.format(adjective, noun, random_uuid)
name_available = get_site_availability(cmd, name).name_available

if name_available:
return name
return ""

retry_times = 5
generated_name = generate_name(cmd)
while not generated_name and retry_times > 0:
retry_times -= 1
generated_name = generate_name(cmd)

if not generated_name:
raise CLIError("Unable to generate a default name for webapp. Please specify webapp name using --name flag")
return generated_name
17 changes: 10 additions & 7 deletions src/azure-cli/azure/cli/command_modules/appservice/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -1951,22 +1951,25 @@
examples:
- name: View the details of the app that will be created, without actually running the operation
text: >
az webapp up -n MyUniqueAppName --dryrun
- name: Create a web app with the default configuration, by running the command from the folder where the code to deployed exists.
az webapp up --dryrun
- name: Create a web app with the default configuration, by running the command from the folder where the code to be deployed exists.
text: >
az webapp up -n MyUniqueAppName -l locationName
- name: Create a web app in a specific region, by running the command from the folder where the code to deployed exists.
az webapp up
- name: Create a web app with a specified name
text: >
az webapp up -n MyUniqueAppName -l locationName
az webapp up -n MyUniqueAppName
- name: Create a web app in a specific region, by running the command from the folder where the code to be deployed exists.
text: >
az webapp up -l locationName
- name: Deploy new code to an app that was originally created using the same command
text: >
az webapp up -n MyUniqueAppName -l locationName
- name: Create a web app and enable log streaming after the deployment operation is complete. This will enable the default configuration required to enable log streaming.
text: >
az webapp up -n MyUniqueAppName --logs
az webapp up --logs
- name: Create a web app and deploy as a static HTML app.
text: >
az webapp up -n MyUniqueAppName --html
az webapp up --html
"""

helps['webapp update'] = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def load_arguments(self, _):
webapp_name_arg_type = CLIArgumentType(configured_default='web', options_list=['--name', '-n'], metavar='NAME',
completer=get_resource_name_completion_list('Microsoft.Web/sites'),
id_part='name',
help="name of the web app. You can configure the default using `az configure --defaults web=<name>`",
help="name of the web app. If left unspecified, a name will be randomly generated. You can configure the default using `az configure --defaults web=<name>`",
local_context_attribute=LocalContextAttribute(name='web_name', actions=[
LocalContextAction.GET]))
functionapp_name_arg_type = CLIArgumentType(options_list=['--name', '-n'], metavar='NAME',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
from ._create_util import (zip_contents_from_dir, get_runtime_version_details, create_resource_group, get_app_details,
should_create_new_rg, set_location, get_site_availability, get_profile_username,
get_plan_to_use, get_lang_from_content, get_rg_to_use, get_sku_to_use,
detect_os_form_src, get_current_stack_from_runtime)
detect_os_form_src, get_current_stack_from_runtime, generate_default_app_name)
from ._constants import (FUNCTIONS_STACKS_API_JSON_PATHS, FUNCTIONS_STACKS_API_KEYS,
FUNCTIONS_LINUX_RUNTIME_VERSION_REGEX, FUNCTIONS_WINDOWS_RUNTIME_VERSION_REGEX,
NODE_EXACT_VERSION_DEFAULT, RUNTIME_STACKS, FUNCTIONS_NO_V2_REGIONS)
Expand Down Expand Up @@ -3618,8 +3618,11 @@ def get_history_triggered_webjob(cmd, resource_group_name, name, webjob_name, sl
return client.web_apps.list_triggered_web_job_history(resource_group_name, name, webjob_name)


def webapp_up(cmd, name, resource_group_name=None, plan=None, location=None, sku=None, # pylint: disable=too-many-statements,too-many-branches
def webapp_up(cmd, name=None, resource_group_name=None, plan=None, location=None, sku=None, # pylint: disable=too-many-statements,too-many-branches
os_type=None, runtime=None, dryrun=False, logs=False, launch_browser=False, html=False):
if not name:
name = generate_default_app_name(cmd)

import os
AppServicePlan = cmd.get_models('AppServicePlan')
src_dir = os.getcwd()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"APP_NAME_ADJECTIVES": [
"ashy",
"black",
"blue",
"gray",
"green",
"icy",
"lemon",
"mango",
"orange",
"purple",
"red",
"salmon",
"white",
"yellow",
"agreeable",
"ambitious",
"brave",
"calm",
"delightful",
"gentle",
"happy",
"jolly",
"kind",
"lively",
"nice",
"polite",
"proud",
"thankful",
"victorious",
"witty",
"wonderful",
"zealous"
],
"APP_NAME_NOUNS": [
"island",
"bay",
"beach",
"sea",
"ocean",
"coast",
"ground",
"dune",
"desert",
"cliff",
"meadow",
"forest",
"glacier",
"hill",
"field",
"grass",
"mushroom",
"pebble",
"rock",
"stone",
"smoke",
"pond",
"river",
"wave",
"sky",
"water",
"tree",
"plant",
"moss",
"flower",
"bush",
"sand",
"mud"
]
}
Loading