-
Notifications
You must be signed in to change notification settings - Fork 1.6k
{containerapp} support connected env command group #6696
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
Merged
zhoxing-ms
merged 15 commits into
Azure:main
from
Greedygre:xinyu/support_connected_env_command_group2
Sep 5, 2023
Merged
Changes from 8 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
56ce297
add connected env group
Greedygre d9e2423
update
Greedygre 3bce709
add help and params
Greedygre 29c1be9
add test
Greedygre f9ce817
add history
Greedygre 3f32af8
fix test
Greedygre eb9a42f
add dependency
Greedygre d8f686a
fix help example and name discription
Greedygre 4b6b2ca
addressed comments
Greedygre 1e6360b
fix test
Greedygre 28803b3
update help
Greedygre 33d5de8
Merge branch 'main' into xinyu/support_connected_env_command_group2
Greedygre cd613c9
use verdor_sdk
Greedygre f41f973
add init file
Greedygre a7eeb23
revert dependencies in setup
Greedygre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
src/containerapp/azext_containerapp/connected_env_decorator.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
| from typing import Any, Dict | ||
|
|
||
| from azure.cli.core.commands import AzCliCommand | ||
| from msrestazure.tools import is_valid_resource_id | ||
|
|
||
| from ._client_factory import handle_raw_exception | ||
| from .base_resource import BaseResource | ||
| from ._constants import CONNECTED_ENVIRONMENT_RESOURCE_TYPE, CONTAINER_APP_EXTENSION_TYPE | ||
| from ._models import ConnectedEnvironment as ConnectedEnvironmentModel, ExtendedLocation as ExtendedLocationModel | ||
| from ._utils import safe_set, _ensure_location_allowed, list_environment_locations, validate_environment_location, \ | ||
| get_custom_location, get_cluster_extension, validate_custom_location | ||
| from azure.cli.core.azclierror import ArgumentUsageError, ValidationError, ResourceNotFoundError | ||
|
|
||
|
|
||
| class ConnectedEnvironmentDecorator(BaseResource): | ||
| def __init__( | ||
| self, cmd: AzCliCommand, client: Any, raw_parameters: Dict, models: str | ||
| ): | ||
| super().__init__(cmd, client, raw_parameters, models) | ||
|
|
||
| def get_argument_custom_location(self): | ||
| return self.get_param("custom_location") | ||
|
|
||
| def get_argument_location(self): | ||
| return self.get_param("location") | ||
|
|
||
| def get_argument_tags(self): | ||
| return self.get_param("tags") | ||
|
|
||
| def get_argument_static_ip(self): | ||
| return self.get_param("static_ip") | ||
|
|
||
| def get_argument_dapr_ai_connection_string(self): | ||
| return self.get_param("dapr_ai_connection_string") | ||
|
|
||
| def set_argument_location(self, location): | ||
| self.set_param("location", location) | ||
|
|
||
| def list(self): | ||
| connected_envs = super().list() | ||
| custom_location = self.get_argument_custom_location() | ||
| if custom_location: | ||
| connected_envs = [c for c in connected_envs if c["extendedLocation"]["name"].lower() == custom_location.lower()] | ||
|
|
||
| return connected_envs | ||
|
|
||
|
|
||
| class ConnectedEnvironmentCreateDecorator(ConnectedEnvironmentDecorator): | ||
| def __init__( | ||
| self, cmd: AzCliCommand, client: Any, raw_parameters: Dict, models: str | ||
| ): | ||
| super().__init__(cmd, client, raw_parameters, models) | ||
| self.connected_env_def = ConnectedEnvironmentModel | ||
|
|
||
| def validate_arguments(self): | ||
| location = validate_environment_location(self.cmd, self.get_argument_location(), CONNECTED_ENVIRONMENT_RESOURCE_TYPE) | ||
| self.set_argument_location(location) | ||
| validate_custom_location(self.cmd, self.get_argument_custom_location()) | ||
|
|
||
| def construct_payload(self): | ||
| self.connected_env_def["location"] = self.get_argument_location() | ||
| if self.get_argument_dapr_ai_connection_string(): | ||
| self.connected_env_def["properties"]["daprAIConnectionString"] = self.get_argument_dapr_ai_connection_string() | ||
|
|
||
| if self.get_argument_static_ip(): | ||
| self.connected_env_def["properties"]["staticIp"] = self.get_argument_static_ip() | ||
|
|
||
| if self.get_argument_tags(): | ||
| self.connected_env_def["tags"] = self.get_argument_tags() | ||
|
|
||
| if self.get_argument_custom_location(): | ||
| extended_location_def = ExtendedLocationModel | ||
| extended_location_def["name"] = self.get_argument_custom_location() | ||
| extended_location_def["type"] = "CustomLocation" | ||
| self.connected_env_def["extendedLocation"] = extended_location_def | ||
|
|
||
| def create(self): | ||
| try: | ||
| r = self.client.create( | ||
| cmd=self.cmd, resource_group_name=self.get_argument_resource_group_name(), name=self.get_argument_name(), | ||
| connected_environment_envelope=self.connected_env_def, no_wait=self.get_argument_no_wait()) | ||
|
|
||
| return r | ||
| except Exception as e: | ||
| handle_raw_exception(e) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.