Skip to content

Commit

Permalink
add builder for buildpack binding (Azure#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
Incarnation-p-lee authored Dec 21, 2021
1 parent 5310038 commit 459d806
Show file tree
Hide file tree
Showing 7 changed files with 267 additions and 93 deletions.
7 changes: 5 additions & 2 deletions src/spring-cloud/azext_spring_cloud/_enterprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
create_service_registry,
create_gateway,
create_api_portal)
from .buildpack_binding import create_default_buildpack_binding_for_application_insights
from .custom import (app_get, _create_service)
from azure.cli.core.commands.client_factory import get_subscription_id
from azure.cli.core.util import sdk_no_wait
Expand Down Expand Up @@ -58,14 +59,16 @@ def spring_cloud_create(cmd, client, resource_group, name, location=None,
create_application_configuration_service(cmd, client, resource_group, name, enable_application_configuration_service),
create_service_registry(cmd, client, resource_group, name, enable_service_registry),
create_gateway(cmd, client, resource_group, name, enable_gateway),
create_api_portal(cmd, client, resource_group, name, enable_api_portal)]
create_api_portal(cmd, client, resource_group, name, enable_api_portal),
create_default_buildpack_binding_for_application_insights(cmd, client, resource_group, name, location, app_insights_key,
app_insights, sampling_rate, disable_app_insights)
]
pollers = [x for x in pollers if x]
if not no_wait:
_wait_till_end(cmd, *pollers)
return resource



