예제 #1
0
    def get(cls, context, action_plan_id):
        """Find a action_plan based on its id or uuid and return a Action object.

        :param action_plan_id: the id *or* uuid of a action_plan.
        :returns: a :class:`Action` object.
        """
        if utils.is_int_like(action_plan_id):
            return cls.get_by_id(context, action_plan_id)
        elif utils.is_uuid_like(action_plan_id):
            return cls.get_by_uuid(context, action_plan_id)
        else:
            raise exception.InvalidIdentity(identity=action_plan_id)
예제 #2
0
    def get(cls, context, efficacy_indicator_id):
        """Find an efficacy indicator object given its ID or UUID

        :param efficacy_indicator_id: the ID or UUID of an efficacy indicator.
        :returns: a :class:`EfficacyIndicator` object.
        """
        if utils.is_int_like(efficacy_indicator_id):
            return cls.get_by_id(context, efficacy_indicator_id)
        elif utils.is_uuid_like(efficacy_indicator_id):
            return cls.get_by_uuid(context, efficacy_indicator_id)
        else:
            raise exception.InvalidIdentity(identity=efficacy_indicator_id)
예제 #3
0
파일: action.py 프로젝트: sanfern/watcher
    def get(cls, context, action_id, eager=False):
        """Find a action based on its id or uuid and return a Action object.

        :param action_id: the id *or* uuid of a action.
        :param eager: Load object fields if True (Default: False)
        :returns: a :class:`Action` object.
        """
        if utils.is_int_like(action_id):
            return cls.get_by_id(context, action_id, eager=eager)
        elif utils.is_uuid_like(action_id):
            return cls.get_by_uuid(context, action_id, eager=eager)
        else:
            raise exception.InvalidIdentity(identity=action_id)
예제 #4
0
파일: api.py 프로젝트: icclab/watcher
def add_identity_filter(query, value):
    """Adds an identity filter to a query.

    Filters results by ID, if supplied value is a valid integer.
    Otherwise attempts to filter results by UUID.

    :param query: Initial query to add filter to.
    :param value: Value for filtering results by.
    :return: Modified query.
    """
    if utils.is_int_like(value):
        return query.filter_by(id=value)
    elif utils.is_uuid_like(value):
        return query.filter_by(uuid=value)
    else:
        raise exception.InvalidIdentity(identity=value)
예제 #5
0
 def get_audit_scope(self, context, audit=None):
     scope = None
     try:
         if utils.is_uuid_like(audit) or utils.is_int_like(audit):
             audit = objects.Audit.get(
                 context, audit)
         else:
             audit = objects.Audit.get_by_name(
                 context, audit)
     except exception.AuditNotFound:
         raise exception.InvalidIdentity(identity=audit)
     if audit:
         scope = audit.scope
     else:
         scope = []
     return scope
예제 #6
0
    def get(cls, context, scoring_engine_id):
        """Find a scoring engine based on its id or uuid

        :param context: Security context. NOTE: This should only
                        be used internally by the indirection_api.
                        Unfortunately, RPC requires context as the first
                        argument, even though we don't use it.
                        A context should be set when instantiating the
                        object, e.g.: ScoringEngine(context)
        :param scoring_engine_name: the name of a scoring_engine.
        :returns: a :class:`ScoringEngine` object.
        """
        if utils.is_int_like(scoring_engine_id):
            return cls.get_by_id(context, scoring_engine_id)
        elif utils.is_uuid_like(scoring_engine_id):
            return cls.get_by_uuid(context, scoring_engine_id)
        else:
            raise exception.InvalidIdentity(identity=scoring_engine_id)
예제 #7
0
    def get(cls, context, goal_id):
        """Find a goal based on its id or uuid

        :param context: Security context. NOTE: This should only
                        be used internally by the indirection_api.
                        Unfortunately, RPC requires context as the first
                        argument, even though we don't use it.
                        A context should be set when instantiating the
                        object, e.g.: Goal(context)
        :param goal_id: the id *or* uuid of a goal.
        :returns: a :class:`Goal` object.
        """
        if utils.is_int_like(goal_id):
            return cls.get_by_id(context, goal_id)
        elif utils.is_uuid_like(goal_id):
            return cls.get_by_uuid(context, goal_id)
        else:
            raise exception.InvalidIdentity(identity=goal_id)
예제 #8
0
파일: service.py 프로젝트: akinsWin/watcher
    def get(cls, context, service_id):
        """Find a service based on its id

        :param context: Security context. NOTE: This should only
                        be used internally by the indirection_api.
                        Unfortunately, RPC requires context as the first
                        argument, even though we don't use it.
                        A context should be set when instantiating the
                        object, e.g.: Service(context)
        :param service_id: the id of a service.
        :returns: a :class:`Service` object.
        """
        if utils.is_int_like(service_id):
            db_service = cls.dbapi.get_service_by_id(context, service_id)
            service = Service._from_db_object(cls(context), db_service)
            return service
        else:
            raise exception.InvalidIdentity(identity=service_id)
예제 #9
0
    def get(cls, context, audit_id, eager=False):
        """Find a audit based on its id or uuid and return a Audit object.

        :param context: Security context. NOTE: This should only
                        be used internally by the indirection_api.
                        Unfortunately, RPC requires context as the first
                        argument, even though we don't use it.
                        A context should be set when instantiating the
                        object, e.g.: Audit(context)
        :param audit_id: the id *or* uuid of a audit.
        :param eager: Load object fields if True (Default: False)
        :returns: a :class:`Audit` object.
        """
        if utils.is_int_like(audit_id):
            return cls.get_by_id(context, audit_id, eager=eager)
        elif utils.is_uuid_like(audit_id):
            return cls.get_by_uuid(context, audit_id, eager=eager)
        else:
            raise exception.InvalidIdentity(identity=audit_id)
예제 #10
0
    def get(cls, context, action_id):
        """Find a action description based on its id

        :param context: Security context. NOTE: This should only
                        be used internally by the indirection_api.
                        Unfortunately, RPC requires context as the first
                        argument, even though we don't use it.
                        A context should be set when instantiating the
                        object
        :param action_id: the id of a action description.
        :returns: a :class:`ActionDescription` object.
        """
        if utils.is_int_like(action_id):
            db_action = cls.dbapi.get_action_description_by_id(
                context, action_id)
            action = ActionDescription._from_db_object(cls(context), db_action)
            return action
        else:
            raise exception.InvalidIdentity(identity=action_id)