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

[App Service] az webapp up/create/update: Add new parameter --basic-auth to allow users to enable and disable basic auth #28237

Merged
merged 10 commits into from
Feb 18, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
ASE_KINDS = ['ASEv2', 'ASEv3']
ASE_OS_PREFERENCE_TYPES = ['Windows', 'Linux']
PUBLIC_NETWORK_ACCESS_MODES = ['Enabled', 'Disabled']
BASIC_AUTH_TYPES = ['Enabled', 'Disabled']
DAPR_LOG_LEVELS = ['debug', 'error', 'info', 'warn']


Expand Down Expand Up @@ -160,6 +161,7 @@ def load_arguments(self, _):
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.")
c.argument('public_network_access', help="Enable or disable public access to the web app", arg_type=get_enum_type(PUBLIC_NETWORK_ACCESS_MODES))
c.argument('acr_use_identity', action='store_true', help="Enable or disable pull image from acr use managed identity")
c.argument('basic_auth', help='Enable or disable basic auth.', arg_type=get_enum_type(BASIC_AUTH_TYPES))
c.ignore('language')
c.ignore('using_webapp_up')

Expand Down Expand Up @@ -209,6 +211,7 @@ def load_arguments(self, _):
arg_type=get_three_state_flag(return_label=True), deprecate_info=c.deprecate(expiration='3.0.0'))
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.")
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.")
c.argument('basic_auth', help='Enable or disable basic auth.', arg_type=get_enum_type(BASIC_AUTH_TYPES))

with self.argument_context('webapp browse') as c:
c.argument('logs', options_list=['--logs', '-l'], action='store_true',
Expand Down Expand Up @@ -693,6 +696,7 @@ def load_arguments(self, _):
default=False, action='store_true')
c.argument('html', help="Ignore app detection and deploy as an html app", default=False, action='store_true')
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]')
c.argument('basic_auth', help='Enable or disable basic auth.', arg_type=get_enum_type(BASIC_AUTH_TYPES))
c.argument('track_status', help="If true, web app startup status during deployment will be tracked for linux web apps.",
arg_type=get_three_state_flag())

Expand Down
26 changes: 22 additions & 4 deletions src/azure-cli/azure/cli/command_modules/appservice/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ def create_webapp(cmd, resource_group_name, name, plan, runtime=None, startup_fi
deployment_local_git=None, docker_registry_server_password=None, docker_registry_server_user=None,
multicontainer_config_type=None, multicontainer_config_file=None, tags=None,
using_webapp_up=False, language=None, assign_identities=None,
role='Contributor', scope=None, vnet=None, subnet=None, https_only=False, public_network_access=None,
acr_use_identity=False):
role='Contributor', scope=None, vnet=None, subnet=None, https_only=False,
public_network_access=None, acr_use_identity=False, basic_auth=""):
from azure.mgmt.web.models import Site
from azure.core.exceptions import ResourceNotFoundError as _ResourceNotFoundError
SiteConfig, SkuDescription, NameValuePair = cmd.get_models(
Expand Down Expand Up @@ -291,9 +291,22 @@ def create_webapp(cmd, resource_group_name, name, plan, runtime=None, startup_fi
identity = assign_identity(cmd, resource_group_name, name, assign_identities,
role, None, scope)
webapp.identity = identity

_enable_basic_auth(cmd, name, None, resource_group_name, basic_auth.lower())
return webapp


def _enable_basic_auth(cmd, app_name, slot_name, resource_group, enabled):
if not enabled or enabled == "":
return
CsmPublishingCredentialsPoliciesEntity = cmd.get_models("CsmPublishingCredentialsPoliciesEntity")
csmPublishingCredentialsPoliciesEntity = CsmPublishingCredentialsPoliciesEntity(allow=enabled == "enabled")
_generic_site_operation(cmd.cli_ctx, resource_group, app_name,
'update_ftp_allowed', slot_name, csmPublishingCredentialsPoliciesEntity)
_generic_site_operation(cmd.cli_ctx, resource_group, app_name,
'update_scm_allowed', slot_name, csmPublishingCredentialsPoliciesEntity)


def _validate_vnet_integration_location(cmd, subnet_resource_group, vnet_name, webapp_location, vnet_sub_id=None):
from azure.cli.core.commands.client_factory import get_subscription_id

Expand Down Expand Up @@ -818,7 +831,7 @@ def get_webapp(cmd, resource_group_name, name, slot=None):
return _generic_site_operation(cmd.cli_ctx, resource_group_name, name, 'get', slot)


def set_webapp(cmd, resource_group_name, name, slot=None, skip_dns_registration=None, # pylint: disable=unused-argument
def set_webapp(cmd, resource_group_name, name, slot=None, skip_dns_registration=None, basic_auth="", # pylint: disable=unused-argument
skip_custom_domain_verification=None, force_dns_registration=None, ttl_in_seconds=None, **kwargs): # pylint: disable=unused-argument
instance = kwargs['parameters']
client = web_client_factory(cmd.cli_ctx)
Expand All @@ -827,6 +840,8 @@ def set_webapp(cmd, resource_group_name, name, slot=None, skip_dns_registration=
if slot:
kwargs['slot'] = slot

_enable_basic_auth(cmd, name, slot, resource_group_name, basic_auth.lower())

return updater(**kwargs)


Expand Down Expand Up @@ -5110,7 +5125,7 @@ def get_history_triggered_webjob(cmd, resource_group_name, name, webjob_name, sl

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,
app_service_environment=None, track_status=False):
app_service_environment=None, track_status=False, basic_auth=""):
if not name:
name = generate_default_app_name(cmd)

Expand Down Expand Up @@ -5280,6 +5295,9 @@ def webapp_up(cmd, name=None, resource_group_name=None, plan=None, location=None
if match:
_update_app_settings_for_windows_if_needed(cmd, rg_name, name, match, site_config, runtime_version)
create_json['runtime_version'] = runtime_version

_enable_basic_auth(cmd, name, None, resource_group_name, basic_auth.lower())

# Zip contents & Deploy
logger.warning("Creating zip with contents of dir %s ...", src_dir)
# zip contents & deploy
Expand Down
Loading