aboutsummaryrefslogtreecommitdiffstats
path: root/osdf/adapters
diff options
context:
space:
mode:
authorkrishnaa96 <krishna.moorthy6@wipro.com>2021-01-05 11:05:17 +0530
committerkrishnaa96 <krishna.moorthy6@wipro.com>2021-01-05 12:20:23 +0530
commit869b18e4db3be57075cf0deb24d62b33f6c6879a (patch)
tree715f60c354ed1b978f5cd035f1bc3e0f24b8aa34 /osdf/adapters
parent8323a205518f013598d9177c14ce26bcee9e09a3 (diff)
Remove ca-cert from docker image
CA cert can be directly used by the request library. So it is not needed to install in the base image Issue-ID: OPTFRA-891 Signed-off-by: krishnaa96 <krishna.moorthy6@wipro.com> Change-Id: Ia7642cded9057148abcaf0f2f8c9e85d63a08012
Diffstat (limited to 'osdf/adapters')
-rw-r--r--osdf/adapters/dcae/des.py15
-rwxr-xr-xosdf/adapters/dcae/message_router.py37
2 files changed, 30 insertions, 22 deletions
diff --git a/osdf/adapters/dcae/des.py b/osdf/adapters/dcae/des.py
index 57d0371..17517d7 100644
--- a/osdf/adapters/dcae/des.py
+++ b/osdf/adapters/dcae/des.py
@@ -17,9 +17,10 @@
#
import requests
-from requests.auth import HTTPBasicAuth
+from requests.exceptions import HTTPError
from osdf.config.base import osdf_config
+from osdf.utils.interfaces import RestClient
class DESException(Exception):
@@ -36,16 +37,14 @@ def extract_data(service_id, request_data):
config = osdf_config.deployment
user, password = config['desUsername'], config['desPassword']
- auth = HTTPBasicAuth(user, password)
headers = config["desHeaders"]
req_url = config["desUrl"] + config["desApiPath"] + service_id
+ rc = RestClient(userid=user, passwd=password, url=req_url, headers=headers, method="POST")
try:
- response = requests.post(req_url, data=request_data, headers=headers, auth=auth, verify=False)
+ response_json = rc.request(data=request_data)
+ return response_json.get("result")
except requests.RequestException as e:
raise DESException("Request exception was encountered {}".format(e))
-
- if response.status_code == 200:
- return response.json().get("result")
- else:
- raise DESException("Response code other than 200. Response code: {}".format(response.status_code))
+ except HTTPError as ex:
+ raise DESException("Response code other than 200. Response code: {}".format(ex.response.status_code))
diff --git a/osdf/adapters/dcae/message_router.py b/osdf/adapters/dcae/message_router.py
index caf04a4..0968812 100755
--- a/osdf/adapters/dcae/message_router.py
+++ b/osdf/adapters/dcae/message_router.py
@@ -17,8 +17,10 @@
#
import requests
-from osdf.utils.data_types import list_like
+
from osdf.operation.exceptions import MessageBusConfigurationException
+from osdf.utils.data_types import list_like
+from osdf.utils.interfaces import RestClient
class MessageRouterClient(object):
@@ -27,7 +29,8 @@ class MessageRouterClient(object):
consumer_group_id=':',
timeout_ms=15000, fetch_limit=1000,
userid_passwd=':'):
- """
+ """Class initializer
+
:param dmaap_url: protocol, host and port; can also be a list of URLs
(e.g. https://dmaap-host.onapdemo.onap.org:3905/events/org.onap.dmaap.MULTICLOUD.URGENT),
can also be a list of such URLs
@@ -44,14 +47,14 @@ class MessageRouterClient(object):
self.topic_urls = [dmaap_url] if not list_like(dmaap_url) else dmaap_url
self.timeout_ms = timeout_ms
self.fetch_limit = fetch_limit
- userid, passwd = userid_passwd.split(':')
- self.auth = (userid, passwd) if userid and passwd else None
+ self.userid, self.passwd = userid_passwd.split(':')
consumer_group, consumer_id = consumer_group_id.split(':')
self.consumer_group = consumer_group
self.consumer_id = consumer_id
def get(self, outputjson=True):
"""Fetch messages from message router (DMaaP or UEB)
+
:param outputjson: (optional, specifies if response is expected to be in json format), ignored for "POST"
:return: response as a json object (if outputjson is True) or as a string
"""
@@ -61,7 +64,7 @@ class MessageRouterClient(object):
for url in urls[:-1]:
try:
return self.http_request(method='GET', url=url, outputjson=outputjson)
- except:
+ except Exception:
pass
return self.http_request(method='GET', url=urls[-1], outputjson=outputjson)
@@ -69,13 +72,13 @@ class MessageRouterClient(object):
for url in self.topic_urls[:-1]:
try:
return self.http_request(method='POST', url=url, inputjson=inputjson, msg=msg)
- except:
+ except Exception:
pass
return self.http_request(method='POST', url=self.topic_urls[-1], inputjson=inputjson, msg=msg)
def http_request(self, url, method, inputjson=True, outputjson=True, msg=None, **kwargs):
- """
- Perform the actual URL request (GET or POST), and do error handling
+ """Perform the actual URL request (GET or POST), and do error handling
+
:param url: full URL (including topic, limit, timeout, etc.)
:param method: GET or POST
:param inputjson: Specify whether input is in json format (valid only for POST)
@@ -83,9 +86,15 @@ class MessageRouterClient(object):
:param msg: content to be posted (valid only for POST)
:return: response as a json object (if outputjson or POST) or as a string; None if error
"""
- res = requests.request(url=url, method=method, auth=self.auth, **kwargs)
- if res.status_code == requests.codes.ok:
- return res.json() if outputjson or method == "POST" else res.content
- else:
- raise Exception("HTTP Response Error: code {}; headers:{}, content: {}".format(
- res.status_code, res.headers, res.content))
+
+ rc = RestClient(userid=self.userid, passwd=self.passwd, url=url, method=method)
+ try:
+ res = rc.request(raw_response=True, data=msg, **kwargs)
+ if res.status_code == requests.codes.ok:
+ return res.json() if outputjson or method == "POST" else res.content
+ else:
+ raise Exception("HTTP Response Error: code {}; headers:{}, content: {}".format(
+ res.status_code, res.headers, res.content))
+
+ except requests.RequestException as ex:
+ raise Exception("Request Exception occurred {}".format(str(ex)))