Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/azure-cli/azure/cli/command_modules/appconfig/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@
text: az appconfig kv set -n MyAppConfiguration --key foo --value null --content-type application/json
- name: Set a key-value using your 'az login' credentials.
text: az appconfig kv set --endpoint https://contoso.azconfig.io --key color --value red --auth-mode login
- name: Set a key-value with a description.
text: az appconfig kv set -n MyAppConfiguration --key color --value red --description "The theme color"
"""

helps['appconfig kv set-keyvault'] = """
Expand All @@ -296,6 +298,8 @@
text: az appconfig kv set-keyvault -n MyAppConfiguration --key HostSecret --label MyLabel --secret-identifier https://contoso.vault.azure.net/Secrets/DummySecret/Dummyversion
- name: Set a keyvault reference with null label and multiple tags using connection string.
text: az appconfig kv set-keyvault --connection-string Endpoint=https://contoso.azconfig.io;Id=xxx;Secret=xxx --key HostSecret --secret-identifier https://contoso.vault.azure.net/Secrets/DummySecret --tags tag1=value1 tag2=value2
- name: Set a keyvault reference with a description.
text: az appconfig kv set-keyvault -n MyAppConfiguration --key HostSecret --secret-identifier https://contoso.vault.azure.net/Secrets/DummySecret --description "Reference to the host secret"
"""

helps['appconfig kv set-snapshot-reference'] = """
Expand All @@ -308,6 +312,8 @@
text: az appconfig kv set-snapshot-reference --endpoint https://contoso.azconfig.io --key MySnapshotRef --snapshot-name MySnapshot --auth-mode login
- name: Set a snapshot reference with tags using connection string.
text: az appconfig kv set-snapshot-reference --connection-string Endpoint=https://contoso.azconfig.io;Id=xxx;Secret=xxx --key MySnapshotRef --snapshot-name MySnapshot --tags tag1=value1 tag2=value2
- name: Set a snapshot reference with a description.
text: az appconfig kv set-snapshot-reference -n MyAppConfiguration --key MySnapshotRef --snapshot-name MySnapshot --description "Reference to MySnapshot"
"""

helps['appconfig kv show'] = """
Expand Down Expand Up @@ -745,8 +751,9 @@
az appconfig snapshot create -s MySnapshot -n MyAppConfiguration --filters '{\\"key\\":\\"app/*\\"}' '{\\"key\\":\\"app/*\\", \\"label\\":\\"prod\\"}' --composition-type 'key'
- name: Create a snapshot of all keys starting with 'Test' and have tags 'tag1=value1' and 'tag2=value2'.
text:
az appconfig snapshot create -s MySnapshot -n MyAppConfiguration --filters '{\\"key\\":\\"Test*\\", \\"tags\\":[\\"tag1=value1\\", \\"tag2=value2\\"]}'
"""
az appconfig snapshot create -s MySnapshot -n MyAppConfiguration --filters '{\\"key\\":\\"Test*\\", \\"tags\\":[\\"tag1=value1\\", \\"tag2=value2\\"]}' - name: Create a snapshot MySnapshot with a description.
text:
az appconfig snapshot create -s MySnapshot -n MyAppConfiguration --filters '{\"key\":\"Test*\"}' --description "Snapshot of Test key-values" """

