def handler(event, context):
    request_type = event['RequestType']
    stack_arn = event['StackId']
    physical_resource_id = aws_utils.get_stack_name_from_stack_arn(stack_arn) + '-' + event['LogicalResourceId']
    data = {}
    stack_manager = stack_info.StackInfoManager()
    stack = stack_manager.get_stack_info(stack_arn)

    if request_type == 'Delete':
        _clear_interface_refs(stack)
        return custom_resource_response.success_response(data, physical_resource_id)

    if not stack.is_deployment_stack:
        raise RuntimeError("InterfaceDependecyResolver can only be stood up on a deployment stack")

    resource_groups = stack.resource_groups

    configuration_bucket_name = stack.project.configuration_bucket
    if not configuration_bucket_name:
        raise RuntimeError('Not adding service settings because there is no project configuration bucket.')
    service_directory = ServiceDirectory(configuration_bucket_name)


    interface_deps = event["ResourceProperties"].get("InterfaceDependencies", {})
    _clear_interface_refs(stack)
    for gem, interface_list in interface_deps.iteritems():
        for interface in interface_list:
            print "getting url for interface {} from gem {} to use in {}:{}".format(interface["id"], interface["gem"], gem, interface["function"])
            interfaces = service_directory.get_interface_services(stack.deployment_name, interface["id"])
            if len(interfaces) > 0:
                _add_url_to_lambda(interfaces[0], gem, interface["function"], stack)
            else:
                print "Failed to lookup interface {}".format(len(interfaces))

    return custom_resource_response.success_response(data, physical_resource_id)
예제 #2
0
def get_service_directory(stack):

    configuration_bucket_name = stack.project.configuration_bucket
    if not configuration_bucket_name:
        raise RuntimeError('Cannot register or unregister service interfaces because there is no project service url.')

    return ServiceDirectory(configuration_bucket_name)
def _add_services_settings(stack, settings, services):

    permitted_arns = []

    if not services:
        print 'Not adding service settings because there are none.'
        return permitted_arns

    if not stack.deployment:
        print 'Not adding service settings because the stack is not associated with a deployment.'
        return permitted_arns

    if not stack.project:
        raise RuntimeError(
            'Not adding service settings because there is no project stack.')

    configuration_bucket_name = stack.project.configuration_bucket
    if not configuration_bucket_name:
        raise RuntimeError(
            'Not adding service settings because there is no project configuration bucket.')

    service_directory = ServiceDirectory(configuration_bucket_name)

    services_settings = settings.setdefault('Services', {})
    for service in services:
        _add_service_settings(stack, service_directory,
                              service, services_settings, permitted_arns)

    return permitted_arns
def handler(event, context):
    request_type = event['RequestType']
    stack_arn = event['StackId']
    physical_resource_id = aws_utils.get_stack_name_from_stack_arn(stack_arn) + '-' + event['LogicalResourceId']
    data = {}
    stack_manager = stack_info.StackInfoManager()
    stack = stack_manager.get_stack_info(stack_arn)

    if request_type == 'Delete':
        _clear_interface_refs(stack)
        return custom_resource_response.success_response(data, physical_resource_id)

    if not stack.is_deployment_stack:
        raise RuntimeError("InterfaceDependencyResolver can only be stood up on a deployment stack")

    configuration_bucket_name = stack.project.configuration_bucket
    if not configuration_bucket_name:
        raise RuntimeError('Not adding service settings because there is no project configuration bucket.')
    service_directory = ServiceDirectory(configuration_bucket_name)

    interface_deps = event["ResourceProperties"].get("InterfaceDependencies", {})
    # start by clearing the refs this function and role have to make sure no old permissions/interfaces linger
    _clear_interface_refs(stack)

    for gem, interface_list in iteritems(interface_deps):
        gem_function_info = {}
        for interface in interface_list:
            if not interface['function'] in gem_function_info:
                gem_function_info[interface['function']] = {"interfaces": []}
            interface_function_info = {"id": interface['id'], "gem": interface.get("gem", "CloudGemFramework")}
            if interface_function_info["gem"] == "CloudGemFramework":
                interface_function_info["url"] = _get_project_url(
                    service_directory, interface['id'])
                interface_function_info["permittedArns"] = _get_permitted_arns(
                    _get_resource_group(gem, stack),
                    _get_project_interface_description(
                        service_directory, interface["id"])
                )
            else:
                interface_function_info["url"] = _get_url(
                    service_directory, stack, interface['id'])
                interface_function_info["permittedArns"] = _get_permitted_arns(
                    _get_resource_group(gem, stack),
                    _get_interface_description(service_directory, stack, interface["id"])
                )
            gem_function_info[interface['function']]["interfaces"].append(
                interface_function_info)

        _put_gem_function_info(gem, gem_function_info, stack)

    return custom_resource_response.success_response(data, physical_resource_id)
예제 #5
0
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#

# LambdaService
import service
import errors

# LambdaSettings
import CloudCanvas

# DirectoryService
from cgf_service_directory import ServiceDirectory

# Bucket used to store service data
bucket_name = CloudCanvas.get_setting('ProjectConfigurationBucket')
impl = ServiceDirectory(bucket_name)


@service.api
def put_service_interfaces(request, deployment_name, service_url,
                           service_interfaces_body):

    items = service_interfaces_body.get('Items', None)
    if items is None:
        raise errors.ClientError(
            'Missing required Items property in the request body.')

    try:
        impl.put_service_interfaces(deployment_name, service_url, items)
    except ValueError as e:
        raise errors.ClientError(str(e))