def add_indicator(self, data, indicator_type=None):
    """ filter api results by indicator """
    # validation indicator
    if not SharedMethods.validate_indicator(self.tc._indicators_regex, data):
        raise AttributeError(ErrorCodes.e5010.value.format(data))

    # get indicator uri attribute

    if indicator_type is None:
        indicator_type = SharedMethods.get_resource_type(
            self.tc._indicators_regex, data)
    indicator_uri_attribute = ApiProperties.api_properties[
        indicator_type.name]['uri_attribute']

    prop = self._resource_properties['indicator']
    ro = RequestObject()
    ro.set_description('api filter by indicator id {0}'.format(data))
    ro.set_owner_allowed(prop['owner_allowed'])
    # TODO: Check this logic
    if self._resource_type == ResourceType.INDICATORS:
        ro.set_request_uri(
            prop['uri'],
            [indicator_uri_attribute,
             SharedMethods.urlsafe(data)])
    else:
        ro.set_request_uri(prop['uri'], [SharedMethods.urlsafe(data)])
    ro.set_resource_pagination(prop['pagination'])
    ro.set_resource_type(indicator_type)
    self._add_request_objects(ro)
def add_indicator(self, data, indicator_type = None):
    """ filter api results by indicator """
    # validation indicator
    if not SharedMethods.validate_indicator(self.tc._indicators_regex, data):
        raise AttributeError(ErrorCodes.e5010.value.format(data))

    # get indicator uri attribute

    if indicator_type is None:
        indicator_type = SharedMethods.get_resource_type(self.tc._indicators_regex, data)
    indicator_uri_attribute = ApiProperties.api_properties[indicator_type.name]['uri_attribute']



    prop = self._resource_properties['indicator']
    ro = RequestObject()
    ro.set_description('api filter by indicator id {0}'.format(data))
    ro.set_owner_allowed(prop['owner_allowed'])
    # TODO: Check this logic
    if self._resource_type == ResourceType.INDICATORS:
        ro.set_request_uri(prop['uri'], [indicator_uri_attribute, SharedMethods.urlsafe(data)])
    else:
        ro.set_request_uri(prop['uri'], [SharedMethods.urlsafe(data)])
    ro.set_resource_pagination(prop['pagination'])
    ro.set_resource_type(indicator_type)
    self._add_request_objects(ro)
def add_indicator(self, data):
    """ """
    # validation indicator
    if not SharedMethods.validate_indicator(data):
        raise AttributeError(ErrorCodes.e5010.value.format(data))

    # get indicator uri attribute
    indicator_type = SharedMethods.get_resource_type(data)
    indicator_uri_attribute = ApiProperties.api_properties[indicator_type.name]['uri_attribute']

    prop = self._resource_properties['indicators']
    ro = RequestObject()
    ro.set_description('api filter by indicator id {0}'.format(data))
    ro.set_owner_allowed(prop['owner_allowed'])
    ro.set_request_uri(prop['uri'], [indicator_uri_attribute, SharedMethods.urlsafe(data)])
    ro.set_resource_pagination(prop['pagination'])
    ro.set_resource_type(self._resource_type)
    self._add_request_objects(ro)
def add_indicator(self, data):
    """ """
    # validation indicator
    if not SharedMethods.validate_indicator(self.tc._indicators_regex, data):
        raise AttributeError(ErrorCodes.e5010.value.format(data))

    # get indicator uri attribute
    indicator_type = SharedMethods.get_resource_type(self.tc._indicators_regex, data)
    indicator_uri_attribute = ApiProperties.api_properties[indicator_type.name]['uri_attribute']

    prop = self._resource_properties['indicators']
    ro = RequestObject()
    ro.set_description('api filter by indicator id {0}'.format(data))
    ro.set_owner_allowed(prop['owner_allowed'])
    ro.set_request_uri(prop['uri'], [indicator_uri_attribute, SharedMethods.urlsafe(data)])
    ro.set_resource_pagination(prop['pagination'])
    ro.set_resource_type(self._resource_type)
    self._add_request_objects(ro)
Exemplo n.º 5
0
def add_tag(self, data):
    """ """
    if not isinstance(data, str):
        raise AttributeError(ErrorCodes.e4070.value.format(data))

    prop = self._resource_properties['tags']
    ro = RequestObject()
    ro.set_description('api filter by tag "{0}"'.format(data))
    ro.set_owner_allowed(prop['owner_allowed'])
    ro.set_resource_pagination(prop['pagination'])
    ro.set_request_uri(prop['uri'], [SharedMethods.urlsafe(data)])
    ro.set_resource_type(self._resource_type)
    self._add_request_objects(ro)
def add_security_label(self, data):
    """ filter api results by security label """
    # validation of data input
    if not isinstance(data, str):
        raise AttributeError(ErrorCodes.e4050.value.format(data))

    prop = self._resource_properties['security_labels']
    ro = RequestObject()
    ro.set_description('api filter by security label "{0}"'.format(data))
    ro.set_owner_allowed(prop['owner_allowed'])
    ro.set_resource_pagination(prop['pagination'])
    ro.set_request_uri(prop['uri'], [SharedMethods.urlsafe(data)])
    ro.set_resource_type(self._resource_type)
    self._add_request_objects(ro)