helps['appconfig snapshot show'] = """
type: command
Expand Down
18 changes: 13 additions & 5 deletions src/azure-cli/azure/cli/command_modules/appconfig/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class QueryFields(Enum):
LAST_MODIFIED = 0x020
LOCKED = 0x040
TAGS = 0x080
ALL = KEY | LABEL | VALUE | CONTENT_TYPE | ETAG | LAST_MODIFIED | LOCKED | TAGS
DESCRIPTION = 0x100
ALL = KEY | LABEL | VALUE | CONTENT_TYPE | ETAG | LAST_MODIFIED | LOCKED | TAGS | DESCRIPTION


class KeyValue:
Expand All @@ -45,6 +46,8 @@ class KeyValue:
Represents whether the key value entry is locked.
:ivar str last_modified:
A str representation of the datetime object representing the last time the key was modified.
:ivar str description:
Description of the entry.
'''

def __init__(self,
Expand All @@ -55,7 +58,8 @@ def __init__(self,
content_type=None,
etag=None,
locked=False,
last_modified=None):
last_modified=None,
description=None):
self.key = key
self.value = value
self.label = label
Expand All @@ -64,6 +68,7 @@ def __init__(self,
self.etag = etag
self.last_modified = last_modified.isoformat() if isinstance(last_modified, datetime) else str(last_modified)
self.locked = locked
self.description = description

def __str__(self):
return "\nKey: " + self.key + \
Expand All @@ -73,7 +78,8 @@ def __str__(self):
"\nLast Modified: " + self.last_modified + \
"\nLocked: " + self.locked + \
"\nContent Type: " + self.content_type + \
"\nTags: " + (str(self.tags) if self.tags else '')
"\nTags: " + (str(self.tags) if self.tags else '') + \
"\nDescription: " + (self.description if self.description else '')


def convert_configurationsetting_to_keyvalue(configuration_setting=None):
Expand All @@ -87,7 +93,8 @@ def convert_configurationsetting_to_keyvalue(configuration_setting=None):
last_modified=configuration_setting.last_modified,
tags=configuration_setting.tags,
locked=configuration_setting.read_only,
etag=configuration_setting.etag)
etag=configuration_setting.etag,
description=getattr(configuration_setting, 'description', None))


def convert_keyvalue_to_configurationsetting(keyvalue=None):
Expand All @@ -99,4 +106,5 @@ def convert_keyvalue_to_configurationsetting(keyvalue=None):
value=keyvalue.value,
tags=keyvalue.tags,
read_only=keyvalue.locked,
etag=keyvalue.etag)
etag=keyvalue.etag,
description=keyvalue.description)
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def load_arguments(self, _):
nargs='+',
help='Space-separated customized output fields.',
validator=validate_query_fields,
arg_type=get_enum_type(['key', 'value', 'label', 'content_type', 'etag', 'tags', 'locked', 'last_modified'])
arg_type=get_enum_type(['key', 'value', 'label', 'content_type', 'etag', 'tags', 'locked', 'last_modified', 'description'])
)
feature_fields_arg_type = CLIArgumentType(
nargs='+',
Expand All @@ -51,7 +51,7 @@ def load_arguments(self, _):
nargs='+',
help='Customize output fields for Snapshots',
validator=validate_snapshot_query_fields,
arg_type=get_enum_type(['name', 'etag', 'retention_period', 'filters', 'status', 'created', 'expires', 'size', 'items_count', 'composition_type', 'tags'])
arg_type=get_enum_type(['name', 'etag', 'retention_period', 'filters', 'status', 'created', 'expires', 'size', 'items_count', 'composition_type', 'tags', 'description'])
)
filter_parameters_arg_type = CLIArgumentType(
validator=validate_filter_parameters,
Expand Down Expand Up @@ -330,17 +330,20 @@ def load_arguments(self, _):
c.argument('tags', arg_type=tags_type)
c.argument('content_type', help='Content type of the key-value to be set.')
c.argument('value', help='Value of the key-value to be set.')
c.argument('description', help='Description of the key-value to be set.')

with self.argument_context('appconfig kv set-keyvault') as c:
c.argument('key', validator=validate_key, help="Key to be set. Key cannot be a '.' or '..', or contain the '%' character.")
c.argument('label', help="If no label specified, set the key with null label by default")
c.argument('tags', arg_type=tags_type)
c.argument('description', help='Description of the key vault reference to be set.')
c.argument('secret_identifier', validator=validate_secret_identifier, help="ID of the Key Vault object. Can be found using 'az keyvault {collection} show' command, where collection is key, secret or certificate. To set reference to the latest version of your secret, remove version information from secret identifier.")

with self.argument_context('appconfig kv set-snapshot-reference') as c:
c.argument('key', validator=validate_key, help="Key to be set. Key cannot be a '.' or '..', or contain the '%' character.")
c.argument('label', help="If no label specified, set the key with null label by default")
c.argument('tags', arg_type=tags_type)
c.argument('description', help='Description of the snapshot reference to be set.')
c.argument('snapshot_name', validator=validate_snapshot_reference, help='Name of the snapshot to reference. This is required.')

with self.argument_context('appconfig kv delete') as c:
Expand Down Expand Up @@ -476,6 +479,7 @@ def load_arguments(self, _):
c.argument('composition_type', arg_type=get_enum_type(["key", "key_label"]), help='Composition type used in building App Configuration snapshots. If not specified, defaults to key.')
c.argument('retention_period', type=int, help='Duration in seconds for which a snapshot can remain archived before expiry. A snapshot can be archived for a maximum of 7 days (604,800s) for free and developer tier stores and 90 days (7,776,000s) for standard and premium tier stores. If specified, retention period must be at least 1 hour (3600s)')
c.argument('tags', arg_type=tags_type, help="Space-separated tags: key[=value] [key[=value] ...].")
c.argument('description', help='Description of the App Configuration snapshot.')

with self.argument_context('appconfig snapshot show') as c:
c.argument('fields', arg_type=snapshot_fields_arg_type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class SnapshotQueryFields(Enum):
TAGS = 0x0100
ETAG = 0x0200
RETENTION_PERIOD = 0x0400
ALL = NAME | STATUS | FILTERS | COMPOSITION_TYPE | CREATED | EXPIRES | SIZE | ITEMS_COUNT | TAGS | ETAG | RETENTION_PERIOD
DESCRIPTION = 0x0800
ALL = NAME | STATUS | FILTERS | COMPOSITION_TYPE | CREATED | EXPIRES | SIZE | ITEMS_COUNT | TAGS | ETAG | RETENTION_PERIOD | DESCRIPTION


class Snapshot:
Expand Down Expand Up @@ -54,6 +55,8 @@ class Snapshot:
Dictionary of tags of the snapshot.
:ivar int retention_period:
Number of seconds for which an archived snapshot will be kept before being deleted.
:ivar str description:
Description of the snapshot.
'''

def __init__(self,
Expand All @@ -68,6 +71,7 @@ def __init__(self,
items_count=None,
tags=None,
retention_period=None,
description=None,
):

self.name = name
Expand All @@ -81,6 +85,7 @@ def __init__(self,
self.items_count = items_count
self.tags = tags
self.retention_period = retention_period
self.description = description

def __str__(self):
return "\nEtag: " + self.etag + \
Expand All @@ -93,7 +98,8 @@ def __str__(self):
"\nSize: " + str(self.size) + \
"\nItem count: " + str(self.items_count) + \
"\nTags: " + (str(self.tags) if self.tags else '{}') + \
"\nRetention Period: " + str(self.retention_period)
"\nRetention Period: " + str(self.retention_period) + \
"\nDescription: " + (self.description if self.description else '')

@classmethod
def from_configuration_snapshot(cls, config_snapshot):
Expand All @@ -108,7 +114,8 @@ def from_configuration_snapshot(cls, config_snapshot):
size=config_snapshot.size,
items_count=config_snapshot.items_count,
tags=config_snapshot.tags,
retention_period=config_snapshot.retention_period
retention_period=config_snapshot.retention_period,
description=getattr(config_snapshot, 'description', None)
)


Expand Down
33 changes: 24 additions & 9 deletions src/azure-cli/azure/cli/command_modules/appconfig/keyvalue.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ def set_key(cmd,
content_type=None,
tags=None,
value=None,
description=None,
yes=False,
connection_string=None,
auth_mode="key",
Expand Down Expand Up @@ -520,10 +521,12 @@ def set_key(cmd,
label=label,
value="" if value is None else value,
content_type="" if content_type is None else content_type,
tags=tags)
tags=tags,
description=description)
else:
value = retrieved_kv.value if value is None else value
content_type = retrieved_kv.content_type if content_type is None else content_type
description = retrieved_kv.description if description is None else description
if is_json_content_type(content_type):
try:
# Ensure that provided value is valid JSON and strip comments if needed.
Expand All @@ -536,14 +539,16 @@ def set_key(cmd,
content_type=content_type,
tags=retrieved_kv.tags if tags is None else tags,
read_only=retrieved_kv.read_only,
etag=retrieved_kv.etag)
etag=retrieved_kv.etag,
description=description)

verification_kv = {
"key": set_kv.key,
"label": set_kv.label,
"content_type": set_kv.content_type,
"value": set_kv.value,
"tags": set_kv.tags
"tags": set_kv.tags,
"description": set_kv.description
}

entry = json.dumps(verification_kv, indent=2, sort_keys=True, ensure_ascii=False)
Expand Down Expand Up @@ -576,6 +581,7 @@ def set_keyvault(cmd,
name=None,
label=None,
tags=None,
description=None,
yes=False,
connection_string=None,
auth_mode="key",
Expand Down Expand Up @@ -608,22 +614,26 @@ def set_keyvault(cmd,
label=label,
value=keyvault_ref_value,
content_type=KeyVaultConstants.KEYVAULT_CONTENT_TYPE,
tags=tags)
tags=tags,
description=description)
else:
description = retrieved_kv.description if description is None else description
set_kv = ConfigurationSetting(key=key,
label=label,
value=keyvault_ref_value,
content_type=KeyVaultConstants.KEYVAULT_CONTENT_TYPE,
tags=retrieved_kv.tags if tags is None else tags,
read_only=retrieved_kv.read_only,
etag=retrieved_kv.etag)
etag=retrieved_kv.etag,
description=description)

verification_kv = {
"key": set_kv.key,
"label": set_kv.label,
"content_type": set_kv.content_type,
"value": set_kv.value,
"tags": set_kv.tags
"tags": set_kv.tags,
"description": set_kv.description
}
entry = json.dumps(verification_kv, indent=2, sort_keys=True, ensure_ascii=False)
confirmation_message = "Are you sure you want to set the keyvault reference: \n" + entry + "\n"
Expand Down Expand Up @@ -655,6 +665,7 @@ def set_snapshot_reference(cmd,
name=None,
label=None,
tags=None,
description=None,
yes=False,
connection_string=None,
auth_mode="key",
Expand Down Expand Up @@ -687,22 +698,26 @@ def set_snapshot_reference(cmd,
label=label,
value=snapshot_ref_value,
content_type=SnapshotReferenceConstants.SNAPSHOT_REFERENCE_CONTENT_TYPE,
tags=tags)
tags=tags,
description=description)
else:
description = retrieved_kv.description if description is None else description
set_kv = ConfigurationSetting(key=key,
label=label,
value=snapshot_ref_value,
content_type=SnapshotReferenceConstants.SNAPSHOT_REFERENCE_CONTENT_TYPE,
tags=retrieved_kv.tags if tags is None else tags,
read_only=retrieved_kv.read_only,
etag=retrieved_kv.etag)
etag=retrieved_kv.etag,
description=description)

verification_kv = {
"key": set_kv.key,
"label": set_kv.label,
"content_type": set_kv.content_type,
"value": set_kv.value,
"tags": set_kv.tags
"tags": set_kv.tags,
"description": set_kv.description
}
entry = json.dumps(verification_kv, indent=2, sort_keys=True, ensure_ascii=False)
confirmation_message = "Are you sure you want to set the snapshot reference: \n" + entry + "\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def create_snapshot(cmd,
endpoint=None,
retention_period=None,
composition_type=None,
tags=None):
tags=None,
description=None):

client = get_appconfig_data_client(cmd, name, connection_string, auth_mode, endpoint)

Expand All @@ -44,7 +45,8 @@ def create_snapshot(cmd,
configurationSettingsFilters,
composition_type=composition_type,
retention_period=retention_period,
tags=tags)
tags=tags,
description=description)

# Poll snapshot creation status
while config_snapshot_poller.status() != ProvisioningStatus.SUCCEEDED:
Expand Down
Loading
Loading