Skip to content

Commit

Permalink
containerapp support additional port mappings (#6594)
Browse files Browse the repository at this point in the history
  • Loading branch information
Greedygre authored Aug 7, 2023
1 parent 050fdd9 commit d4a2155
Show file tree
Hide file tree
Showing 89 changed files with 157,036 additions and 122,841 deletions.
2 changes: 2 additions & 0 deletions src/containerapp/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Upcoming
* 'az containerapp service': add support for creation and deletion of MariaDB
* 'az containerapp create/list': support --environment-type parameter
* 'az containerapp logs show': fix raising error for response status code is not OK
* 'az containerapp auth show/update': support api-version 2023-05-02-preview
* 'az containerapp create': --yaml support property additionalPortMappings for api-version 2023-05-02-preview

0.3.36
++++++
Expand Down
6 changes: 5 additions & 1 deletion src/containerapp/azext_containerapp/_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
logger = get_logger(__name__)

CURRENT_API_VERSION = "2023-04-01-preview"
PREVIEW_API_VERSION = "2023-04-01-preview"
PREVIEW_API_VERSION = "2023-05-02-preview"
ARC_PREVIEW_API_VERSION = "2023-04-01-preview"
POLLING_TIMEOUT = 600 # how many seconds before exiting
POLLING_SECONDS = 2 # how many seconds between requests
Expand Down Expand Up @@ -1522,6 +1522,10 @@ class ManagedEnvironmentPreviewClient(ManagedEnvironmentClient):
api_version = PREVIEW_API_VERSION


class AuthPreviewClient(AuthClient):
api_version = PREVIEW_API_VERSION


class ConnectedEnvironmentClient():
api_version = ARC_PREVIEW_API_VERSION

Expand Down
52 changes: 52 additions & 0 deletions src/containerapp/azext_containerapp/_sdk_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4775,6 +4775,8 @@ class Ingress(_serialization.Model): # pylint: disable=too-many-instance-attrib
~azure.mgmt.appcontainers.models.IngressClientCertificateMode
:ivar cors_policy: CORS policy for container app.
:vartype cors_policy: ~azure.mgmt.appcontainers.models.CorsPolicy
:ivar additional_port_mappings: Additional exposed ports for Container Apps.
:vartype additional_port_mappings: ~azure.mgmt.appcontainers.models.IngressAdditionalPortMapping
"""

_validation = {
Expand All @@ -4794,6 +4796,7 @@ class Ingress(_serialization.Model): # pylint: disable=too-many-instance-attrib
"sticky_sessions": {"key": "stickySessions", "type": "IngressStickySessions"},
"client_certificate_mode": {"key": "clientCertificateMode", "type": "str"},
"cors_policy": {"key": "corsPolicy", "type": "CorsPolicy"},
"additional_port_mappings": {"key": "additionalPortMappings", "type": "[IngressAdditionalPortMapping]"},
}

def __init__(
Expand All @@ -4810,6 +4813,7 @@ def __init__(
sticky_sessions: Optional["_models.IngressStickySessions"] = None,
client_certificate_mode: Optional[Union[str, "_models.IngressClientCertificateMode"]] = None,
cors_policy: Optional["_models.CorsPolicy"] = None,
additional_port_mappings: Optional[List["_models.IngressAdditionalPortMapping"]] = None,
**kwargs: Any
) -> None:
"""
Expand Down Expand Up @@ -4842,6 +4846,8 @@ def __init__(
~azure.mgmt.appcontainers.models.IngressClientCertificateMode
:keyword cors_policy: CORS policy for container app.
:paramtype cors_policy: ~azure.mgmt.appcontainers.models.CorsPolicy
:keyword additional_port_mappings: Additional exposed ports for Container Apps.
:paramtype additional_port_mappings: list[~azure.mgmt.appcontainers.models.IngressAdditionalPortMapping]
"""
super().__init__(**kwargs)
self.fqdn = None
Expand All @@ -4856,6 +4862,7 @@ def __init__(
self.sticky_sessions = sticky_sessions
self.client_certificate_mode = client_certificate_mode
self.cors_policy = cors_policy
self.additional_port_mappings = additional_port_mappings


class IngressStickySessions(_serialization.Model):
Expand Down Expand Up @@ -8350,3 +8357,48 @@ def __init__(
self.minimum_count = minimum_count
self.maximum_count = maximum_count
self.current_count = current_count


class IngressAdditionalPortMapping(_serialization.Model):
"""Port mapping for Container App Ingress.
All required parameters must be populated in order to send to Azure.
:ivar external: Specifies whether the app port is accessible outside of the environment.
:vartype external: bool
:ivar target_port: Specifies the port user's container listens on.
:vartype target_port: int
:ivar exposed_port: Specifies the exposed port for the target port. If not specified, it defaults to target port.
:vartype exposed_port: int
"""

_validation = {
"external": {"required": True},
"target_port": {"required": True},
}

_attribute_map = {
"external": {"key": "external", "type": "bool"},
"target_port": {"key": "targetPort", "type": "int"},
"exposed_port": {"key": "exposedPort", "type": "int"},
}

def __init__(
self,
*,
external: bool,
target_port: int,
exposed_port: Optional[int] = None,
**kwargs: Any
) -> None:
"""
:keyword external: Specifies whether the app port is accessible outside of the environment.
Required.
:paramtype external: bool
:keyword target_port: Specifies the port user's container listens on.
:paramtype target_port: int
:keyword exposed_port: Specifies the exposed port for the target port. If not specified, it defaults to target port.
:paramtype exposed_port: int
"""
super().__init__(**kwargs)
self.external = external
self.target_port = target_port
self.exposed_port = exposed_port
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,9 @@ def get_argument_proxy_custom_proto_header(self):

def get_argument_excluded_paths(self):
return self.get_param("excluded_paths")


# decorator for preview auth show/update
class ContainerAppPreviewAuthDecorator(ContainerAppAuthDecorator):
def construct_payload(self):
super().construct_payload()
16 changes: 8 additions & 8 deletions src/containerapp/azext_containerapp/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@

from .containerapp_job_decorator import ContainerAppJobDecorator, ContainerAppJobCreateDecorator
from .containerapp_env_decorator import ContainerAppEnvDecorator, ContainerAppEnvCreateDecorator, ContainerAppEnvUpdateDecorator
from .containerapp_auth_decorator import ContainerAppAuthDecorator
from .containerapp_decorator import ContainerAppCreateDecorator, BaseContainerAppDecorator, \
ContainerAppPreviewCreateDecorator, ContainerAppPreviewListDecorator
from .containerapp_auth_decorator import ContainerAppPreviewAuthDecorator
from .containerapp_decorator import BaseContainerAppDecorator, ContainerAppPreviewCreateDecorator, ContainerAppPreviewListDecorator
from ._client_factory import handle_raw_exception, handle_non_404_exception
from ._clients import (
ManagedEnvironmentClient,
Expand All @@ -49,7 +48,8 @@
AuthClient,
WorkloadProfileClient,
ContainerAppsJobClient,
ContainerAppPreviewClient
ContainerAppPreviewClient,
AuthPreviewClient
)
from ._dev_service_utils import DevServiceUtils
from ._github_oauth import get_github_access_token
Expand Down Expand Up @@ -5038,9 +5038,9 @@ def update_auth_config(cmd, resource_group_name, name, set_string=None, enabled=
proxy_convention=None, proxy_custom_host_header=None,
proxy_custom_proto_header=None, excluded_paths=None):
raw_parameters = locals()
containerapp_auth_decorator = ContainerAppAuthDecorator(
containerapp_auth_decorator = ContainerAppPreviewAuthDecorator(
cmd=cmd,
client=AuthClient,
client=AuthPreviewClient,
raw_parameters=raw_parameters,
models=CONTAINER_APPS_SDK_MODELS
)
Expand All @@ -5051,9 +5051,9 @@ def update_auth_config(cmd, resource_group_name, name, set_string=None, enabled=

def show_auth_config(cmd, resource_group_name, name):
raw_parameters = locals()
containerapp_auth_decorator = ContainerAppAuthDecorator(
containerapp_auth_decorator = ContainerAppPreviewAuthDecorator(
cmd=cmd,
client=AuthClient,
client=AuthPreviewClient,
raw_parameters=raw_parameters,
models=CONTAINER_APPS_SDK_MODELS
)
Expand Down
Loading

0 comments on commit d4a2155

Please sign in to comment.