Skip to content

Commit 692c843

Browse files
style
1 parent 7ce1d50 commit 692c843

File tree

2 files changed

+42
-42
lines changed

2 files changed

+42
-42
lines changed

src/azure-cli/azure/cli/command_modules/appconfig/_kv_import_helpers.py

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -571,20 +571,20 @@ def __read_kv_from_file(
571571
def flatten_config_data(config_data, format_, content_type, prefix_to_add="", depth=None, separator=None):
572572
"""
573573
Flatten configuration data into a dictionary of key-value pairs.
574-
574+
575575
Args:
576576
config_data: The configuration data to flatten (dict or list)
577577
format_ (str): The format of the configuration data ('json', 'yaml', 'properties')
578578
content_type (str): Content type for JSON validation
579579
prefix_to_add (str): Prefix to add to each key
580580
depth (int): Maximum depth for flattening hierarchical data
581581
separator (str): Separator for hierarchical keys
582-
582+
583583
Returns:
584584
dict: Flattened key-value pairs
585585
"""
586586
flattened_data = {}
587-
587+
588588
if format_ == "json" and content_type and is_json_content_type(content_type):
589589
for key in config_data:
590590
__flatten_json_key_value(
@@ -756,7 +756,7 @@ def __read_kv_from_kubernetes_configmap(
756756
):
757757
"""
758758
Read key-value pairs from a Kubernetes ConfigMap using aks_runcommand.
759-
759+
760760
Args:
761761
cmd: The command context object
762762
aks_cluster (str): Name of the AKS cluster
@@ -767,64 +767,64 @@ def __read_kv_from_kubernetes_configmap(
767767
content_type (str): Content type to apply to the key-values
768768
depth (int): Maximum depth for flattening hierarchical data
769769
separator (str): Separator for hierarchical keys
770-
770+
771771
Returns:
772772
list: List of KeyValue objects
773773
"""
774-
# try:
775-
key_values = []
776-
from azure.cli.command_modules.acs.custom import aks_runcommand
777-
from azure.cli.command_modules.acs._client_factory import cf_managed_clusters
774+
try:
775+
key_values = []
776+
from azure.cli.command_modules.acs.custom import aks_runcommand
777+
from azure.cli.command_modules.acs._client_factory import cf_managed_clusters
778778

779-
# Get the AKS client from the factory
780-
cmd.cli_ctx.data['subscription_id'] = aks_cluster["subscription"]
781-
cmd.cli_ctx.data['safe_params'] = None
782-
aks_client = cf_managed_clusters(cmd.cli_ctx)
779+
# Get the AKS client from the factory
780+
cmd.cli_ctx.data['subscription_id'] = aks_cluster["subscription"]
781+
cmd.cli_ctx.data['safe_params'] = None
782+
aks_client = cf_managed_clusters(cmd.cli_ctx)
783783

784-
# Command to get the ConfigMap and output it as JSON
785-
command = f"kubectl get configmap {configmap_name} -n {namespace} -o json"
784+
# Command to get the ConfigMap and output it as JSON
785+
command = f"kubectl get configmap {configmap_name} -n {namespace} -o json"
786786

787-
# Execute the command on the cluster
788-
result = aks_runcommand(cmd, aks_client, aks_cluster["resource_group"], aks_cluster["name"], command_string=command)
787+
# Execute the command on the cluster
788+
result = aks_runcommand(cmd, aks_client, aks_cluster["resource_group"], aks_cluster["name"], command_string=command)
789789

790-
if hasattr(result, 'logs') and result.logs:
791-
if not hasattr(result, 'exit_code') or result.exit_code != 0:
792-
raise AzureResponseError(f"{result.logs.strip()}")
790+
if hasattr(result, 'logs') and result.logs:
791+
if not hasattr(result, 'exit_code') or result.exit_code != 0:
792+
raise AzureResponseError(f"{result.logs.strip()}")
793793

794-
try:
795-
configmap_data = json.loads(result.logs)
794+
try:
795+
configmap_data = json.loads(result.logs)
796796

797-
# Extract the data section which contains the key-value pairs
798-
kvs = __extract_kv_from_configmap_data(
799-
configmap_data, content_type, prefix_to_add, format_, depth, separator)
797+
# Extract the data section which contains the key-value pairs
798+
kvs = __extract_kv_from_configmap_data(
799+
configmap_data, content_type, prefix_to_add, format_, depth, separator)
800800

801-
key_values.extend(kvs)
802-
except json.JSONDecodeError:
803-
raise ValidationError(
804-
f"The result from ConfigMap {configmap_name} could not be parsed as valid JSON."
805-
)
806-
else:
807-
raise AzureResponseError("Unable to get the ConfigMap.")
801+
key_values.extend(kvs)
802+
except json.JSONDecodeError:
803+
raise ValidationError(
804+
f"The result from ConfigMap {configmap_name} could not be parsed as valid JSON."
805+
)
806+
else:
807+
raise AzureResponseError("Unable to get the ConfigMap.")
808808

809-
return key_values
810-
# except Exception as exception:
811-
# raise AzureInternalError(
812-
# f"Failed to read key-values from ConfigMap '{configmap_name}' in namespace '{namespace}'.\n{str(exception)}"
813-
# )
809+
return key_values
810+
except Exception as exception:
811+
raise AzureInternalError(
812+
f"Failed to read key-values from ConfigMap '{configmap_name}' in namespace '{namespace}'.\n{str(exception)}"
813+
)
814814

815815

816816
def __extract_kv_from_configmap_data(configmap_data, content_type, prefix_to_add="", format_=None, depth=None, separator=None):
817817
"""
818818
Helper function to extract key-value pairs from ConfigMap data.
819-
819+
820820
Args:
821821
configmap_data (dict): The ConfigMap data as a dictionary
822822
prefix_to_add (str): Prefix to add to each key
823823
content_type (str): Content type to apply to the key-values
824824
format_ (str): Format of the data in the ConfigMap (e.g., "json", "yaml")
825825
depth (int): Maximum depth for flattening hierarchical data
826826
separator (str): Separator for hierarchical keys
827-
827+
828828
Returns:
829829
list: List of KeyValue objects
830830
"""
@@ -833,7 +833,7 @@ def __extract_kv_from_configmap_data(configmap_data, content_type, prefix_to_add
833833
if 'data' not in configmap_data:
834834
logger.warning("ConfigMap exists but has no data")
835835
return key_values
836-
836+
837837
for key, value in configmap_data['data'].items():
838838
if format_ in ("json", "yaml", "properties"):
839839
if format_ == "json":
@@ -886,7 +886,7 @@ def __extract_kv_from_configmap_data(configmap_data, content_type, prefix_to_add
886886
json.loads(value)
887887
except json.JSONDecodeError:
888888
logger.warning(
889-
'Value "{value}" for key "{key}" is not a valid JSON object, which conflicts with the provided content type "{content_type}".',
889+
'Value "%s" for key "%s" is not a valid JSON object, which conflicts with the provided content type "%s".',
890890
value, key, content_type
891891
)
892892
continue

src/azure-cli/azure/cli/command_modules/appconfig/_params.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def load_arguments(self, _):
266266
c.argument('appservice_account', validator=validate_appservice_name_or_id, help='ARM ID for AppService OR the name of the AppService, assuming it is in the same subscription and resource group as the App Configuration store. Required for AppService arguments')
267267

268268
with self.argument_context('appconfig kv import', arg_group='AKS') as c:
269-
c.argument('aks_cluster', validator=validate_aks_cluster_name_or_id, help='ARM ID for AKS OR the name of the AKS, assuming it is in the same subscription and resource group as the App Configuration store. Required for AKS arguments'),
269+
c.argument('aks_cluster', validator=validate_aks_cluster_name_or_id, help='ARM ID for AKS OR the name of the AKS, assuming it is in the same subscription and resource group as the App Configuration store. Required for AKS arguments')
270270
c.argument('configmap_name', help='Name of the ConfigMap. Required for AKS arguments.')
271271
c.argument('configmap_namespace', help='Namespace of the ConfigMap. default to "default" namespace if not specified.')
272272

0 commit comments

Comments
 (0)