Skip to content

Commit f51ebf0

Browse files
committed
add --basic-auth to webapp up/create/update
1 parent 7a4d03f commit f51ebf0

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

src/azure-cli/azure/cli/command_modules/appservice/_params.py

+3
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ def load_arguments(self, _):
159159
c.argument('vnet', help="Name or resource ID of the regional virtual network. If there are multiple vnets of the same name across different resource groups, use vnet resource id to specify which vnet to use. If vnet name is used, by default, the vnet in the same resource group as the webapp will be used. Must be used with --subnet argument.")
160160
c.argument('subnet', help="Name or resource ID of the pre-existing subnet to have the webapp join. The --vnet is argument also needed if specifying subnet by name.")
161161
c.argument('public_network_access', help="Enable or disable public access to the web app", arg_type=get_enum_type(PUBLIC_NETWORK_ACCESS_MODES))
162+
c.argument('basic_auth', options_list=['--basic-auth'], help='Enable or disable basic auth.')
162163
c.ignore('language')
163164
c.ignore('using_webapp_up')
164165

@@ -208,6 +209,7 @@ def load_arguments(self, _):
208209
arg_type=get_three_state_flag(return_label=True), deprecate_info=c.deprecate(expiration='3.0.0'))
209210
c.argument('minimum_elastic_instance_count', options_list=["--minimum-elastic-instance-count", "-i"], type=int, is_preview=True, help="Minimum number of instances. App must be in an elastic scale App Service Plan.")
210211
c.argument('prewarmed_instance_count', options_list=["--prewarmed-instance-count", "-w"], type=int, is_preview=True, help="Number of preWarmed instances. App must be in an elastic scale App Service Plan.")
212+
c.argument('basic_auth', options_list=['--basic-auth'], help='Enable or disable basic auth.')
211213

212214
with self.argument_context('webapp browse') as c:
213215
c.argument('logs', options_list=['--logs', '-l'], action='store_true',
@@ -688,6 +690,7 @@ def load_arguments(self, _):
688690
default=False, action='store_true')
689691
c.argument('html', help="Ignore app detection and deploy as an html app", default=False, action='store_true')
690692
c.argument('app_service_environment', options_list=['--app-service-environment', '-e'], help='name or resource ID of the (pre-existing) App Service Environment to deploy to. Requires an Isolated V2 sku [I1v2, I2v2, I3v2]')
693+
c.argument('basic_auth', options_list=['--basic-auth'], help='Enable or disable basic auth.')
691694

