示例#1
0
 def add_version(self,
                 version,
                 uri,
                 submitter: User,
                 uuid=None,
                 name=None,
                 hosting_service: models.WorkflowRegistry = None):
     if hosting_service:
         if self.external_id and hasattr(hosting_service,
                                         'get_external_uuid'):
             try:
                 self.uuid = hosting_service.get_external_uuid(
                     self.external_id, version, submitter)
             except RuntimeError as e:
                 raise lm_exceptions.NotAuthorizedException(details=str(e))
         elif not self.external_id and hasattr(hosting_service,
                                               'get_external_id'):
             try:
                 self.external_id = hosting_service.get_external_id(
                     self.uuid, version, submitter)
             except lm_exceptions.EntityNotFoundException:
                 logger.warning(
                     "Unable to associate an external ID to the workflow")
     return WorkflowVersion(self,
                            uri,
                            version,
                            submitter,
                            uuid=uuid,
                            name=name,
                            hosting_service=hosting_service)
示例#2
0
 def add_version(self, version, uri, submitter: User, uuid=None, name=None,
                 hosting_service: models.WorkflowRegistry = None):
     try:
         if hosting_service:
             if self.external_id and hasattr(hosting_service, 'get_external_uuid'):
                 self.uuid = hosting_service.get_external_uuid(self.external_id, version, submitter)
             elif not self.external_id and hasattr(hosting_service, 'get_external_id'):
                 self.external_id = hosting_service.get_external_id(self.uuid, version, submitter)
     except lm_exceptions.EntityNotFoundException as e:
         raise lm_exceptions.NotAuthorizedException(details=str(e))
     return WorkflowVersion(self, uri, version, submitter, uuid=uuid, name=name,
                            hosting_service=hosting_service)
示例#3
0
 def get_user_registry_workflows(
         user: User,
         registry: models.WorkflowRegistry) -> List[models.Workflow]:
     workflows = []
     if registry.get_user(user.id):
         try:
             workflows.extend([
                 w for w in registry.get_user_workflows(user)
                 if w not in workflows
             ])
         except lm_exceptions.NotAuthorizedException as e:
             logger.debug(e)
     return workflows
示例#4
0
def get_token_scopes(access_token):
    """
    The referenced function accepts a token string as argument and
    should return a dict containing a scope field that is either a space-separated list of scopes
    belonging to the supplied token.

    :param access_token:
    :return: a dict containing a scope field that is either a space-separated list of scopes
    belonging to the supplied token.
    """
    token = Token.find(access_token)
    if not token:
        logger.debug("Access token %r not found", access_token)
        raise auth_services.NotAuthorizedException(detail="Invalid token")
    logger.debug("Found a token: %r", token)

    # only if the token has been issued to a user
    # the user has to be automatically logged in
    logger.debug("The token user: %r", token.user)
    if token.user:
        auth_services.login_user(token.user)
    # store the current client
    g.oauth2client = token.client
    # if the client is a Registry, store it on the current session
    from lifemonitor.api.models import WorkflowRegistry
    registry = WorkflowRegistry.find_by_client_id(token.client.client_id)
    logger.debug("Token issued to a WorkflowRegistry: %r", registry
                 is not None)
    if registry:
        auth_services.login_registry(registry)
    return {"scope": token.scope}
示例#5
0
 def deregister_registry_workflow(workflow_uuid, workflow_version, registry: models.WorkflowRegistry):
     workflow = registry.get_workflow(workflow_uuid).versions[workflow_version]
     logger.debug("WorkflowVersion to delete: %r", workflow)
     if not workflow:
         raise lm_exceptions.EntityNotFoundException(models.WorkflowVersion, (workflow_uuid, workflow_version))
     workflow.delete()
     logger.debug("Deleted workflow wf_uuid: %r - version: %r", workflow_uuid, workflow_version)
     return workflow_uuid, workflow_version
示例#6
0
 def get_registry_workflow_version(registry: models.WorkflowRegistry,
                                   uuid,
                                   version=None) -> models.WorkflowVersion:
     w = registry.get_workflow(uuid)
     if w is None:
         raise lm_exceptions.EntityNotFoundException(
             models.WorkflowVersion, f"{uuid}_{version}")
     return w.latest_version if version is None or version == "latest" else w.versions[
         version]
示例#7
0
 def get_workflow_registry_users(registry: models.WorkflowRegistry) -> List[User]:
     return registry.get_users()
示例#8
0
 def get_registry_workflow_version(registry: models.WorkflowRegistry, uuid, version=None) -> models.WorkflowVersion:
     w = registry.get_workflow(uuid)
     return w.latest_version if version is None else w.versions[version]
示例#9
0
 def get_registry_workflow_versions(registry: models.WorkflowRegistry, uuid) -> List[models.WorkflowVersion]:
     return registry.get_workflow(uuid).versions.values()
示例#10
0
 def get_registry_workflows(registry: models.WorkflowRegistry) -> List[models.Workflow]:
     return registry.get_workflows()
示例#11
0
def get_registry(_app_settings, _admin_user):
    registry = WorkflowRegistry.find_by_name("seek")
    if registry is None:
        registry = create_client_credentials_registry(_app_settings,
                                                      _admin_user)
    return registry