Skip to content
Merged
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
2 changes: 2 additions & 0 deletions src/aks-preview/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ To release a new version, please select a new version number (usually plus 1 to
Pending
+++++++

* Add custom transform for custom CA

0.5.116
+++++++

Expand Down
43 changes: 42 additions & 1 deletion src/aks-preview/azext_aks_preview/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,46 @@
aks_show_table_format,
aks_upgrades_table_format,
)
from knack.log import get_logger

logger = get_logger(__name__)


def transform_mc_objects_with_custom_cas(result):
# convert custom_ca_trust_certificates in bytearray format encoded in utf-8 to string
if not result:
return result
from msrest.paging import Paged

def _patch_custom_cas_in_security_profile(security_profile):
# modify custom_ca_trust_certificates in-place
# security_profile shouldn't be None
custom_cas = getattr(security_profile, 'custom_ca_trust_certificates', None)
if custom_cas:
decoded_custom_cas = []
for custom_ca in custom_cas:
try:
decoded_custom_ca = custom_ca.decode("utf-8")
except Exception: # pylint: disable=broad-except
logger.warning("failed to decode customCaTrustCertificates")
decoded_custom_ca = None
decoded_custom_cas.append(decoded_custom_ca)
security_profile.custom_ca_trust_certificates = decoded_custom_cas

singular = False
if isinstance(result, Paged):
result = list(result)

if not isinstance(result, list):
singular = True
result = [result]

for r in result:
if getattr(r, 'security_profile', None):
# security_profile shouldn't be None
_patch_custom_cas_in_security_profile(r.security_profile)

return result[0] if singular else result


def load_command_table(self, _):
Expand Down Expand Up @@ -77,7 +117,8 @@ def load_command_table(self, _):
)

# AKS managed cluster commands
with self.command_group('aks', managed_clusters_sdk, client_factory=cf_managed_clusters) as g:
with self.command_group('aks', managed_clusters_sdk, client_factory=cf_managed_clusters,
transform=transform_mc_objects_with_custom_cas) as g:
g.custom_command('kollect', 'aks_kollect')
g.custom_command('kanalyze', 'aks_kanalyze')
g.custom_command('browse', 'aks_browse')
Expand Down