summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/resources/scripts/sdcBePy/common
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src/main/resources/scripts/sdcBePy/common')
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/common/healthCheck.py11
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/common/normative/toscaElements.py4
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/common/normative/toscaTypes.py4
-rwxr-xr-xcatalog-be/src/main/resources/scripts/sdcBePy/common/sdcBeProxy.py32
4 files changed, 32 insertions, 19 deletions
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/common/healthCheck.py b/catalog-be/src/main/resources/scripts/sdcBePy/common/healthCheck.py
index c99db5b434..a0acc90d44 100644
--- a/catalog-be/src/main/resources/scripts/sdcBePy/common/healthCheck.py
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/common/healthCheck.py
@@ -12,9 +12,9 @@ from sdcBePy.common.sdcBeProxy import SdcBeProxy
colors = BColors()
-def check_backend(sdc_be_proxy=None, reply_append_count=1, be_host=None, be_port=None, scheme=None, debug=False):
+def check_backend(sdc_be_proxy=None, reply_append_count=1, be_host=None, be_port=None, header=None, scheme=None, debug=False):
if sdc_be_proxy is None:
- sdc_be_proxy = SdcBeProxy(be_host, be_port, scheme, debug=debug)
+ sdc_be_proxy = SdcBeProxy(be_host, be_port, header, scheme, debug=debug)
for i in range(1, reply_append_count + 1):
if sdc_be_proxy.check_backend() == 200:
@@ -28,9 +28,9 @@ def check_backend(sdc_be_proxy=None, reply_append_count=1, be_host=None, be_port
return False
-def run(be_host, be_port, protocol):
+def run(be_host, be_port, header, protocol):
if not check_backend(reply_append_count=properties.retry_attempts, be_host=be_host,
- be_port=be_port, scheme=protocol):
+ be_port=be_port, header=header, scheme=protocol):
print('[ERROR]: ' + time.strftime('%Y/%m/%d %H:%M:%S') + colors.FAIL + ' Backend is DOWN :-(' + colors.END_C)
sys.exit()
@@ -40,12 +40,13 @@ def get_args():
parser.add_argument('-i', '--ip', required=True)
parser.add_argument('-p', '--port', required=True)
+ parser.add_argument('--header')
parser.add_argument('--https', action='store_true')
args = parser.parse_args()
init_properties(10, 10)
- return [args.ip, args.port, 'https' if args.https else 'http']
+ return [args.ip, args.port, args.header, 'https' if args.https else 'http']
def main():
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/common/normative/toscaElements.py b/catalog-be/src/main/resources/scripts/sdcBePy/common/normative/toscaElements.py
index 5cdca0a095..5ef3173907 100644
--- a/catalog-be/src/main/resources/scripts/sdcBePy/common/normative/toscaElements.py
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/common/normative/toscaElements.py
@@ -9,11 +9,11 @@ from sdcBePy.common.errors import ResourceCreationError
def process_and_create_normative_element(normative_element,
- scheme=None, be_host=None, be_port=None, admin_user=None, sdc_be_proxy=None,
+ scheme=None, be_host=None, be_port=None, header=None, admin_user=None, sdc_be_proxy=None,
debug=False,
exit_on_success=False):
if sdc_be_proxy is None:
- sdc_be_proxy = SdcBeProxy(be_host, be_port, scheme, admin_user, debug=debug)
+ sdc_be_proxy = SdcBeProxy(be_host, be_port, header, scheme, admin_user, debug=debug)
file_dir, url_suffix, element_name, element_from_name, with_metadata = normative_element.get_parameters()
_create_normative_element(sdc_be_proxy,
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/common/normative/toscaTypes.py b/catalog-be/src/main/resources/scripts/sdcBePy/common/normative/toscaTypes.py
index 5d64f448d3..97fb2d1d7e 100644
--- a/catalog-be/src/main/resources/scripts/sdcBePy/common/normative/toscaTypes.py
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/common/normative/toscaTypes.py
@@ -9,13 +9,13 @@ from sdcBePy.common.sdcBeProxy import SdcBeProxy
def process_and_create_normative_types(normative_type,
- scheme=None, be_host=None, be_port=None, admin_user=None,
+ scheme=None, be_host=None, be_port=None, header=None, admin_user=None,
sdc_be_proxy=None,
update_version=False,
debug=False,
exit_on_success=False):
if sdc_be_proxy is None:
- sdc_be_proxy = SdcBeProxy(be_host, be_port, scheme, admin_user, debug=debug)
+ sdc_be_proxy = SdcBeProxy(be_host, be_port, header, scheme, admin_user, debug=debug)
file_dir, normative_type_list = normative_type.get_parameters()
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/common/sdcBeProxy.py b/catalog-be/src/main/resources/scripts/sdcBePy/common/sdcBeProxy.py
index d9aa260b80..169979ae73 100755
--- a/catalog-be/src/main/resources/scripts/sdcBePy/common/sdcBeProxy.py
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/common/sdcBeProxy.py
@@ -15,21 +15,22 @@ class SdcBeProxy:
BODY_SEPARATOR = "\r\n\r\n"
CHARTSET = 'UTF-8'
- def __init__(self, be_ip, be_port, scheme, user_id="jh0003",
+ def __init__(self, be_ip, be_port, header, scheme, user_id="jh0003",
debug=False, connector=None):
if not check_arguments_not_none(be_ip, be_port, scheme, user_id):
raise AttributeError("The be_host, be_port, scheme or admin_user are missing")
url = get_url(be_ip, be_port, scheme)
self.con = connector if connector \
- else CurlConnector(url, user_id, scheme=scheme, debug=debug)
+ else CurlConnector(url, user_id, header, scheme=scheme, debug=debug)
def check_backend(self):
return self.con.get('/sdc2/rest/v1/user/jh0003')
def check_user(self, user_name):
- return self.con.get("/sdc2/rest/v1/user/" + user_name)
+ return self.con.get("/sdc2/rest/v1/user" + user_name)
def create_user(self, first_name, last_name, user_id, email, role):
+
return self.con.post('/sdc2/rest/v1/user', json.dumps({
'firstName': first_name,
'lastName': last_name,
@@ -39,10 +40,10 @@ class SdcBeProxy:
}))
def check_consumer(self, consumer_name):
- return self.con.get("/sdc2/rest/v1/consumers/" + consumer_name)
+ return self.con.get("/sdc2/rest/v1/consumers" + consumer_name)
def create_consumer(self, consumer_name, slat, password):
- return self.con.post("/sdc2/rest/v1/consumers/", json.dumps({
+ return self.con.post("/sdc2/rest/v1/consumers", json.dumps({
'consumerName': consumer_name,
'consumerSalt': slat,
'consumerPassword': password
@@ -67,7 +68,7 @@ class CurlConnector:
CONTENT_TYPE_HEADER = "Content-Type: application/json"
ACCEPT_HEADER = "Accept: application/json; charset=UTF-8"
- def __init__(self, url, user_id_header, buffer=None, scheme="http", debug=False):
+ def __init__(self, url, user_id_header, header, buffer=None, scheme="http", debug=False):
self.c = pycurl.Curl()
self.c.setopt(pycurl.HEADER, True)
@@ -82,6 +83,11 @@ class CurlConnector:
if not buffer:
self.buffer = BytesIO()
+ if header is None:
+ self.basicauth_header = ""
+ else:
+ self.basicauth_header = "Authorization: Basic " + header
+
self.url = url
self._check_schema(scheme)
@@ -90,7 +96,9 @@ class CurlConnector:
self.c.setopt(pycurl.URL, self.url + path)
self.c.setopt(pycurl.HTTPHEADER, [self.user_header,
CurlConnector.CONTENT_TYPE_HEADER,
- CurlConnector.ACCEPT_HEADER])
+ CurlConnector.ACCEPT_HEADER,
+ self.basicauth_header])
+
if with_buffer:
write = self.buffer.write if not buffer else buffer.write
@@ -105,9 +113,11 @@ class CurlConnector:
try:
self.c.setopt(pycurl.URL, self.url + path)
self.c.setopt(pycurl.POST, 1)
+
self.c.setopt(pycurl.HTTPHEADER, [self.user_header,
- CurlConnector.CONTENT_TYPE_HEADER,
- CurlConnector.ACCEPT_HEADER])
+ CurlConnector.CONTENT_TYPE_HEADER,
+ CurlConnector.ACCEPT_HEADER,
+ self.basicauth_header])
self.c.setopt(pycurl.POSTFIELDS, data)
@@ -122,7 +132,9 @@ class CurlConnector:
try:
self.c.setopt(pycurl.URL, self.url + path)
self.c.setopt(pycurl.POST, 1)
- self.c.setopt(pycurl.HTTPHEADER, [self.user_header])
+ self.c.setopt(pycurl.HTTPHEADER, [self.user_header,
+ self.basicauth_header])
+
self.c.setopt(pycurl.HTTPPOST, post_body)