Skip to content

Commit

Permalink
redact connection-string set/delete output for webapp and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amberwang113 committed Oct 20, 2023
1 parent e37059d commit 6be01c7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
18 changes: 14 additions & 4 deletions src/azure-cli/azure/cli/command_modules/appservice/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -1667,7 +1667,7 @@ def update_connection_strings(cmd, resource_group_name, name, connection_string_
slot_cfg_names.connection_string_names -= rm_sticky_slot_settings
client.web_apps.update_slot_configuration_names(resource_group_name, name, slot_cfg_names)

return result.properties
return _redact_connection_strings(result.properties)


def delete_connection_strings(cmd, resource_group_name, name, setting_names, slot=None):
Expand All @@ -1686,9 +1686,19 @@ def delete_connection_strings(cmd, resource_group_name, name, setting_names, slo
if is_slot_settings:
client.web_apps.update_slot_configuration_names(resource_group_name, name, slot_cfg_names)

return _generic_settings_operation(cmd.cli_ctx, resource_group_name, name,
'update_connection_strings',
conn_strings, slot, client)
result = _generic_settings_operation(cmd.cli_ctx, resource_group_name, name,
'update_connection_strings',
conn_strings, slot, client)
_redact_connection_strings(result.properties)
return result


def _redact_connection_strings(properties):
logger.warning('Connection string values have been redacted. '
'Use `az webapp config connection-string list` to view.')
for setting in properties:
properties[setting].value = None
return properties


CONTAINER_APPSETTING_NAMES = ['DOCKER_REGISTRY_SERVER_URL', 'DOCKER_REGISTRY_SERVER_USERNAME',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,11 @@ def test_webapp_config(self, resource_group):

# site connection string tests
self.cmd('webapp config connection-string set -t mysql -g {} -n {} --settings c1="conn1" c2=conn2 '
'--slot-settings c3=conn3'.format(resource_group, linux_webapp))
'--slot-settings c3=conn3'
.format(resource_group, linux_webapp)).assert_with_checks([
JMESPathCheck("[?name=='c1']|[0].value", None),
JMESPathCheck("[?name=='c2']|[0].value", None)
])
self.cmd('webapp config connection-string list -g {} -n {}'
.format(resource_group, linux_webapp)).assert_with_checks([
JMESPathCheck('length([])', 3),
Expand All @@ -772,7 +776,7 @@ def test_webapp_config(self, resource_group):
JMESPathCheck("[?name=='c2']|[0].slotSetting", False),
JMESPathCheck("[?name=='c3']|[0].slotSetting", True)])
self.cmd('webapp config connection-string delete -g {} -n {} --setting-names c1 c3'
.format(resource_group, linux_webapp))
.format(resource_group, linux_webapp)).assert_with_checks([JMESPathCheck("[?name=='c2']|[0].value", None)])
self.cmd('webapp config connection-string list -g {} -n {}'
.format(resource_group, linux_webapp)).assert_with_checks([
JMESPathCheck('length([])', 1),
Expand All @@ -782,7 +786,11 @@ def test_webapp_config(self, resource_group):
test_json = os.path.join(TEST_DIR, 'test.json')
print(test_json)
self.cmd('webapp config connection-string set -g {} -n {} --settings "@{}"'
.format(resource_group, linux_webapp, test_json))
.format(resource_group, linux_webapp, test_json)).assert_with_checks([
JMESPathCheck("[?name=='c1']|[0].value", None),
JMESPathCheck("[?name=='c2']|[0].value", None),
JMESPathCheck("[?name=='c3']|[0].value", None),
JMESPathCheck("[?name=='c4']|[0].value", None),])
self.cmd('webapp config connection-string list -g {} -n {}'
.format(resource_group, linux_webapp)).assert_with_checks([
JMESPathCheck('length([])', 4),
Expand Down Expand Up @@ -1373,7 +1381,11 @@ def test_webapp_slot(self, resource_group):
JMESPathCheck("[?name=='s3']|[0].slotSetting", False),
])

self.cmd('webapp config connection-string set -g {} -n {} -t mysql --slot {} --settings c1=connection1 --slot-settings c2=connection2'.format(resource_group, webapp, slot2))
self.cmd('webapp config connection-string set -g {} -n {} -t mysql --slot {} --settings c1=connection1 --slot-settings c2=connection2'
.format(resource_group, webapp, slot2)).assert_with_checks([
JMESPathCheck("[?name=='c1']|[0].value", None),
JMESPathCheck("[?name=='c2']|[0].value", None)
])
# verify we can swap with non production slot
self.cmd('webapp deployment slot swap -g {} -n {} --slot {} --target-slot {}'.format(
resource_group, webapp, slot, slot2))
Expand Down

0 comments on commit 6be01c7

Please sign in to comment.