Skip to content

Commit

Permalink
webapp/functionapp: support cors (Azure#7038)
Browse files Browse the repository at this point in the history
  • Loading branch information
yugangw-msft authored Aug 15, 2018
1 parent dbaaea9 commit 8f4e460
Show file tree
Hide file tree
Showing 8 changed files with 1,323 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/command_modules/azure-cli-appservice/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Release History

0.2.3
+++++
* support CORS on functionapp & webapp
* arm tag support on create commands

0.2.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,37 @@
short-summary: Clear the routing rules and send all traffic to production.
"""

helps['webapp cors'] = """
type: group
short-summary: Manage Cross-Origin Resource Sharing (CORS)
"""

helps['webapp cors add'] = """
type: command
short-summary: Add allowed origins
examples:
- name: add a new allowed origin
text: >
az webapp cors add -g <myRG> -n <myAppName> --allowed-origins https://myapps.com
"""

helps['webapp cors remove'] = """
type: command
short-summary: Remove allowed origins
examples:
- name: remove an allowed origin
text: >
az webapp cors remove -g <myRG> -n <myAppName> --allowed-origins https://myapps.com
- name: remove all allowed origins
text: >
az webapp cors add -g <myRG> -n <myAppName> --allowed-origins
"""

helps['webapp cors show'] = """
type: command
short-summary: show allowed origins
"""

helps['appservice plan'] = """
type: group
short-summary: Manage app service plans.
Expand Down Expand Up @@ -782,3 +813,34 @@
-g <myRG> -n <myAppName> \\
--src <zip file path location>
"""

helps['functionapp cors'] = """
type: group
short-summary: Manage Cross-Origin Resource Sharing (CORS)
"""

helps['functionapp cors add'] = """
type: command
short-summary: Add allowed origins
examples:
- name: add a new allowed origin
text: >
az functionapp cors add -g <myRG> -n <myAppName> --allowed-origins https://myapps.com
"""

helps['functionapp cors remove'] = """
type: command
short-summary: Remove allowed origins
examples:
- name: remove an allowed origin
text: >
az functionapp cors add -g <myRG> -n <myAppName> --allowed-origins https://myapps.com
- name: remove all allowed origins
text: >
az functionapp cors add -g <myRG> -n <myAppName> --allowed-origins
"""

helps['functionapp cors show'] = """
type: command
short-summary: show allowed origins
"""
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ def load_arguments(self, _):
with self.argument_context(scope + ' config hostname list') as c:
c.argument('webapp_name', arg_type=webapp_name_arg_type, id_part=None, options_list='--webapp-name')

with self.argument_context(scope + ' cors') as c:
c.argument('allowed_origins', options_list=['--allowed-origins', '-a'], nargs='*', help='space separated origins that should be allowed to make cross-origin calls (for example: http://example.com:12345). To allow all, use "*" and remove all other origins from the list')

with self.argument_context('webapp config connection-string list') as c:
c.argument('name', arg_type=webapp_name_arg_type, id_part=None)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ def load_command_table(self, _):
g.custom_show_command('show', 'show_traffic_routing')
g.custom_command('clear', 'clear_traffic_routing')

with self.command_group('webapp cors') as g:
g.custom_command('add', 'add_cors')
g.custom_command('remove', 'remove_cors')
g.custom_command('show', 'show_cors')

with self.command_group('webapp config') as g:
g.custom_command('set', 'update_site_configs')
g.custom_show_command('show', 'get_site_configs')
Expand Down Expand Up @@ -220,3 +225,8 @@ def load_command_table(self, _):

with self.command_group('functionapp deployment') as g:
g.custom_command('list-publishing-profiles', 'list_publish_profiles')

with self.command_group('functionapp cors') as g:
g.custom_command('add', 'add_cors')
g.custom_command('remove', 'remove_cors')
g.custom_command('show', 'show_cors')
Original file line number Diff line number Diff line change
Expand Up @@ -1371,6 +1371,32 @@ def clear_traffic_routing(cmd, resource_group_name, name):
set_traffic_routing(cmd, resource_group_name, name, [])


def add_cors(cmd, resource_group_name, name, allowed_origins, slot=None):
from azure.mgmt.web.models import CorsSettings
configs = get_site_configs(cmd, resource_group_name, name, slot)
if not configs.cors:
configs.cors = CorsSettings()
configs.cors.allowed_origins = (configs.cors.allowed_origins or []) + allowed_origins
result = _generic_site_operation(cmd.cli_ctx, resource_group_name, name, 'update_configuration', slot, configs)
return result.cors


def remove_cors(cmd, resource_group_name, name, allowed_origins, slot=None):
configs = get_site_configs(cmd, resource_group_name, name, slot)
if configs.cors:
if allowed_origins:
configs.cors.allowed_origins = [x for x in (configs.cors.allowed_origins or []) if x not in allowed_origins]
else:
configs.cors.allowed_origins = []
configs = _generic_site_operation(cmd.cli_ctx, resource_group_name, name, 'update_configuration', slot, configs)
return configs.cors


def show_cors(cmd, resource_group_name, name, slot=None):
configs = get_site_configs(cmd, resource_group_name, name, slot)
return configs.cors


def get_streaming_log(cmd, resource_group_name, name, provider=None, slot=None):
scm_url = _get_scm_url(cmd, resource_group_name, name, slot)
streaming_url = scm_url + '/logstream'
Expand Down
Loading

0 comments on commit 8f4e460

Please sign in to comment.