Skip to content

Commit 46fbdea

Browse files
authoredMar 22, 2022
{AKS} Fix custom header extraction issue (Azure#21713)
* fix custom header extraction issue * update test
1 parent 7bbad7d commit 46fbdea

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed
 

‎src/azure-cli/azure/cli/command_modules/acs/_validators.py

+5
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ def extract_comma_separated_string(
416416
allow_empty_value=False,
417417
keep_none=False,
418418
default_value=None,
419+
allow_appending_values_to_same_key=False,
419420
):
420421
"""Extract comma-separated string.
421422
@@ -425,6 +426,8 @@ def extract_comma_separated_string(
425426
Option allow_empty_value is valid since extract_kv is specified. When the number of string segments split by "="
426427
is 1, the first segment is retained as the key and empty string would be set as its corresponding value without
427428
raising an exception.
429+
Option allow_appending_values_to_same_key is valid since extract_kv is specified. For the same key, the new value
430+
is appended to the existing value separated by commas.
428431
If keep_none is specified, will return None when input is None. Otherwise will return default_value if input is
429432
None or empty string.
430433
"""
@@ -457,6 +460,8 @@ def extract_comma_separated_string(
457460
if enable_strip:
458461
key = key.strip()
459462
value = value.strip()
463+
if allow_appending_values_to_same_key and key in result:
464+
value = "{},{}".format(result[key], value)
460465
result[key] = value
461466
else:
462467
raise InvalidArgumentValueError(

‎src/azure-cli/azure/cli/command_modules/acs/agentpool_decorator.py

+1
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ def get_aks_custom_headers(self) -> Dict[str, str]:
349349
enable_strip=True,
350350
extract_kv=True,
351351
default_value={},
352+
allow_appending_values_to_same_key=True,
352353
)
353354

354355
# this parameter does not need validation

‎src/azure-cli/azure/cli/command_modules/acs/custom.py

+4
Original file line numberDiff line numberDiff line change
@@ -3203,6 +3203,7 @@ def aks_agentpool_add(cmd, client, resource_group_name, cluster_name, nodepool_n
32033203
enable_strip=True,
32043204
extract_kv=True,
32053205
default_value={},
3206+
allow_appending_values_to_same_key=True,
32063207
)
32073208

32083209
return sdk_no_wait(
@@ -3300,6 +3301,7 @@ def aks_agentpool_upgrade(cmd, client, resource_group_name, cluster_name,
33003301
enable_strip=True,
33013302
extract_kv=True,
33023303
default_value={},
3304+
allow_appending_values_to_same_key=True,
33033305
)
33043306

33053307
return sdk_no_wait(
@@ -3413,6 +3415,7 @@ def aks_agentpool_update(cmd, client, resource_group_name, cluster_name, nodepoo
34133415
enable_strip=True,
34143416
extract_kv=True,
34153417
default_value={},
3418+
allow_appending_values_to_same_key=True,
34163419
)
34173420

34183421
return sdk_no_wait(
@@ -4161,6 +4164,7 @@ def aks_snapshot_create(cmd, # pylint: disable=too-many-locals,too-many-state
41614164
enable_strip=True,
41624165
extract_kv=True,
41634166
default_value={},
4167+
allow_appending_values_to_same_key=True,
41644168
)
41654169
return client.create_or_update(resource_group_name, name, snapshot, headers=aks_custom_headers)
41664170

‎src/azure-cli/azure/cli/command_modules/acs/decorator.py

+1
Original file line numberDiff line numberDiff line change
@@ -4617,6 +4617,7 @@ def get_aks_custom_headers(self) -> Dict[str, str]:
46174617
enable_strip=True,
46184618
extract_kv=True,
46194619
default_value={},
4620+
allow_appending_values_to_same_key=True,
46204621
)
46214622

46224623
# In create mode, add AAD session key to header.

‎src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_validators.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ def test_extract_comma_separated_string(self):
351351
validators.extract_comma_separated_string(s12, extract_kv=True)
352352

353353
s13 = "WindowsContainerRuntime=containerd,AKSHTTPCustomFeatures=Microsoft.ContainerService/CustomNodeConfigPreview"
354-
t13 = validators.extract_comma_separated_string(s13, enable_strip=True, extract_kv=True, default_value={},)
354+
t13 = validators.extract_comma_separated_string(s13, enable_strip=True, extract_kv=True, default_value={}, allow_appending_values_to_same_key=True)
355355
g13 = {"WindowsContainerRuntime": "containerd", "AKSHTTPCustomFeatures": "Microsoft.ContainerService/CustomNodeConfigPreview"}
356356
self.assertEqual(t13, g13)
357357

@@ -360,6 +360,16 @@ def test_extract_comma_separated_string(self):
360360
g14 = {"": ""}
361361
self.assertEqual(t14, g14)
362362

363+
s15 = "WindowsContainerRuntime=containerd,AKSHTTPCustomFeatures=Microsoft.ContainerService/AKSTestFeaturePreview,AKSHTTPCustomFeatures=Microsoft.ContainerService/AKSExampleFeaturePreview"
364+
t15 = validators.extract_comma_separated_string(s15, enable_strip=True, extract_kv=True, default_value={},)
365+
g15 = {"WindowsContainerRuntime": "containerd", "AKSHTTPCustomFeatures": "Microsoft.ContainerService/AKSExampleFeaturePreview"}
366+
self.assertEqual(t15, g15)
367+
368+
s16 = "WindowsContainerRuntime=containerd,AKSHTTPCustomFeatures=Microsoft.ContainerService/AKSTestFeaturePreview,AKSHTTPCustomFeatures=Microsoft.ContainerService/AKSExampleFeaturePreview"
369+
t16 = validators.extract_comma_separated_string(s16, enable_strip=True, extract_kv=True, default_value={}, allow_appending_values_to_same_key=True)
370+
g16 = {"WindowsContainerRuntime": "containerd", "AKSHTTPCustomFeatures": "Microsoft.ContainerService/AKSTestFeaturePreview,Microsoft.ContainerService/AKSExampleFeaturePreview"}
371+
self.assertEqual(t16, g16)
372+
363373

364374
class CredentialFormatNamespace:
365375
def __init__(self, credential_format):
@@ -381,3 +391,7 @@ def test_valid_format(self):
381391
namespace = CredentialFormatNamespace(credential_format)
382392

383393
validators.validate_credential_format(namespace)
394+
395+
396+
if __name__ == "__main__":
397+
unittest.main()

0 commit comments

Comments
 (0)