Skip to content

Commit

Permalink
Merge pull request #106 from StrawnSC/autoregister-msft.app
Browse files Browse the repository at this point in the history
Automatically register Microsoft.App RP
  • Loading branch information
StrawnSC committed May 19, 2022
2 parents 0eca228 + 9a85503 commit 6f2943c
Show file tree
Hide file tree
Showing 10 changed files with 2,024 additions and 5,402 deletions.
3 changes: 2 additions & 1 deletion scripts/ci/credscan/CredScanSuppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@
"src\\containerapp\\azext_containerapp\\tests\\latest\\recordings\\test_containerapp_logstream.yaml",
"src\\containerapp\\azext_containerapp\\tests\\latest\\recordings\\test_containerapp_update.yaml",
"src\\containerapp\\azext_containerapp\\tests\\latest\\recordings\\test_containerapp_dapr_e2e.yaml",
"src\\containerapp\\azext_containerapp\\tests\\latest\\recordings\\test_containerapp_up_image_e2e.yaml"
"src\\containerapp\\azext_containerapp\\tests\\latest\\recordings\\test_containerapp_up_image_e2e.yaml",
"src\\containerapp\\azext_containerapp\\tests\\latest\\recordings\\test_containerapp_custom_domains_e2e.yaml"
],
"_justification": "Dummy resources' keys left during testing Microsoft.App (required for log-analytics to create managedEnvironments)"
}
Expand Down
1 change: 1 addition & 0 deletions src/containerapp/azext_containerapp/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
LONG_POLLING_INTERVAL_SECS = 10

LOG_ANALYTICS_RP = "Microsoft.OperationalInsights"
CONTAINER_APPS_RP = "Microsoft.App"

MAX_ENV_PER_LOCATION = 2

Expand Down
16 changes: 7 additions & 9 deletions src/containerapp/azext_containerapp/_up_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@
get_container_app_if_exists,
trigger_workflow,
_ensure_location_allowed,
_is_resource_provider_registered,
_register_resource_provider
register_provider_if_needed
)

from ._constants import MAXIMUM_SECRET_LENGTH, LOG_ANALYTICS_RP
from ._constants import MAXIMUM_SECRET_LENGTH, LOG_ANALYTICS_RP, CONTAINER_APPS_RP

from .custom import (
create_managed_environment,
Expand Down Expand Up @@ -196,8 +195,7 @@ def create_if_needed(self, app_name):

def create(self):
self.location = validate_environment_location(self.cmd, self.location)
if not _is_resource_provider_registered(self.cmd, LOG_ANALYTICS_RP):
_register_resource_provider(self.cmd, LOG_ANALYTICS_RP)
register_provider_if_needed(self.cmd, LOG_ANALYTICS_RP)
env = create_managed_environment(
self.cmd,
self.name,
Expand All @@ -216,7 +214,7 @@ def get_rid(self):
rid = resource_id(
subscription=get_subscription_id(self.cmd.cli_ctx),
resource_group=self.resource_group.name,
namespace="Microsoft.App",
namespace=CONTAINER_APPS_RP,
type="managedEnvironments",
name=self.name,
)
Expand Down Expand Up @@ -828,7 +826,7 @@ def validate_environment_location(cmd, location):

if location:
try:
_ensure_location_allowed(cmd, location, "Microsoft.App", "managedEnvironments")
_ensure_location_allowed(cmd, location, CONTAINER_APPS_RP, "managedEnvironments")
except Exception as e: # pylint: disable=broad-except
raise ValidationError("You cannot create a Containerapp environment in location {}. List of eligible locations: {}.".format(location, allowed_locs)) from e

Expand All @@ -846,7 +844,7 @@ def validate_environment_location(cmd, location):
def list_environment_locations(cmd):
from ._utils import providers_client_factory
providers_client = providers_client_factory(cmd.cli_ctx, get_subscription_id(cmd.cli_ctx))
resource_types = getattr(providers_client.get("Microsoft.App"), 'resource_types', [])
resource_types = getattr(providers_client.get(CONTAINER_APPS_RP), 'resource_types', [])
res_locations = []
for res in resource_types:
if res and getattr(res, 'resource_type', "") == "managedEnvironments":
Expand All @@ -859,7 +857,7 @@ def list_environment_locations(cmd):

def check_env_name_on_rg(cmd, managed_env, resource_group_name, location):
if location:
_ensure_location_allowed(cmd, location, "Microsoft.App", "managedEnvironments")
_ensure_location_allowed(cmd, location, CONTAINER_APPS_RP, "managedEnvironments")
if managed_env and resource_group_name and location:
env_def = None
try:
Expand Down
9 changes: 7 additions & 2 deletions src/containerapp/azext_containerapp/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@
from ._clients import ContainerAppClient, ManagedEnvironmentClient
from ._client_factory import handle_raw_exception, providers_client_factory, cf_resource_groups, log_analytics_client_factory, log_analytics_shared_key_client_factory
from ._constants import (MAXIMUM_CONTAINER_APP_NAME_LENGTH, SHORT_POLLING_INTERVAL_SECS, LONG_POLLING_INTERVAL_SECS,
LOG_ANALYTICS_RP, CHECK_CERTIFICATE_NAME_AVAILABILITY_TYPE)
LOG_ANALYTICS_RP, CONTAINER_APPS_RP, CHECK_CERTIFICATE_NAME_AVAILABILITY_TYPE)
from ._models import (ContainerAppCustomDomainEnvelope as ContainerAppCustomDomainEnvelopeModel)

logger = get_logger(__name__)


def register_provider_if_needed(cmd, rp_name):
if not _is_resource_provider_registered(cmd, rp_name):
_register_resource_provider(cmd, rp_name)


def validate_container_app_name(name):
if name and len(name) > MAXIMUM_CONTAINER_APP_NAME_LENGTH:
raise ValidationError(f"Container App names cannot be longer than {MAXIMUM_CONTAINER_APP_NAME_LENGTH}. "
Expand Down Expand Up @@ -508,7 +513,7 @@ def _get_default_containerapps_location(cmd, location=None):
providers_client = None
try:
providers_client = providers_client_factory(cmd.cli_ctx, get_subscription_id(cmd.cli_ctx))
resource_types = getattr(providers_client.get("Microsoft.App"), 'resource_types', [])
resource_types = getattr(providers_client.get(CONTAINER_APPS_RP), 'resource_types', [])
res_locations = []
for res in resource_types:
if res and getattr(res, 'resource_type', "") == "workspaces":
Expand Down
Loading

0 comments on commit 6f2943c

Please sign in to comment.