Skip to content

Commit

Permalink
Change PUT to PATCH for update command (#6930)
Browse files Browse the repository at this point in the history
* Change PUT to PATCH for update command

* Update tests

* Remove whitespace

---------

Co-authored-by: Alan Zhang <alanzhang@microsoft.com>
  • Loading branch information
ABZhang0 and Alan Zhang committed Nov 1, 2023
1 parent e4fc6a9 commit d3182c3
Show file tree
Hide file tree
Showing 7 changed files with 1,788 additions and 2,187 deletions.
42 changes: 25 additions & 17 deletions src/amg/azext_amg/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,46 +175,54 @@ def update_grafana(cmd, grafana_name, api_key_and_service_account=None, determin
client = cf_amg(cmd.cli_ctx, subscription=None)
instance = client.grafana.get(resource_group_name, grafana_name)

resource = {}
resourceProperties = {}

if api_key_and_service_account:
instance.properties.api_key = api_key_and_service_account
resourceProperties["apiKey"] = api_key_and_service_account

if deterministic_outbound_ip:
instance.properties.deterministic_outbound_ip = deterministic_outbound_ip
resourceProperties["deterministicOutboundIP"] = deterministic_outbound_ip

if public_network_access:
instance.properties.public_network_access = public_network_access
resourceProperties["publicNetworkAccess"] = public_network_access

if tags:
instance.tags = tags
resource["tags"] = tags

if (smtp or host or user or password or start_tls_policy
or from_address or from_name or skip_verify is not None):

from azext_amg.vendored_sdks.models import GrafanaConfigurations, Smtp
if not instance.properties.grafana_configurations:
instance.properties.grafana_configurations = GrafanaConfigurations()
resourceProperties["grafanaConfigurations"] = GrafanaConfigurations()

if not instance.properties.grafana_configurations.smtp:
instance.properties.grafana_configurations.smtp = Smtp()
resourceProperties["grafanaConfigurations"].smtp = Smtp()
else:
resourceProperties["grafanaConfigurations"] = instance.properties.grafana_configurations

if smtp:
instance.properties.grafana_configurations.smtp.enabled = (smtp == "Enabled")
resourceProperties["grafanaConfigurations"].smtp.enabled = (smtp == "Enabled")
if host:
instance.properties.grafana_configurations.smtp.host = host
resourceProperties["grafanaConfigurations"].smtp.host = host
if user:
instance.properties.grafana_configurations.smtp.user = user
resourceProperties["grafanaConfigurations"].smtp.user = user
if password:
instance.properties.grafana_configurations.smtp.password = password
resourceProperties["grafanaConfigurations"].smtp.password = password
if start_tls_policy:
instance.properties.grafana_configurations.smtp.start_tls_policy = start_tls_policy
resourceProperties["grafanaConfigurations"].smtp.start_tls_policy = start_tls_policy
if skip_verify is not None:
instance.properties.grafana_configurations.smtp.skip_verify = skip_verify
resourceProperties["grafanaConfigurations"].smtp.skip_verify = skip_verify
if from_address:
instance.properties.grafana_configurations.smtp.from_address = from_address
resourceProperties["grafanaConfigurations"].smtp.from_address = from_address
if from_name:
instance.properties.grafana_configurations.smtp.from_name = from_name
resourceProperties["grafanaConfigurations"].smtp.from_name = from_name

if resourceProperties:
resource["properties"] = resourceProperties

# "begin_create" uses PUT, which handles both Create and Update
return client.grafana.begin_create(resource_group_name, grafana_name, instance)
# "update" uses PATCH
return client.grafana.update(resource_group_name, grafana_name, resource)


def show_grafana(cmd, grafana_name, resource_group_name=None, subscription=None):
Expand Down
1,834 changes: 894 additions & 940 deletions src/amg/azext_amg/tests/latest/recordings/test_amg_backup_restore.yaml

Large diffs are not rendered by default.

553 changes: 226 additions & 327 deletions src/amg/azext_amg/tests/latest/recordings/test_amg_crud.yaml

Large diffs are not rendered by default.

1,040 changes: 395 additions & 645 deletions src/amg/azext_amg/tests/latest/recordings/test_amg_e2e.yaml

Large diffs are not rendered by default.

215 changes: 105 additions & 110 deletions src/amg/azext_amg/tests/latest/recordings/test_api_key_e2e.yaml

Large diffs are not rendered by default.

289 changes: 142 additions & 147 deletions src/amg/azext_amg/tests/latest/recordings/test_service_account_e2e.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/amg/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

# TODO: Confirm this is the right version number you want and it matches your
# HISTORY.rst entry.
VERSION = '1.2.8'
VERSION = '1.2.9'

# The full list of classifiers is available at
# https://pypi.python.org/pypi?%3Aaction=list_classifiers
Expand Down

0 comments on commit d3182c3

Please sign in to comment.