-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[Containerapp] az containerapp function: Add function key management commands
#9163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,10 @@ Release History | |
| =============== | ||
| upcoming | ||
| ++++++ | ||
| * 'az containerapp function list-keys': List function keys for a specific function in a container app | ||
| * 'az containerapp function update-keys': Update specific function key for a specific function in a container app | ||
| * 'az containerapp function list-hostkeys': List host keys for a container app | ||
| * 'az containerapp function update-hostkeys': Update specific host key for a container app | ||
|
Comment on lines
+7
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we also have master key and system keys. Instead of adding separate commands for each type of keys, can we follow the same approach as that of My suggestion is to have only one command that handles all kinds of function keys, following the az functionapp conventions.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| * 'az containerapp update/up': Disallow changing `--revisions-mode` to Labels. | ||
| * 'az containerapp session code-interpreter': Fix `--path` in examples | ||
| * 'az containerapp sessionpool create/update': Support `--lifecycle-type` and `--max-alive-period` | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,185 @@ | ||
| # coding=utf-8 | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
| # pylint: disable=line-too-long, broad-except, logging-format-interpolation | ||
| from knack.log import get_logger | ||
| from typing import Any, Dict | ||
|
|
||
| from azure.cli.core.commands import AzCliCommand | ||
| from azure.cli.core.azclierror import ValidationError | ||
| from azure.cli.command_modules.containerapp.base_resource import BaseResource | ||
|
|
||
| from ._clients import ContainerAppFunctionsPreviewClient | ||
| from ._client_factory import handle_raw_exception | ||
|
|
||
| logger = get_logger(__name__) | ||
|
|
||
|
|
||
| class ContainerAppFunctionKeysDecorator(BaseResource): | ||
| """Base decorator for Container App Function Keys operations""" | ||
|
|
||
| def __init__(self, cmd: AzCliCommand, client: Any, raw_parameters: Dict, models: str): | ||
| super().__init__(cmd, client, raw_parameters, models) | ||
|
|
||
| def get_argument_function_name(self): | ||
| return self.get_param("function_name") | ||
|
|
||
| def get_argument_revision_name(self): | ||
| return self.get_param("revision_name") | ||
|
|
||
| def validate_common_arguments(self): | ||
| """Validate common arguments required for all function operations""" | ||
| resource_group_name = self.get_argument_resource_group_name() | ||
| name = self.get_argument_name() | ||
| revision_name = self.get_argument_revision_name() | ||
|
|
||
| if not resource_group_name: | ||
| raise ValidationError("Resource group name is required.") | ||
|
|
||
| if not name: | ||
| raise ValidationError("Container app name is required.") | ||
|
|
||
| if not revision_name: | ||
| raise ValidationError("Revision name is required.") | ||
|
|
||
| return resource_group_name, name, revision_name | ||
|
|
||
| def validate_function_arguments(self): | ||
| """Validate arguments required for function-specific operations""" | ||
| resource_group_name, name, revision_name = self.validate_common_arguments() | ||
| function_name = self.get_argument_function_name() | ||
|
|
||
| if not function_name: | ||
| raise ValidationError("Function name is required.") | ||
|
|
||
| return resource_group_name, name, revision_name, function_name | ||
|
|
||
|
|
||
| class ContainerAppFunctionKeysListDecorator(ContainerAppFunctionKeysDecorator): | ||
| """Decorator for listing function keys""" | ||
|
|
||
| def __init__(self, cmd: AzCliCommand, client: Any, raw_parameters: Dict, models: str): | ||
| super().__init__(cmd, client, raw_parameters, models) | ||
|
|
||
| def list_keys(self): | ||
| """List keys for a specific function""" | ||
| try: | ||
| resource_group_name, name, revision_name, function_name = self.validate_function_arguments() | ||
|
|
||
| return self.client.list_function_keys( | ||
| cmd=self.cmd, | ||
| resource_group_name=resource_group_name, | ||
| name=name, | ||
| function_name=function_name | ||
| ) | ||
| except Exception as e: | ||
| handle_raw_exception(e) | ||
|
|
||
|
|
||
| class ContainerAppFunctionKeysUpdateDecorator(ContainerAppFunctionKeysDecorator): | ||
| """Decorator for updating function keys""" | ||
|
|
||
| def __init__(self, cmd: AzCliCommand, client: Any, raw_parameters: Dict, models: str): | ||
| super().__init__(cmd, client, raw_parameters, models) | ||
|
|
||
| def get_argument_key_name(self): | ||
| return self.get_param("key_name") | ||
|
|
||
| def get_argument_key_value(self): | ||
| return self.get_param("key_value") | ||
|
|
||
| def validate_update_arguments(self): | ||
| """Validate arguments required for updating function keys""" | ||
| resource_group_name, name, revision_name, function_name = self.validate_function_arguments() | ||
| key_name = self.get_argument_key_name() | ||
|
|
||
| if not key_name: | ||
| raise ValidationError("Key name is required.") | ||
|
|
||
| return resource_group_name, name, revision_name, function_name, key_name | ||
|
|
||
| def update_keys(self): | ||
| """Update keys for a specific function""" | ||
| try: | ||
| resource_group_name, name, revision_name, function_name, key_name = self.validate_update_arguments() | ||
| key_value = self.get_argument_key_value() | ||
|
|
||
| return self.client.update_function_keys( | ||
| cmd=self.cmd, | ||
| resource_group_name=resource_group_name, | ||
| name=name, | ||
| function_name=function_name, | ||
| key_name=key_name, | ||
| key_value=key_value | ||
| ) | ||
| except Exception as e: | ||
| handle_raw_exception(e) | ||
|
|
||
|
|
||
| class ContainerAppFunctionHostKeysListDecorator(ContainerAppFunctionKeysDecorator): | ||
| """Decorator for listing host keys""" | ||
|
|
||
| def __init__(self, cmd: AzCliCommand, client: Any, raw_parameters: Dict, models: str): | ||
| super().__init__(cmd, client, raw_parameters, models) | ||
|
|
||
| def list_host_keys(self): | ||
| """List host keys for the container app function host""" | ||
| try: | ||
| resource_group_name, name, revision_name = self.validate_common_arguments() | ||
|
|
||
| return self.client.list_host_keys( | ||
| cmd=self.cmd, | ||
| resource_group_name=resource_group_name, | ||
| name=name | ||
| ) | ||
| except Exception as e: | ||
| handle_raw_exception(e) | ||
|
|
||
|
|
||
| class ContainerAppFunctionHostKeysUpdateDecorator(ContainerAppFunctionKeysDecorator): | ||
| """Decorator for updating host keys""" | ||
|
|
||
| def __init__(self, cmd: AzCliCommand, client: Any, raw_parameters: Dict, models: str): | ||
| super().__init__(cmd, client, raw_parameters, models) | ||
|
|
||
| def get_argument_key_type(self): | ||
| return self.get_param("key_type") | ||
|
|
||
| def get_argument_key_name(self): | ||
| return self.get_param("key_name") | ||
|
|
||
| def get_argument_key_value(self): | ||
| return self.get_param("key_value") | ||
|
|
||
| def validate_host_key_arguments(self): | ||
| """Validate arguments required for updating host keys""" | ||
| resource_group_name, name, revision_name = self.validate_common_arguments() | ||
| key_type = self.get_argument_key_type() | ||
| key_name = self.get_argument_key_name() | ||
|
|
||
| if not key_type: | ||
| raise ValidationError("Key type is required.") | ||
|
|
||
| if not key_name: | ||
| raise ValidationError("Key name is required.") | ||
|
|
||
| return resource_group_name, name, revision_name, key_type, key_name | ||
|
|
||
| def update_host_keys(self): | ||
| """Update host keys for the container app function host""" | ||
| try: | ||
| resource_group_name, name, revision_name, key_type, key_name = self.validate_host_key_arguments() | ||
| key_value = self.get_argument_key_value() | ||
|
|
||
| return self.client.update_host_keys( | ||
| cmd=self.cmd, | ||
| resource_group_name=resource_group_name, | ||
| name=name, | ||
| key_type=key_type, | ||
| key_name=key_name, | ||
| key_value=key_value | ||
| ) | ||
| except Exception as e: | ||
| handle_raw_exception(e) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please review these commands from Nitesh/Deep as well.