def app_create_enterprise(cmd, client, resource_group, service, name,
assign_endpoint=None,
cpu=None,
Expand Down
54 changes: 31 additions & 23 deletions src/spring-cloud/azext_spring_cloud/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,45 +694,53 @@

helps['spring-cloud build-service buildpacks-binding'] = """
type: group
short-summary: (Enterprise Tier Only) Commands to manage Buildpacks Binding
short-summary: (Enterprise Tier Only) Commands to manage buildpack Binding
"""

helps['spring-cloud build-service buildpacks-binding create'] = """
helps['spring-cloud build-service builder buildpack-binding create'] = """
type: command
short-summary: Create a buildpacks binding.
short-summary: Create a buildpack binding.
examples:
- name: Create a buildpacks binding without properties or secrets.
text: az spring-cloud build-service buildpacks-binding create --name first-binding --type ApplicationInsights
- name: Create a buildpacks binding with only secrets.
text: az spring-cloud build-service buildpacks-binding create --name first-binding --type ApplicationInsights --secrets k1=v1 k2=v2
- name: Create a buildpacks binding with only properties.
text: az spring-cloud build-service buildpacks-binding create --name first-binding --type ApplicationInsights --properties a=b c=d
- name: Create a buildpacks binding with properties and secrets.
text: az spring-cloud build-service buildpacks-binding create --name first-binding --type ApplicationInsights --properties a=b c=d --secrets k1=v1 k2=v2
- name: Create a buildpack binding without properties or secrets.
text: az spring-cloud build-service builder buildpack-binding create --name first-binding --builder-name first-builder --type ApplicationInsights
- name: Create a buildpack binding with only secrets.
text: az spring-cloud build-service builder buildpack-binding create --name first-binding --builder-name first-builder --type ApplicationInsights --secrets k1=v1 k2=v2
- name: Create a buildpack binding with only properties.
text: az spring-cloud build-service builder buildpack-binding create --name first-binding --builder-name first-builder --type ApplicationInsights --properties a=b c=d
- name: Create a buildpack binding with properties and secrets.
text: az spring-cloud build-service builder buildpack-binding create --name first-binding --builder-name first-builder --type ApplicationInsights --properties a=b c=d --secrets k1=v1 k2=v2
"""

helps['spring-cloud build-service buildpacks-binding set'] = """
helps['spring-cloud build-service builder buildpack-binding set'] = """
type: command
short-summary: Set a buildpacks binding.
short-summary: Set a buildpack binding.
examples:
- name: Set a buildpacks binding with properties and secrets.
text: az spring-cloud build-service buildpacks-binding set --name first-binding --type ApplicationInsights --properties a=b c=d --secrets k1=v1 k2=v2
- name: Set a buildpack binding with properties and secrets.
text: az spring-cloud build-service builder buildpack-binding set --name first-binding --builder-name first-builder --type ApplicationInsights --properties a=b c=d --secrets k1=v1 k2=v2
"""

helps['spring-cloud build-service buildpacks-binding show'] = """
helps['spring-cloud build-service builder buildpack-binding show'] = """
type: command
short-summary: Show a buildpacks binding. The secrets will be masked.
short-summary: Show a buildpack binding. The secrets will be masked.
examples:
- name: Show a buildpacks binding.
text: az spring-cloud build-service buildpacks-binding show --name first-binding
- name: Show a buildpack binding.
text: az spring-cloud build-service builder buildpack-binding show --name first-binding --builder-name first-builder
"""

helps['spring-cloud build-service buildpacks-binding delete'] = """
helps['spring-cloud build-service builder buildpack-binding list'] = """
type: command
short-summary: Delete a buildpacks binding.
short-summary: List all buildpack binding in a builder. The secrets will be masked.
examples:
- name: Delete a buildpacks binding.
text: az spring-cloud build-service buildpacks-binding delete --name first-binding
- name: Show a buildpack binding.
text: az spring-cloud build-service builder buildpack-binding list --builder-name first-builder
"""

helps['spring-cloud build-service builder buildpack-binding delete'] = """
type: command
short-summary: Delete a buildpack binding.
examples:
- name: Delete a buildpack binding.
text: az spring-cloud build-service builder buildpack-binding delete --name first-binding --builder-name first-builder
"""

helps['spring-cloud gateway'] = """
Expand Down
53 changes: 37 additions & 16 deletions src/spring-cloud/azext_spring_cloud/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
validate_app_insights_parameters, validate_instance_count, validate_java_agent_parameters,
validate_jar)
from ._validators_enterprise import (validate_config_file_patterns, validate_cpu, validate_memory,
validate_buildpacks_binding_properties,
validate_buildpacks_binding_secrets, only_support_enterprise,
validate_buildpacks_binding_not_exist, validate_buildpacks_binding_exist,
validate_buildpack_binding_properties,
validate_buildpack_binding_secrets, only_support_enterprise,
validate_buildpack_binding_not_exist, validate_buildpack_binding_exist,
validate_git_uri, validate_acs_patterns, validate_routes, validate_builder,
validate_build_pool_size, validate_builder_resource, validate_builder_create,
validate_builder_update)
Expand Down Expand Up @@ -539,34 +539,55 @@ def prepare_logs_argument(c):
with self.argument_context(scope) as c:
c.argument('name', type=str, help="The builder name.")

for scope in ['spring-cloud build-service buildpacks-binding create',
'spring-cloud build-service buildpacks-binding set']:
# BuildpackBinding in Builder
for scope in ['spring-cloud build-service builder buildpack-binding create']:
with self.argument_context(scope) as c:
c.argument('type',
arg_type=get_enum_type(v20220101_preview_AppPlatformEnums.BindingType),
help='Required type for buildpacks binding.')
help='Required type for buildpack binding.')
c.argument('properties',
help='Non-sensitive properties for launchProperties. Format "key[=value]".',
nargs='*',
validator=validate_buildpacks_binding_properties)
validator=validate_buildpack_binding_properties)
c.argument('secrets',
help='Sensitive properties for launchProperties. '
'Once put, it will be encrypted and never return to user. '
'Format "key[=value]".',
nargs='*',
validator=validate_buildpacks_binding_secrets)
validator=validate_buildpack_binding_secrets)
c.argument('name', help='Name for buildpack binding.', validator=validate_buildpack_binding_not_exist)
c.argument('builder_name', help='The name for builder.', default="default")
c.argument('service', service_name_type, validator=only_support_enterprise)


for scope in ['spring-cloud build-service buildpacks-binding create']:
for scope in ['spring-cloud build-service builder buildpack-binding set']:
with self.argument_context(scope) as c:
c.argument('name', help='Name for buildpacks binding.', validator=validate_buildpacks_binding_not_exist)
c.argument('type',
arg_type=get_enum_type(v20220101_preview_AppPlatformEnums.BindingType),
help='Required type for buildpack binding.')
c.argument('properties',
help='Non-sensitive properties for launchProperties. Format "key[=value]".',
nargs='*',
validator=validate_buildpack_binding_properties)
c.argument('secrets',
help='Sensitive properties for launchProperties. '
'Once put, it will be encrypted and never return to user. '
'Format "key[=value]".',
nargs='*',
validator=validate_buildpack_binding_secrets)
c.argument('name', help='Name for buildpack binding.', validator=validate_buildpack_binding_exist)
c.argument('builder_name', help='The name for builder.', default="default")
c.argument('service', service_name_type, validator=only_support_enterprise)


for scope in ['spring-cloud build-service buildpacks-binding set']:
for scope in ['spring-cloud build-service builder buildpack-binding show',
'spring-cloud build-service builder buildpack-binding delete']:
with self.argument_context(scope) as c:
c.argument('name', help='Name for buildpacks binding.', validator=validate_buildpacks_binding_exist)
c.argument('name', help='Name for buildpack binding.', validator=validate_buildpack_binding_exist)
c.argument('builder_name', help='The name for builder.', default="default")
c.argument('service', service_name_type, validator=only_support_enterprise)

for scope in ['spring-cloud build-service buildpacks-binding create',
'spring-cloud build-service buildpacks-binding set',
'spring-cloud build-service buildpacks-binding show',
'spring-cloud build-service buildpacks-binding delete']:
for scope in ['spring-cloud build-service builder buildpack-binding list']:
with self.argument_context(scope) as c:
c.argument('builder_name', help='The name for builder.', default="default")
c.argument('service', service_name_type, validator=only_support_enterprise)
19 changes: 10 additions & 9 deletions src/spring-cloud/azext_spring_cloud/_validators_enterprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _is_valid_app_and_profile_name(pattern):
return len(parts) == 2 and _is_valid_app_name(parts[0]) and _is_valid_profile_name(parts[1])


def validate_buildpacks_binding_properties(namespace):
def validate_buildpack_binding_properties(namespace):
""" Extracts multiple space-separated properties in key[=value] format """
if isinstance(namespace.properties, list):
properties_dict = {}
Expand All @@ -91,7 +91,7 @@ def validate_buildpacks_binding_properties(namespace):
namespace.properties = properties_dict


def validate_buildpacks_binding_secrets(namespace):
def validate_buildpack_binding_secrets(namespace):
""" Extracts multiple space-separated secrets in key[=value] format """
if isinstance(namespace.secrets, list):
secrets_dict = {}
Expand All @@ -100,28 +100,29 @@ def validate_buildpacks_binding_secrets(namespace):
namespace.secrets = secrets_dict


def validate_buildpacks_binding_not_exist(cmd, namespace):
def validate_buildpack_binding_not_exist(cmd, namespace):
client = get_client(cmd)
try:
binding_resource = client.buildpacks_binding.get(namespace.resource_group,
binding_resource = client.buildpack_binding.get(namespace.resource_group,
namespace.service,
DEFAULT_BUILD_SERVICE_NAME,
namespace.builder_name,
namespace.name)
if binding_resource is not None:
raise CLIError('Buildpacks Binding {} already exists '
raise CLIError('buildpack Binding {} in builder {} already exists '
'in resource group {}, service {}. You can edit it by set command.'
.format(namespace.name, namespace.resource_group, namespace.service))
.format(namespace.name, namespace.resource_group, namespace.service, namespace.builder_name))
except ResourceNotFoundError:
# Excepted case
pass


def validate_buildpacks_binding_exist(cmd, namespace):
def validate_buildpack_binding_exist(cmd, namespace):
client = get_client(cmd)
# If not exists exception will be raised
client.buildpacks_binding.get(namespace.resource_group,
client.buildpack_binding.get(namespace.resource_group,
namespace.service,
DEFAULT_BUILD_SERVICE_NAME,
namespace.builder_name,
namespace.name)


Expand Down
Loading

0 comments on commit 459d806

Please sign in to comment.