Exemplo n.º 1
0
    def _get_headers(self):
        # Populate HTTP headers
        headers = {
            CustomHeaders.CONTEXT_MARKER.value: self.context_marker,
            CustomHeaders.END_USER.value: self.end_user,
            'X-Auth-Token': get_token()
        }

        return headers
Exemplo n.º 2
0
def _get_validations_for_component(url, design_reference, response, exception,
                                   context_marker, thread_name, **kwargs):
    # Invoke the POST for validation
    try:
        headers = {
            'X-Context-Marker': context_marker,
            'X-Auth-Token': get_token(),
            'content-type': 'application/json'
        }

        http_resp = requests.post(
            url,
            headers=headers,
            data=design_reference,
            timeout=(CONF.requests_config.validation_connect_timeout,
                     CONF.requests_config.validation_read_timeout))
        # 400 response is "valid" failure to validate. > 400 is a problem.
        LOG.debug("%s responded with status code %s", thread_name,
                  http_resp.status_code)
        if http_resp.status_code > 400:
            http_resp.raise_for_status()
        response['response'] = http_resp.json()
    except Exception as ex:
        # catch anything exceptional as a failure to run validations
        unable_str = ('{} unable to validate configdocs or an invalid response'
                      ' has been returned').format(thread_name)
        LOG.exception(unable_str)
        response['response'] = {
            'details': {
                'messageList': [{
                    'message':
                    unable_str,
                    'kind':
                    'ValidationMessage',
                    'error':
                    True,
                    'level':
                    "Error",
                    'diagnostic':
                    '{}: {}'.format(ex.__class__.__name__, str(ex))
                }]
            }
        }
        exception['exception'] = ex
def _get_validations_for_component(url, design_reference, response,
                                   exception, context_marker, thread_name,
                                   **kwargs):
    # Invoke the POST for validation
    try:
        headers = {
            'X-Context-Marker': context_marker,
            'X-Auth-Token': get_token(),
            'content-type': 'application/json'
        }

        http_resp = requests.post(
            url,
            headers=headers,
            data=design_reference,
            timeout=(
                CONF.requests_config.validation_connect_timeout,
                CONF.requests_config.validation_read_timeout))
        # 400 response is "valid" failure to validate. > 400 is a problem.
        if http_resp.status_code > 400:
            http_resp.raise_for_status()
        response_dict = http_resp.json()
        response['response'] = response_dict
    except Exception as ex:
        # catch anything exceptional as a failure to run validations
        unable_str = '{} unable to validate configdocs'.format(thread_name)
        LOG.error("%s. Exception follows.", unable_str)
        LOG.error(str(ex))
        response['response'] = {
            'details': {
                'messageList': [{
                    'message': unable_str,
                    'kind': 'SimpleMessage',
                    'error': True
                }, {
                    'message': str(ex),
                    'kind': 'SimpleMessage',
                    'error': True
                }]
            }
        }
        exception['exception'] = ex
Exemplo n.º 4
0
    def _delete_request(self, url, params=None):
        # invokes a DELETE against the specified URL
        try:
            headers = {
                'X-Context-Marker': self.context_marker,
                'X-Auth-Token': get_token()
            }

            DeckhandClient._log_request('DELETE', url, params)
            response = requests.delete(
                url,
                params=params,
                headers=headers,
                timeout=(CONF.requests_config.deckhand_client_connect_timeout,
                         CONF.requests_config.deckhand_client_read_timeout))
            return response
        except RequestException as rex:
            LOG.error(rex)
            raise DeckhandAccessError(response_message=(
                'Unable to Invoke deckhand: {}'.format(str(rex)), ))
Exemplo n.º 5
0
    def _post_request(self, url, document_data=None, params=None):
        # invokes a POST against the specified URL with the
        # supplied document_data body
        try:
            headers = {
                'X-Context-Marker': self.context_marker,
                'X-Auth-Token': get_token()
            }
            if document_data is not None:
                headers['content-type'] = 'application/x-yaml'

            DeckhandClient._log_request('POST', url, params)
            response = requests.post(
                url,
                params=params,
                headers=headers,
                data=document_data,
                timeout=(CONF.requests_config.deckhand_client_connect_timeout,
                         CONF.requests_config.deckhand_client_read_timeout))
            return response
        except RequestException as rex:
            LOG.error(rex)
            raise DeckhandAccessError(response_message=(
                'Unable to Invoke deckhand: {}'.format(str(rex)), ))
Exemplo n.º 6
0
    def _get_request(self, url, params=None):
        # invokes a GET against the specified URL
        try:
            headers = {
                'content-type': 'application/x-yaml',
                'X-Context-Marker': self.context_marker,
                'X-Auth-Token': get_token()
            }

            if not params:
                params = None

            DeckhandClient._log_request('GET', url, params)
            response = requests.get(
                url,
                params=params,
                headers=headers,
                timeout=(CONF.requests_config.deckhand_client_connect_timeout,
                         CONF.requests_config.deckhand_client_read_timeout))
            return response
        except RequestException as rex:
            LOG.error(rex)
            raise DeckhandAccessError(response_message=(
                'Unable to Invoke deckhand: {}'.format(str(rex)), ))
Exemplo n.º 7
0
def _auth_gen():
    return [('X-Auth-Token', svc_endpoints.get_token())]