def add_security_label(self, data):
    """ filter api results by security label """
    # validation of data input
    if not isinstance(data, str):
        raise AttributeError(ErrorCodes.e4050.value.format(data))

    prop = self._resource_properties['security_labels']
    ro = RequestObject()
    ro.set_description('api filter by security label "{0}"'.format(data))
    ro.set_owner_allowed(prop['owner_allowed'])
    ro.set_resource_pagination(prop['pagination'])
    ro.set_request_uri(prop['uri'], [SharedMethods.urlsafe(data)])
    ro.set_resource_type(self._resource_type)
    self._add_request_objects(ro)
Exemplo n.º 8
0
    def add(self, indicator, owner=None, type=None, api_entity=None):
        """ add indicator to resource container """
        if type is not None:
            if isinstance(type, IndicatorType):
                if type == IndicatorType.CUSTOM_INDICATORS and not isinstance(indicator, OrderedDict):
                    # change dicts to be Ordered before calling set_indicator
                    field_names = self.tc.indicator_parser.get_field_labels_by_api_entity(api_entity)
                    ordered_indicator = OrderedDict()
                    for field_name in field_names:
                        ordered_indicator[field_name] = indicator.get(field_name)

                    indicator = ordered_indicator

                # generate unique temporary id
                resource_id = uuid.uuid4().int

                # resource object
                resource_obj = self.tc.indicator_parser.construct_typed_indicator(ResourceType(type.value), api_entity=api_entity)
                resource_obj.set_id(int(resource_id))  # set temporary resource id
                resource_obj.set_indicator(indicator, ResourceType(type.value), False)
                resource_obj.set_owner_name(owner)
                resource_obj.set_phase(1)  # set resource api phase (1 = add)

                return self._method_wrapper(resource_obj)

            else:
                raise AttributeError(ErrorCodes.e10060.name.format(indicator))

        elif SharedMethods.validate_indicator(self.tc._indicators_regex, indicator):
            # validate indicator

            # generate unique temporary id
            resource_id = uuid.uuid4().int

            resource_type = get_resource_type(self.tc._indicators_regex, indicator)

            # resource object
            resource_obj = self.tc.indicator_parser.construct_typed_indicator(resource_type)
            resource_obj.set_id(int(resource_id))  # set temporary resource id
            resource_obj.set_indicator(indicator, resource_type, False)
            resource_obj.set_owner_name(owner)
            resource_obj.set_phase(1)  # set resource api phase (1 = add)

            # return object for modification
            return self._method_wrapper(resource_obj)
        else:
            raise AttributeError(ErrorCodes.e10050.name.format(indicator))
Exemplo n.º 9
0
    def add(self, indicator, owner=None, type=None):
        """ add indicator to resource container """

        if type is not None:
            if isinstance(type, IndicatorType):
                # generate unique temporary id
                resource_id = uuid.uuid4().int

                # resource object
                resource_obj = IndicatorObject()
                resource_obj.set_id(int(resource_id))  # set temporary resource id
                # resource_obj.set_resource_type(ResourceType(type.value)) # set this before indicator
                resource_obj.set_indicator(indicator, ResourceType(type.value), False)
                resource_obj.set_owner_name(owner)
                resource_obj.set_phase(1)  # set resource api phase (1 = add)

                # return object for modification
                return self._method_wrapper(resource_obj)
            else:
                raise AttributeError(ErrorCodes.e10060.name.format(indicator))

        elif SharedMethods.validate_indicator(self.tc._indicators_regex, indicator):
            # validate indicator

            # generate unique temporary id
            resource_id = uuid.uuid4().int

            # resource object
            resource_obj = IndicatorObject()
            resource_obj.set_id(int(resource_id))  # set temporary resource id
            resource_type = get_resource_type(self.tc._indicators_regex, indicator)
            resource_obj.set_indicator(indicator, resource_type, False)
            resource_obj.set_owner_name(owner)
            resource_obj.set_phase(1)  # set resource api phase (1 = add)

            # return object for modification
            return self._method_wrapper(resource_obj)
        else:
            raise AttributeError(ErrorCodes.e10050.name.format(indicator))
 def set_method(self, data):
     """ set post filter method name for getattr """
     self._method = SharedMethods.uni(data)
 def set_filter(self, data):
     """ set post filter data to filter on """
     self._filter = SharedMethods.uni(data)
 def set_description(self, data):
     """ set post filter description """
     self._description = SharedMethods.uni(data)
Exemplo n.º 13
0
 def set_status_code(self, data_int):
     """ """
     self._status_code = SharedMethods.uni(data_int)
Exemplo n.º 14
0
 def set_failure_msg(self, data):
     """ """
     self._failure_msg = SharedMethods.uni(data)
Exemplo n.º 15
0
 def set_request_url(self, data):
     """ """
     self._request_url = SharedMethods.uni(data)