-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[staticwebapp] Add Static Web App extension #5819
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
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
613590f
start SWA hawaii commands
StrawnSC 8bfad38
TODO
StrawnSC 8568d17
refactor DB-dependent logic
StrawnSC 845b6b4
add connection string logic for non-pgsql databases
StrawnSC 72fd1dd
add params and pgsql flex connection string logic
StrawnSC 1e4b2c7
add connection string logic for pgsql single; minor refactor
StrawnSC b3bcaae
finish DB connection string logic; add warning text for providing unn…
StrawnSC 8ba5377
start style fixes
StrawnSC 3714589
merge
StrawnSC 448677a
Merge branch 'main' into swa-dbconnection
StrawnSC ebe018e
remove connection string overriding; use DB server RIDs instead of DB…
StrawnSC 86fd990
update for change in detailed show API
StrawnSC ed5ea02
bump version for test
StrawnSC 845ef3d
allow creating db connection on the site and not just the build
StrawnSC d58d7c6
connection string auth tests
StrawnSC 7243217
fix
StrawnSC bfc0d43
mark command group as preview
StrawnSC 2016b07
Merge branch 'swa-dbconnection-builds' into swa-dbconnection
StrawnSC 07f6f21
change logic for SWA builds
StrawnSC b293ffe
fix style/linter issues
StrawnSC c950bd2
fix codeowners
StrawnSC 2dccd53
update connection string formats
StrawnSC e314e1a
fix exception on delete
StrawnSC b754af2
update initial release version
StrawnSC d89fb2b
Update src/staticwebapp/azext_staticwebapp/_help.py
zhoxing-ms 11b3ba3
Apply suggestions from code review
zhoxing-ms 8b80723
Apply suggestions from code review
zhoxing-ms 0046229
Update src/staticwebapp/azext_staticwebapp/azext_metadata.json
zhoxing-ms da969a2
rerecord failing tests
StrawnSC 6e62dcc
add confirmation to delete command; inform user of the supported conn…
StrawnSC File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| .. :changelog: | ||
|
|
||
| Release History | ||
| =============== | ||
|
|
||
| 1.0.0 | ||
| ++++++ | ||
| * Add commands to manage Static Web App database connections: `az staticwebapp dbconnection create/show/delete` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| Microsoft Azure CLI 'staticwebapp' Extension | ||
| ========================================== | ||
|
|
||
| This package is for the 'staticwebapp' extension. | ||
| i.e. 'az staticwebapp' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
|
|
||
| from azure.cli.core import AzCommandsLoader | ||
|
|
||
| from azext_staticwebapp._help import helps # pylint: disable=unused-import | ||
|
|
||
|
|
||
| class StaticwebappCommandsLoader(AzCommandsLoader): | ||
|
|
||
| def __init__(self, cli_ctx=None): | ||
| from azure.cli.core.commands import CliCommandType | ||
| staticwebapp_custom = CliCommandType( | ||
| operations_tmpl='azext_staticwebapp.custom#{}', | ||
| client_factory=None) | ||
| super(StaticwebappCommandsLoader, self).__init__(cli_ctx=cli_ctx, | ||
| custom_command_type=staticwebapp_custom) | ||
|
|
||
| def load_command_table(self, args): | ||
| from azext_staticwebapp.commands import load_command_table | ||
| load_command_table(self, args) | ||
| return self.command_table | ||
|
|
||
| def load_arguments(self, command): | ||
| from azext_staticwebapp._params import load_arguments | ||
| load_arguments(self, command) | ||
|
|
||
|
|
||
| COMMAND_LOADER_CLS = StaticwebappCommandsLoader |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
|
|
||
| import json | ||
|
|
||
| from azure.cli.core.util import send_raw_request | ||
| from azure.cli.core.commands.client_factory import get_subscription_id | ||
|
|
||
|
|
||
| API_VERSION = "2022-03-01" | ||
|
|
||
|
|
||
| class DbConnectionClient(): | ||
| @classmethod | ||
| def create_or_update(cls, cmd, resource_group_name, name, environment, connection_name="default", | ||
| db_connection=None): | ||
| management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager | ||
| api_version = API_VERSION | ||
| sub_id = get_subscription_id(cmd.cli_ctx) | ||
| if environment: | ||
| url_fmt = ("{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.Web/staticsites/{}/builds/{}" | ||
| "/databaseConnections/{}?api-version={}") | ||
| request_url = url_fmt.format( | ||
| management_hostname.strip('/'), | ||
| sub_id, | ||
| resource_group_name, | ||
| name, | ||
| environment, | ||
| connection_name, | ||
| api_version) | ||
| else: | ||
| url_fmt = ("{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.Web/staticsites/{}" | ||
| "/databaseConnections/{}?api-version={}") | ||
| request_url = url_fmt.format( | ||
| management_hostname.strip('/'), | ||
| sub_id, | ||
| resource_group_name, | ||
| name, | ||
| connection_name, | ||
| api_version) | ||
|
|
||
| r = send_raw_request(cmd.cli_ctx, "PUT", request_url, body=json.dumps(db_connection)) | ||
| return r.json() | ||
|
|
||
| @classmethod | ||
| def show(cls, cmd, resource_group_name, name, environment, connection_name="default", detailed=False): | ||
| management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager | ||
| api_version = API_VERSION | ||
| sub_id = get_subscription_id(cmd.cli_ctx) | ||
| if environment: | ||
| url_fmt = ("{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.Web/staticsites/{}/builds/{}" | ||
| "/databaseConnections/{}?api-version={}") | ||
| request_url = url_fmt.format( | ||
| management_hostname.strip('/'), | ||
| sub_id, | ||
| resource_group_name, | ||
| name, | ||
| environment, | ||
| connection_name, | ||
| api_version) | ||
| else: | ||
| url_fmt = ("{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.Web/staticsites/{}" | ||
| "/databaseConnections/{}?api-version={}") | ||
| request_url = url_fmt.format( | ||
| management_hostname.strip('/'), | ||
| sub_id, | ||
| resource_group_name, | ||
| name, | ||
| connection_name, | ||
| api_version) | ||
|
|
||
| verb = "GET" if not detailed else "POST" | ||
|
|
||
| r = send_raw_request(cmd.cli_ctx, verb, request_url) | ||
| return r.json() | ||
|
|
||
| @classmethod | ||
| def list(cls, cmd, resource_group_name, name, environment, connection_name="default", detailed=False): | ||
| management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager | ||
| api_version = API_VERSION | ||
| sub_id = get_subscription_id(cmd.cli_ctx) | ||
| if environment: | ||
| url_fmt = ("{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.Web/staticsites/{}/builds/{}" | ||
| "/databaseConnections/{}?api-version={}") | ||
| request_url = url_fmt.format( | ||
| management_hostname.strip('/'), | ||
| sub_id, | ||
| resource_group_name, | ||
| name, | ||
| environment, | ||
| connection_name if not detailed else f"{connection_name}/show", | ||
| api_version) | ||
| else: | ||
| url_fmt = ("{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.Web/staticsites/{}" | ||
| "/databaseConnections/{}?api-version={}") | ||
| request_url = url_fmt.format( | ||
| management_hostname.strip('/'), | ||
| sub_id, | ||
| resource_group_name, | ||
| name, | ||
| connection_name if not detailed else f"{connection_name}/show", | ||
| api_version) | ||
|
|
||
| verb = "GET" if not detailed else "POST" | ||
|
|
||
| r = send_raw_request(cmd.cli_ctx, verb, request_url) | ||
| return r.json() | ||
|
|
||
| @classmethod | ||
| def delete(cls, cmd, resource_group_name, name, environment, connection_name="default"): | ||
| management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager | ||
| api_version = API_VERSION | ||
| sub_id = get_subscription_id(cmd.cli_ctx) | ||
| if environment: | ||
| url_fmt = ("{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.Web/staticsites/{}/builds/{}" | ||
| "/databaseConnections/{}?api-version={}") | ||
| request_url = url_fmt.format( | ||
| management_hostname.strip('/'), | ||
| sub_id, | ||
| resource_group_name, | ||
| name, | ||
| environment, | ||
| connection_name, | ||
| api_version) | ||
| else: | ||
| url_fmt = ("{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.Web/staticsites/{}" | ||
| "/databaseConnections/{}?api-version={}") | ||
| request_url = url_fmt.format( | ||
| management_hostname.strip('/'), | ||
| sub_id, | ||
| resource_group_name, | ||
| name, | ||
| connection_name, | ||
| api_version) | ||
|
|
||
| send_raw_request(cmd.cli_ctx, "DELETE", request_url) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # coding=utf-8 | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
|
|
||
| from knack.help_files import helps # pylint: disable=unused-import | ||
|
|
||
|
|
||
| helps['staticwebapp dbconnection'] = """ | ||
| type: group | ||
| short-summary: Manage Static Web App database connections. | ||
| """ | ||
|
|
||
| helps['staticwebapp dbconnection create'] = """ | ||
| type: command | ||
| short-summary: Create a Static Web App database connection. | ||
| """ | ||
|
|
||
| helps['staticwebapp dbconnection show'] = """ | ||
| type: command | ||
| short-summary: Get details for a Static Web App database connection. | ||
| """ | ||
|
|
||
| helps['staticwebapp dbconnection delete'] = """ | ||
| type: command | ||
| short-summary: Delete a Static Web App database connection. | ||
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| DbConnection = { | ||
| "properties": { | ||
| "resourceId": None, | ||
| "connectionIdentity": None, | ||
| "region": None, | ||
| "connectionString": None, | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| def load_arguments(self, _): | ||
|
|
||
| from azure.cli.core.commands.parameters import resource_group_name_type | ||
|
|
||
| with self.argument_context('staticwebapp dbconnection') as c: | ||
| c.argument('name', options_list=['--name', '-n'], help="Name of the Static Web App.") | ||
| c.argument('resource_group_name', resource_group_name_type) | ||
| c.argument('environment', help="Name of the environment of Static Web App.", | ||
| options_list=["--environment", "-e"]) | ||
|
|
||
| with self.argument_context('staticwebapp dbconnection create') as c: | ||
| c.argument('db_resource_id', options_list=['--db-resource-id', '-d'], | ||
| help="The azure resource ID for the database server/account to connect to e.g. '/subscriptions/MySubId/resourceGroups/MyResourceGroup/providers/Microsoft.Sql/servers/MyServer' for an Azure SQL database.") | ||
| c.argument('db_name', options_list=['--db-name', '-b'], help="The name of the database to connect to. Not required for CosmosDB.") | ||
| c.argument('username', options_list=["--username", "-u"], help="The username to use for authentication with the database. Not required for all databases.") | ||
| c.argument('password', options_list=["--password", "-p"], help="The password to use for authentication with the database. Not required for all databases.") | ||
| c.argument('mi_user_assigned', options_list=["--mi-user-assigned", "-i"], help="A resource ID for a user-assigned managed identity to use for auth with the database. Must be assigned to the Static Web App and have the right permissions on the database.") | ||
|
zhoxing-ms marked this conversation as resolved.
|
||
| c.argument('mi_system_assigned', options_list=["--mi-system-assigned", "-s"], help="Use the Static Web App's system-assigned identity for auth with the database. Must be assigned to the Static Web App and have the right permissions on the database.") | ||
|
|
||
| with self.argument_context('staticwebapp dbconnection show') as c: | ||
| c.argument('detailed', options_list=['--detailed', '-d'], action='store_true', | ||
| default=False, help="Get detailed information on database connections.") | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.