692695
with self.argument_context('webapp ssh') as c:
693696
c.argument('port', options_list=['--port', '-p'],

src/azure-cli/azure/cli/command_modules/appservice/custom.py

+35-3
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ def create_webapp(cmd, resource_group_name, name, plan, runtime=None, startup_fi
104104
deployment_local_git=None, docker_registry_server_password=None, docker_registry_server_user=None,
105105
multicontainer_config_type=None, multicontainer_config_file=None, tags=None,
106106
using_webapp_up=False, language=None, assign_identities=None,
107-
role='Contributor', scope=None, vnet=None, subnet=None, https_only=False, public_network_access=None):
107+
role='Contributor', scope=None, vnet=None, subnet=None, https_only=False,
108+
public_network_access=None, basic_auth=""):
108109
from azure.mgmt.web.models import Site
109110
from azure.core.exceptions import ResourceNotFoundError as _ResourceNotFoundError
110111
SiteConfig, SkuDescription, NameValuePair = cmd.get_models(
@@ -113,6 +114,9 @@ def create_webapp(cmd, resource_group_name, name, plan, runtime=None, startup_fi
113114
if deployment_source_url and deployment_local_git:
114115
raise MutuallyExclusiveArgumentError('usage error: --deployment-source-url <url> | --deployment-local-git')
115116

117+
basic_auth = basic_auth.lower()
118+
_check_basic_auth_param(basic_auth)
119+
116120
docker_registry_server_url = parse_docker_image_name(deployment_container_image_name)
117121

118122
client = web_client_factory(cmd.cli_ctx)
@@ -286,9 +290,27 @@ def create_webapp(cmd, resource_group_name, name, plan, runtime=None, startup_fi
286290
identity = assign_identity(cmd, resource_group_name, name, assign_identities,
287291
role, None, scope)
288292
webapp.identity = identity
293+
294+
_enable_basic_auth(cmd, name, None, resource_group_name, basic_auth)
289295
return webapp
290296

291297

298+
def _enable_basic_auth(cmd, app_name, slot_name, resource_group, enabled):
299+
if enabled == "":
300+
return
301+
CsmPublishingCredentialsPoliciesEntity = cmd.get_models("CsmPublishingCredentialsPoliciesEntity")
302+
csmPublishingCredentialsPoliciesEntity = CsmPublishingCredentialsPoliciesEntity(allow=enabled == "enabled")
303+
_generic_site_operation(cmd.cli_ctx, resource_group, app_name,
304+
'update_ftp_allowed', slot_name, csmPublishingCredentialsPoliciesEntity)
305+
_generic_site_operation(cmd.cli_ctx, resource_group, app_name,
306+
'update_scm_allowed', slot_name, csmPublishingCredentialsPoliciesEntity)
307+
308+
309+
def _check_basic_auth_param(basic_auth):
310+
if basic_auth != "enabled" and basic_auth != "disabled" and basic_auth != "":
311+
raise ValidationError("--basic_auth parameter only accept Enabled or Disabled as input")
312+
313+
292314
def _validate_vnet_integration_location(cmd, subnet_resource_group, vnet_name, webapp_location, vnet_sub_id=None):
293315
from azure.cli.core.commands.client_factory import get_subscription_id
294316

@@ -807,7 +829,7 @@ def get_webapp(cmd, resource_group_name, name, slot=None):
807829
return _generic_site_operation(cmd.cli_ctx, resource_group_name, name, 'get', slot)
808830

809831

810-
def set_webapp(cmd, resource_group_name, name, slot=None, skip_dns_registration=None, # pylint: disable=unused-argument
832+
def set_webapp(cmd, resource_group_name, name, slot=None, skip_dns_registration=None, basic_auth="", # pylint: disable=unused-argument
811833
skip_custom_domain_verification=None, force_dns_registration=None, ttl_in_seconds=None, **kwargs): # pylint: disable=unused-argument
812834
instance = kwargs['parameters']
813835
client = web_client_factory(cmd.cli_ctx)
@@ -816,6 +838,10 @@ def set_webapp(cmd, resource_group_name, name, slot=None, skip_dns_registration=
816838
if slot:
817839
kwargs['slot'] = slot
818840

841+
basic_auth = basic_auth.lower()
842+
_check_basic_auth_param(basic_auth)
843+
_enable_basic_auth(cmd, name, slot, resource_group_name, basic_auth)
844+
819845
return updater(**kwargs)
820846

821847

@@ -5052,10 +5078,13 @@ def get_history_triggered_webjob(cmd, resource_group_name, name, webjob_name, sl
50525078

50535079
def webapp_up(cmd, name=None, resource_group_name=None, plan=None, location=None, sku=None, # pylint: disable=too-many-statements,too-many-branches
50545080
os_type=None, runtime=None, dryrun=False, logs=False, launch_browser=False, html=False,
5055-
app_service_environment=None):
5081+
app_service_environment=None, basic_auth=None):
50565082
if not name:
50575083
name = generate_default_app_name(cmd)
50585084

5085+
basic_auth = basic_auth.lower()
5086+
_check_basic_auth_param(basic_auth)
5087+
50595088
import os
50605089

50615090
AppServicePlan = cmd.get_models('AppServicePlan')
@@ -5222,6 +5251,9 @@ def webapp_up(cmd, name=None, resource_group_name=None, plan=None, location=None
52225251
if match:
52235252
_update_app_settings_for_windows_if_needed(cmd, rg_name, name, match, site_config, runtime_version)
52245253
create_json['runtime_version'] = runtime_version
5254+
5255+
_enable_basic_auth(cmd, name, None, resource_group_name, basic_auth)
5256+
52255257
# Zip contents & Deploy
52265258
logger.warning("Creating zip with contents of dir %s ...", src_dir)
52275259
# zip contents & deploy

0 commit comments

Comments
 (0)