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
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,14 @@ def validate_onedeploy_params(namespace):
raise RequiredArgumentMissingError('Deployment type is mandatory when deploying from URLs. Use --type')


def validate_onedeploy_functionapp_params(cmd, namespace):
validate_onedeploy_params(namespace)
from azure.cli.core.cloud import AZURE_PUBLIC_CLOUD
if cmd.cli_ctx.cloud.name != AZURE_PUBLIC_CLOUD.name:
raise ValidationError("The 'az functionapp deploy' command is currently available only in AzureCloud. "
"Use 'az functionapp deployment source config-zip' in this cloud.")


def _validate_ip_address_format(namespace):
if namespace.ip_address is not None:
input_value = namespace.ip_address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from azure.cli.core.util import empty_on_404

from ._client_factory import cf_web_client, cf_plans, cf_webapps
from ._validators import (validate_onedeploy_params, validate_staticsite_link_function, validate_staticsite_sku,
from ._validators import (validate_onedeploy_params, validate_onedeploy_functionapp_params, validate_staticsite_link_function, validate_staticsite_sku,
validate_vnet_integration, validate_asp_create, validate_functionapp_asp_create,
validate_webapp_up, validate_app_exists, validate_add_vnet, validate_app_is_functionapp,
validate_app_is_webapp, validate_functionapp_on_containerapp_vnet,
Expand Down Expand Up @@ -382,7 +382,7 @@ def load_command_table(self, _):
g.custom_command('identity assign', 'assign_identity')
g.custom_show_command('identity show', 'show_identity')
g.custom_command('identity remove', 'remove_identity')
g.custom_command('deploy', 'perform_onedeploy_functionapp', validator=validate_onedeploy_params, is_preview=True)
g.custom_command('deploy', 'perform_onedeploy_functionapp', validator=validate_onedeploy_functionapp_params, is_preview=True)
g.generic_update_command('update', getter_name="get_functionapp", setter_name='set_functionapp', exception_handler=update_function_ex_handler_factory(),
custom_func_name='update_functionapp', getter_type=appservice_custom, setter_type=appservice_custom, command_type=webapp_sdk,
validator=validate_functionapp_on_containerapp_update)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
import unittest
from unittest import mock

from azure.cli.core.azclierror import ArgumentUsageError
from azure.cli.core.azclierror import ArgumentUsageError, ValidationError

from azure.cli.command_modules.appservice._validators import (
_normalize_http_headers,
_normalize_ip_address_list,
_validate_ip_address_existence,
_validate_service_tag_existence,
validate_onedeploy_functionapp_params,
)


Expand Down Expand Up @@ -249,6 +250,31 @@ def test_namespace_without_http_headers_attr(self):
self.fail('Missing http_headers attribute should be treated as no headers')


class ValidateFunctionappOneDeployParamsTest(unittest.TestCase):
def _make_namespace(self):
ns = mock.MagicMock()
ns.src_path = 'artifact.zip'
ns.src_url = None
ns.artifact_type = None
return ns

def test_allowed_in_public_cloud(self):
cmd = mock.MagicMock()
cmd.cli_ctx.cloud.name = 'AzureCloud'

validate_onedeploy_functionapp_params(cmd, self._make_namespace())

def test_blocked_in_non_public_cloud(self):
cmd = mock.MagicMock()
cmd.cli_ctx.cloud.name = 'AzureUSGovernment'

with self.assertRaises(ValidationError) as ctx:
validate_onedeploy_functionapp_params(cmd, self._make_namespace())

self.assertIn('available only in AzureCloud', str(ctx.exception))
self.assertIn('deployment source config-zip', str(ctx.exception))


class ValidateServiceTagExistenceTest(unittest.TestCase):
def _make_namespace(self, service_tag, http_headers=None, scm_site=False):
ns = mock.MagicMock()
Expand Down