Example #1
0
    def async_get_request(self,
                          uri,
                          auth_header,
                          params=None,
                          headers=None,
                          timeout=DEFAULT_TIMEOUT):
        """
        Makes a asynchronous get request to a given uri
        :param uri: string representing uri to make request to
        :param params: Optional parameters to be append as the query string to the URL
        :param auth_header: A value to supply for the Authorization header
        :param headers: Optional request headers
        :param timeout: Optional timeout
        :return: result of get request
        """

        uri = encode_whitespace(uri)

        if not headers:
            headers = {HEADER_CONTENT_TYPE: APPLICATION_JSON}

        if auth_header is not None:
            headers[HEADER_AUTHORIZATION] = repr(auth_header)

        LOGGER.debug('GET uri=%s, params=%s' % (uri, str(params)))

        uri = unicode(uri)

        return self.treq.get(url=uri,
                             headers=headers,
                             params=params,
                             timeout=timeout)
def get_all_collections(session_key, app_name=constants.SPACEBRIDGE_APP_NAME):
    uri = encode_whitespace(
        '{}/servicesNS/nobody/{}/storage/collections/config'.format(
            rest.makeSplunkdUri(), app_name))
    params = {'output_mode': 'json'}
    return rest.simpleRequest(uri,
                              sessionKey=session_key,
                              method='GET',
                              getargs=params,
                              raiseAllErrors=True)
Example #3
0
 def __init__(self,
              collection=None,
              session_key=None,
              owner=NOBODY,
              timestamp_attribute_name='timestamp'):
     rest_uri = rest.makeSplunkdUri()
     self.uri = unicode(
         encode_whitespace(
             '{}servicesNS/{}/{}/storage/collections/data/{}'.format(
                 rest_uri, owner, constants.SPACEBRIDGE_APP_NAME,
                 collection)))
     self.session_key = session_key
     self.timestamp_attribute_name = timestamp_attribute_name
Example #4
0
    def async_post_request(self,
                           uri,
                           auth_header,
                           params=None,
                           data=None,
                           headers=None,
                           timeout=DEFAULT_TIMEOUT):
        """
        Makes a asynchronous post request to a given uri
        :param uri: string representing uri to make request to
        :param params: Optional parameters to be append as the query string to the URL
        :param data: Request body
        :param auth_header: A value to supply for the Authorization header
        :param headers: header to send with post request.
        :param timeout: Optional timeout
        :return:
        """

        uri = encode_whitespace(uri)

        if not headers:
            headers = {HEADER_CONTENT_TYPE: APPLICATION_JSON}

        if auth_header is not None:
            headers[HEADER_AUTHORIZATION] = repr(auth_header)

        # In python 3 Treq requires post data to be bytes not string so we need to explicitly encode it
        # https://github.com/twisted/treq/issues/151
        if sys.version_info >= (3, 0) and isinstance(data, str):
            data = data.encode('utf-8')

        # don't log request data as username and passwords can be leaked in plaintext MSB-846
        LOGGER.debug('POST uri=%s, params=%s', uri, params)

        uri = unicode(uri)

        return self.treq.post(url=uri,
                              headers=headers,
                              params=params,
                              data=data,
                              timeout=timeout)