aboutsummaryrefslogtreecommitdiffstats
path: root/onap-client/onap_client
diff options
context:
space:
mode:
Diffstat (limited to 'onap-client/onap_client')
-rw-r--r--onap-client/onap_client/client/catalog.py11
-rw-r--r--onap-client/onap_client/client/request.py10
-rw-r--r--onap-client/onap_client/config.py11
-rw-r--r--onap-client/onap_client/lib.py4
4 files changed, 25 insertions, 11 deletions
diff --git a/onap-client/onap_client/client/catalog.py b/onap-client/onap_client/client/catalog.py
index 7c2eb0d..abd090d 100644
--- a/onap-client/onap_client/client/catalog.py
+++ b/onap-client/onap_client/client/catalog.py
@@ -64,9 +64,10 @@ class Catalog(ABC):
"""Attached as an attribute for each catalog entry in a catalog.
Used to make a request to ONAP."""
- def __init__(self, catalog_resource, response_callback=None, verify=False):
+ def __init__(self, catalog_resource, response_callback=None, verify=False, proxies={}):
self.resource = catalog_resource
self.verify_request = verify
+ self.proxies = proxies
self.callback = (
response_callback if response_callback else self.empty_callback
)
@@ -78,7 +79,7 @@ class Catalog(ABC):
self.callback(message=f"Submitting request: {self.resource.description}")
response_handler = make_request(
- self.resource, attempts, self.verify_request, **kwargs
+ self.resource, attempts, self.verify_request, self.proxies, **kwargs
)
self.callback(response_handler=response_handler)
@@ -135,7 +136,7 @@ class Catalog(ABC):
self.set_config(config_file)
- def load(self, item_name, resource_data, verify=False):
+ def load(self, item_name, resource_data, verify=False, proxies={}):
"""Consume a catalog resource entry as an APICatalogResource,
and set it as an attribute on this.class as a CallHandle object"""
resource = APICatalogResource(item_name, resource_data)
@@ -147,7 +148,7 @@ class Catalog(ABC):
setattr(
self,
item_name.lower(),
- self.CallHandle(resource, response_callback=callback, verify=verify),
+ self.CallHandle(resource, response_callback=callback, verify=verify, proxies=proxies),
)
def add_to_history(self, message="", response_handler=None):
@@ -212,7 +213,7 @@ class Catalog(ABC):
if isinstance(attr, Catalog):
attr.set_config(config_file)
for k, v in attr.catalog_resources.items():
- attr.load(k, v, verify=verify)
+ attr.load(k, v, verify=verify, proxies=self.config.proxies)
def override(override_key):
def decorator(func):
diff --git a/onap-client/onap_client/client/request.py b/onap-client/onap_client/client/request.py
index d06d748..9ea5e3e 100644
--- a/onap-client/onap_client/client/request.py
+++ b/onap-client/onap_client/client/request.py
@@ -59,13 +59,13 @@ class RequestHandler:
"""
self.request_object = request_object
- def make_request(self, attempts, verify):
+ def make_request(self, attempts, verify, proxies):
r = Request(self.request_object)
logger.info("Submitting request: {}".format(self.request_object.description))
# TODO
# Add verify to config file
- return ResponseHandler(r.request(attempts, verify=verify), self.request_object)
+ return ResponseHandler(r.request(attempts, proxies, verify=verify), self.request_object)
class Request:
@@ -113,7 +113,7 @@ class Request:
except TypeError:
logger.info(debug_request)
- def request(self, attempts, verify=True):
+ def request(self, attempts, proxies, verify=True):
http = requests.Session()
retry_strategy = Retry(
total=attempts,
@@ -126,7 +126,9 @@ class Request:
http.mount("https://", adapter)
http.mount("http://", adapter)
- return http.request(**self.kwargs, verify=verify, timeout=(6.05, int(os.environ.get("ONAP_CLIENT_TIMEOUT", 120))))
+ logger.info(f"Using http proxy for request: {proxies}")
+
+ return http.request(**self.kwargs, proxies=proxies, verify=verify, timeout=(6.05, int(os.environ.get("ONAP_CLIENT_TIMEOUT", 120))))
class APICatalogRequestObject:
diff --git a/onap-client/onap_client/config.py b/onap-client/onap_client/config.py
index e7d9d6d..33b2150 100644
--- a/onap-client/onap_client/config.py
+++ b/onap-client/onap_client/config.py
@@ -91,6 +91,17 @@ class Config:
def application_id(self):
return "robot-ete"
+ @property
+ def http_proxy(self):
+ return self.config.get("HTTP_PROXY")
+
+ @property
+ def proxies(self):
+ return {
+ "http": self.http_proxy,
+ "https": self.http_proxy
+ }
+
def load_config(config_file, *config_args):
config = Config(config_file)
diff --git a/onap-client/onap_client/lib.py b/onap-client/onap_client/lib.py
index 32f5ef5..02d97b5 100644
--- a/onap-client/onap_client/lib.py
+++ b/onap-client/onap_client/lib.py
@@ -43,7 +43,7 @@ from onap_client import exceptions
from onap_client.client.request import RequestHandler, APICatalogRequestObject
-def make_request(catalog_item, attempts, verify_request, **kwargs):
+def make_request(catalog_item, attempts, verify_request, proxies, **kwargs):
"""Makes a request using by merging an APICatalogResource and
kwargs to fill in the required parameters
@@ -56,7 +56,7 @@ def make_request(catalog_item, attempts, verify_request, **kwargs):
request_handler = RequestHandler(catalog_request)
- return request_handler.make_request(attempts, verify_request)
+ return request_handler.make_request(attempts, verify_request, proxies)
def get_request_object(catalog_item, **kwargs):