From 75d03e09151d522f9679191860426b330df49470 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Wed, 14 Sep 2022 21:00:20 +0000 Subject: [PATCH 1/8] [appservice] `az staticwebapp functions link`: Add environment-name parameter --- .../cli/command_modules/appservice/static_sites.py | 10 +++++++++- .../tests/latest/test_staticapp_commands_thru_mock.py | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/appservice/static_sites.py b/src/azure-cli/azure/cli/command_modules/appservice/static_sites.py index f37a2dc9cb0..a99000f6777 100644 --- a/src/azure-cli/azure/cli/command_modules/appservice/static_sites.py +++ b/src/azure-cli/azure/cli/command_modules/appservice/static_sites.py @@ -562,7 +562,14 @@ def reset_staticsite_api_key(cmd, name, resource_group_name=None): reset_properties_envelope=reset_envelope) -def link_user_function(cmd, name, resource_group_name, function_resource_id, force=False): +def link_user_function( + cmd, + name, + resource_group_name, + function_resource_id, + environment_name: str = "default", + force=False, +): from azure.mgmt.web.models import StaticSiteUserProvidedFunctionAppARMResource if force: @@ -581,6 +588,7 @@ def link_user_function(cmd, name, resource_group_name, function_resource_id, for name=name, resource_group_name=resource_group_name, function_app_name=function_name, + environment_name=environment_name, static_site_user_provided_function_envelope=function, is_forced=force) diff --git a/src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_staticapp_commands_thru_mock.py b/src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_staticapp_commands_thru_mock.py index 203c7d9d8d4..381529701c1 100644 --- a/src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_staticapp_commands_thru_mock.py +++ b/src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_staticapp_commands_thru_mock.py @@ -597,7 +597,7 @@ def test_functions_link(self, *args, **kwargs): functionapp_resource_id = "/subscriptions/sub/resourceGroups/{}/providers/Microsoft.Web/sites/{}".format( self.rg1, functionapp_name ) - link_user_function(self.mock_cmd, self.name1, self.rg1, functionapp_resource_id) + link_user_function(self.mock_cmd, self.name1, self.rg1, functionapp_resource_id, self.environment1) self.staticapp_client.begin_register_user_provided_function_app_with_static_site.assert_called_once() From ea96db0b9c628cb385fa451154441d909265e956 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Wed, 14 Sep 2022 21:19:03 +0000 Subject: [PATCH 2/8] Add param --- src/azure-cli/azure/cli/command_modules/appservice/_params.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/azure-cli/azure/cli/command_modules/appservice/_params.py b/src/azure-cli/azure/cli/command_modules/appservice/_params.py index 99cf1527da3..a701188deec 100644 --- a/src/azure-cli/azure/cli/command_modules/appservice/_params.py +++ b/src/azure-cli/azure/cli/command_modules/appservice/_params.py @@ -1110,6 +1110,7 @@ def load_arguments(self, _): c.argument('sku', arg_type=static_web_app_sku_arg_type) with self.argument_context('staticwebapp functions link') as c: c.argument('function_resource_id', help="Resource ID of the functionapp to link. Can be retrieved with 'az functionapp --query id'") + c.argument('environment_name', options_list=['--environment-name'], help="Name of the environment of static site") c.argument('force', help="Force the function link even if the function is already linked to a static webapp. May be needed if the function was previously linked to a static webapp.") with self.argument_context('staticwebapp enterprise-edge') as c: From 7f1de8a56dcc1d92f83401bf3df6b82c9acc4dcf Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Fri, 16 Sep 2022 12:31:29 +0200 Subject: [PATCH 3/8] Use correct function --- .../azure/cli/command_modules/appservice/static_sites.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/azure-cli/azure/cli/command_modules/appservice/static_sites.py b/src/azure-cli/azure/cli/command_modules/appservice/static_sites.py index a99000f6777..d4828f1c6e9 100644 --- a/src/azure-cli/azure/cli/command_modules/appservice/static_sites.py +++ b/src/azure-cli/azure/cli/command_modules/appservice/static_sites.py @@ -584,7 +584,7 @@ def link_user_function( function = StaticSiteUserProvidedFunctionAppARMResource(function_app_resource_id=function_resource_id, function_app_region=function_location) - return client.begin_register_user_provided_function_app_with_static_site( + return client.begin_register_user_provided_function_app_with_static_site_build( name=name, resource_group_name=resource_group_name, function_app_name=function_name, From 12e405a437d91aa815af74a57d2ca4b484447916 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Tue, 25 Oct 2022 11:20:27 +0200 Subject: [PATCH 4/8] fix test --- .../tests/latest/test_staticapp_commands_thru_mock.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_staticapp_commands_thru_mock.py b/src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_staticapp_commands_thru_mock.py index 381529701c1..c6e4257e584 100644 --- a/src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_staticapp_commands_thru_mock.py +++ b/src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_staticapp_commands_thru_mock.py @@ -599,7 +599,7 @@ def test_functions_link(self, *args, **kwargs): ) link_user_function(self.mock_cmd, self.name1, self.rg1, functionapp_resource_id, self.environment1) - self.staticapp_client.begin_register_user_provided_function_app_with_static_site.assert_called_once() + self.staticapp_client.begin_register_user_provided_function_app_with_static_site_build.assert_called_once() @mock.patch("azure.cli.command_modules.appservice.static_sites.get_user_function", return_value=[mock.MagicMock()]) def test_functions_unlink(self, *args, **kwargs): From ba105ad3a1c694e291ae88ad92d5ae1edbfcc088 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Thu, 10 Nov 2022 22:39:37 +0000 Subject: [PATCH 5/8] add special case for no env --- .../cli/command_modules/appservice/static_sites.py | 11 ++++++++++- .../tests/latest/test_staticapp_commands_thru_mock.py | 10 ++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/azure-cli/azure/cli/command_modules/appservice/static_sites.py b/src/azure-cli/azure/cli/command_modules/appservice/static_sites.py index d4828f1c6e9..7e1cd1c5b2e 100644 --- a/src/azure-cli/azure/cli/command_modules/appservice/static_sites.py +++ b/src/azure-cli/azure/cli/command_modules/appservice/static_sites.py @@ -567,7 +567,7 @@ def link_user_function( name, resource_group_name, function_resource_id, - environment_name: str = "default", + environment_name: str, force=False, ): from azure.mgmt.web.models import StaticSiteUserProvidedFunctionAppARMResource @@ -584,6 +584,15 @@ def link_user_function( function = StaticSiteUserProvidedFunctionAppARMResource(function_app_resource_id=function_resource_id, function_app_region=function_location) + if environment_name is None: + # Special casing since the type of the created resource differ + return client.begin_register_user_provided_function_app_with_static_site( + name=name, + resource_group_name=resource_group_name, + function_app_name=function_name, + static_site_user_provided_function_envelope=function, + is_forced=force) + return client.begin_register_user_provided_function_app_with_static_site_build( name=name, resource_group_name=resource_group_name, diff --git a/src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_staticapp_commands_thru_mock.py b/src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_staticapp_commands_thru_mock.py index c6e4257e584..67aa9efe9c2 100644 --- a/src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_staticapp_commands_thru_mock.py +++ b/src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_staticapp_commands_thru_mock.py @@ -593,6 +593,16 @@ def test_reset_staticsite_api_key(self): @mock.patch("azure.cli.command_modules.appservice.static_sites.show_app") def test_functions_link(self, *args, **kwargs): + functionapp_name = "functionapp" + functionapp_resource_id = "/subscriptions/sub/resourceGroups/{}/providers/Microsoft.Web/sites/{}".format( + self.rg1, functionapp_name + ) + link_user_function(self.mock_cmd, self.name1, self.rg1, functionapp_resource_id) + + self.staticapp_client.begin_register_user_provided_function_app_with_static_site.assert_called_once() + + @mock.patch("azure.cli.command_modules.appservice.static_sites.show_app") + def test_functions_link_with_environment(self, *args, **kwargs): functionapp_name = "functionapp" functionapp_resource_id = "/subscriptions/sub/resourceGroups/{}/providers/Microsoft.Web/sites/{}".format( self.rg1, functionapp_name From 32d8061005260f9d6d4da0be9145626a260f33bb Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Fri, 11 Nov 2022 10:41:03 +0000 Subject: [PATCH 6/8] fix test --- .../tests/latest/test_staticapp_commands_thru_mock.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_staticapp_commands_thru_mock.py b/src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_staticapp_commands_thru_mock.py index 67aa9efe9c2..4461fcb0da2 100644 --- a/src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_staticapp_commands_thru_mock.py +++ b/src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_staticapp_commands_thru_mock.py @@ -597,7 +597,7 @@ def test_functions_link(self, *args, **kwargs): functionapp_resource_id = "/subscriptions/sub/resourceGroups/{}/providers/Microsoft.Web/sites/{}".format( self.rg1, functionapp_name ) - link_user_function(self.mock_cmd, self.name1, self.rg1, functionapp_resource_id) + link_user_function(self.mock_cmd, self.name1, self.rg1, functionapp_resource_id, None) self.staticapp_client.begin_register_user_provided_function_app_with_static_site.assert_called_once() From 235c822f0f994273631162bfa2aa88be0758a0bc Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Wed, 4 Jan 2023 14:54:59 +0100 Subject: [PATCH 7/8] Update src/azure-cli/azure/cli/command_modules/appservice/static_sites.py Co-authored-by: Xing Zhou --- .../azure/cli/command_modules/appservice/static_sites.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/azure-cli/azure/cli/command_modules/appservice/static_sites.py b/src/azure-cli/azure/cli/command_modules/appservice/static_sites.py index 7e1cd1c5b2e..b707c4edec6 100644 --- a/src/azure-cli/azure/cli/command_modules/appservice/static_sites.py +++ b/src/azure-cli/azure/cli/command_modules/appservice/static_sites.py @@ -567,7 +567,7 @@ def link_user_function( name, resource_group_name, function_resource_id, - environment_name: str, + environment_name=None, force=False, ): from azure.mgmt.web.models import StaticSiteUserProvidedFunctionAppARMResource From ef7daa962779693221bd668d988406f96570daa3 Mon Sep 17 00:00:00 2001 From: Xing Zhou Date: Thu, 5 Jan 2023 11:10:59 +0800 Subject: [PATCH 8/8] Update src/azure-cli/azure/cli/command_modules/appservice/_params.py --- src/azure-cli/azure/cli/command_modules/appservice/_params.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/azure-cli/azure/cli/command_modules/appservice/_params.py b/src/azure-cli/azure/cli/command_modules/appservice/_params.py index 6afa7d08f0b..9ace7ca44ae 100644 --- a/src/azure-cli/azure/cli/command_modules/appservice/_params.py +++ b/src/azure-cli/azure/cli/command_modules/appservice/_params.py @@ -1102,7 +1102,7 @@ def load_arguments(self, _): c.argument('sku', arg_type=static_web_app_sku_arg_type) with self.argument_context('staticwebapp functions link') as c: c.argument('function_resource_id', help="Resource ID of the functionapp to link. Can be retrieved with 'az functionapp --query id'") - c.argument('environment_name', options_list=['--environment-name'], help="Name of the environment of static site") + c.argument('environment_name', help="Name of the environment of static site") c.argument('force', help="Force the function link even if the function is already linked to a static webapp. May be needed if the function was previously linked to a static webapp.") with self.argument_context('staticwebapp enterprise-edge') as c: