Example #1
0
async def register(request):
    """ Registers a new redirect with the server. """

    if not is_authorized(request):
        raise ex.HTTPUnauthorized()

    data = await request.json(loads=quiet_json)
    ttl = int(data.get('ttl', 3600))

    token = random_token()

    try:
        method = data['method'].upper()

        if method not in ('GET', 'POST', 'PUT'):
            raise ex.HTTPBadRequest(
                reason="Unsupported HTTP method {}".format(method))

        request.app.db[token] = {
            'url': data['url'],
            'expiration': datetime.utcnow() + timedelta(seconds=ttl),
            'secret': data['secret'],
            'method': method,
            'success_url': data['success_url'],
            'error_url': data['error_url']
        }
    except KeyError as e:
        raise ex.HTTPBadRequest(reason="Missing key: {}".format(e.args[0]))

    return web.json_response({'token': token})
Example #2
0
async def services_get(request: web.Request,
                       service_type: Optional[str] = None) -> web.Response:
    log.debug(
        "Client does services_get request %s with service_type %s",
        request,
        service_type,
    )
    try:
        services = []
        if not service_type:
            services = await registry_proxy.list_services(
                request.app, registry_proxy.ServiceType.ALL)
        elif "computational" in service_type:
            services = await registry_proxy.list_services(
                request.app, registry_proxy.ServiceType.COMPUTATIONAL)
        elif "interactive" in service_type:
            services = await registry_proxy.list_services(
                request.app, registry_proxy.ServiceType.DYNAMIC)
        # NOTE: the validation is done in the catalog. This entrypoint IS and MUST BE only used by the catalog!!
        # NOTE2: the catalog will directly talk to the registry see case #2165 [https://github.com/ITISFoundation/osparc-simcore/issues/2165]
        # services = node_validator.validate_nodes(services)
        return web.json_response(data=dict(data=services))
    except exceptions.RegistryConnectionError as err:
        raise web_exceptions.HTTPUnauthorized(reason=str(err))
    except Exception as err:
        raise web_exceptions.HTTPInternalServerError(reason=str(err))
Example #3
0
async def services_by_key_version_get(request, service_key, service_version):  # pylint:disable=unused-argument
    log.debug(
        "Client does services_get request %s with service_key %s, service_version %s",
        request, service_key, service_version)
    try:
        services = [
            await registry_proxy.get_service_details(service_key,
                                                     service_version)
        ]
        return web.json_response(data=dict(data=services))
    except exceptions.ServiceNotAvailableError as err:
        raise web_exceptions.HTTPNotFound(reason=str(err))
    except exceptions.RegistryConnectionError as err:
        raise web_exceptions.HTTPUnauthorized(reason=str(err))
    except Exception as err:
        raise web_exceptions.HTTPInternalServerError(reason=str(err))
Example #4
0
async def services_get(request, service_type=None):  # pylint:disable=unused-argument
    log.debug("Client does services_get request %s with service_type %s",
              request, service_type)
    try:
        services = []
        if not service_type or "computational" in service_type:
            services.extend(await _list_services(
                registry_proxy.list_computational_services))
        if not service_type or "interactive" in service_type:
            services.extend(await _list_services(
                registry_proxy.list_interactive_services))
        return web.json_response(data=dict(data=services))
    except exceptions.RegistryConnectionError as err:
        raise web_exceptions.HTTPUnauthorized(reason=str(err))
    except Exception as err:
        raise web_exceptions.HTTPInternalServerError(reason=str(err))
Example #5
0
async def get_service_labels(request: web.Request, service_key: str,
                             service_version: str) -> web.Response:
    log.debug(
        "Retrieving service labels %s with service_key %s, service_version %s",
        request,
        service_key,
        service_version,
    )
    try:
        service_labels = await registry_proxy.get_image_labels(
            request.app, service_key, service_version)
        return web.json_response(data=dict(data=service_labels))
    except exceptions.ServiceNotAvailableError as err:
        raise web_exceptions.HTTPNotFound(reason=str(err))
    except exceptions.RegistryConnectionError as err:
        raise web_exceptions.HTTPUnauthorized(reason=str(err))
    except Exception as err:
        raise web_exceptions.HTTPInternalServerError(reason=str(err))
Example #6
0
async def services_by_key_version_get(request: web.Request, service_key: str,
                                      service_version: str) -> web.Response:
    log.debug(
        "Client does services_get request %s with service_key %s, service_version %s",
        request,
        service_key,
        service_version,
    )
    try:
        services = [
            await registry_proxy.get_image_details(request.app, service_key,
                                                   service_version)
        ]
        return web.json_response(data=dict(data=services))
    except exceptions.ServiceNotAvailableError as err:
        raise web_exceptions.HTTPNotFound(reason=str(err))
    except exceptions.RegistryConnectionError as err:
        raise web_exceptions.HTTPUnauthorized(reason=str(err))
    except Exception as err:
        raise web_exceptions.HTTPInternalServerError(reason=str(err))
Example #7
0
async def running_interactive_services_post(
    request: web.Request,
    user_id: str,
    project_id: str,
    service_key: str,
    service_uuid: str,
    service_tag: str,
    service_basepath: str,
) -> web.Response:
    log.debug(
        "Client does running_interactive_services_post request %s with user_id %s, project_id %s, service %s:%s, service_uuid %s, service_basepath %s",
        request,
        user_id,
        project_id,
        service_key,
        service_tag,
        service_uuid,
        service_basepath,
    )
    try:
        service = await producer.start_service(
            request.app,
            user_id,
            project_id,
            service_key,
            service_tag,
            service_uuid,
            service_basepath,
        )
        return web.json_response(data=dict(data=service), status=201)
    except exceptions.ServiceStartTimeoutError as err:
        raise web_exceptions.HTTPInternalServerError(reason=str(err))
    except exceptions.ServiceNotAvailableError as err:
        raise web_exceptions.HTTPNotFound(reason=str(err))
    except exceptions.ServiceUUIDInUseError as err:
        raise web_exceptions.HTTPConflict(reason=str(err))
    except exceptions.RegistryConnectionError as err:
        raise web_exceptions.HTTPUnauthorized(reason=str(err))
    except Exception as err:
        raise web_exceptions.HTTPInternalServerError(reason=str(err))
Example #8
0
async def services_get(request: web.Request,
                       service_type: Optional[str] = None) -> web.Response:
    log.debug(
        "Client does services_get request %s with service_type %s",
        request,
        service_type,
    )
    try:
        services = []
        if not service_type:
            services = await registry_proxy.list_services(
                request.app, registry_proxy.ServiceType.ALL)
        elif "computational" in service_type:
            services = await registry_proxy.list_services(
                request.app, registry_proxy.ServiceType.COMPUTATIONAL)
        elif "interactive" in service_type:
            services = await registry_proxy.list_services(
                request.app, registry_proxy.ServiceType.DYNAMIC)
        services = node_validator.validate_nodes(services)
        return web.json_response(data=dict(data=services))
    except exceptions.RegistryConnectionError as err:
        raise web_exceptions.HTTPUnauthorized(reason=str(err))
    except Exception as err:
        raise web_exceptions.HTTPInternalServerError(reason=str(err))