diff --git a/alpine/apiclient.py b/alpine/apiclient.py index 4231080..1521c42 100644 --- a/alpine/apiclient.py +++ b/alpine/apiclient.py @@ -41,8 +41,8 @@ def __init__(self, host=None, port=None, username=None, password=None, is_secure :param str username: Username to log in with. :param str password: Password to log in with. :param bool is_secure: True for HTTPS, else false. - :param bool validate_certs: - :param ca_certs: + :param bool validate_certs: True for SSL Verification, else false + :param ca_certs: If String, Path to SSL client certificate file(.pem). If Tuple, ('cert', 'key') pair :param str token: Alpine API authentication token. :param str logging_level: Use to set the logging level. See https://docs.python.org/2/howto/logging.html#logging-levels. @@ -51,7 +51,6 @@ def __init__(self, host=None, port=None, username=None, password=None, is_secure super(APIClient, self).__init__(token=token) self._setup_logging(default_level=logging_level) - self.is_secure = is_secure if is_secure: self.protocol = 'https' @@ -64,13 +63,20 @@ def __init__(self, host=None, port=None, username=None, password=None, is_secure self.host = host else: self.host = "{0}:{1}".format(host, port) - + ### disable InsecureRequestWarning + requests.packages.urllib3.disable_warnings() self.session = requests.Session() # instantiate a session for requests self.base_url = "{0}://{1}/api".format(self.protocol, self.host) - self.ca_certs = ca_certs - self.validate_certs = validate_certs + self.verify = False + if validate_certs == False or ca_certs is None: + self.verify = validate_certs + else: + self.verify = ca_certs + + self.session.verify = self.verify + self.user_id = None if username and password: self.login(username, password) @@ -94,20 +100,12 @@ def login(self, username, password): url = "{0}/sessions?session_id=NULL".format(self.base_url) # url = self.base_url + "/sessions?session_id=NULL" body = {"username": username, "password": password} - # TODO login with cert. - cert_path = os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), - "../host_deploy/resource/ssl/certificates/test.crt") - - key_path = os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), - "../host_deploy/resource/ssl/certificates/test.key") - self.session.headers.update({"Content-Type": "application/x-www-form-urlencoded"}) if self.protocol == 'http': login_response = self.session.post(url, data=body) else: login_response = self.session.post(url, data=body, - verify=self.validate_certs, cert=(cert_path, key_path), headers={'Connection': 'close'}) if login_response.status_code == 201: response = login_response.json() diff --git a/doc/logo.png b/doc/logo.png index d8b6da4..884a547 100644 Binary files a/doc/logo.png and b/doc/logo.png differ diff --git a/tests/api/alpineunittest.py b/tests/api/alpineunittest.py index 9834b55..38de6b5 100644 --- a/tests/api/alpineunittest.py +++ b/tests/api/alpineunittest.py @@ -19,9 +19,12 @@ class AlpineTestCase(TestCase): def setUp(self): - self.host = "10.0.0.205" - self.port = "8080" - self.regex_alpine_version_string = "6.3.*" + self.is_secure = True + self.validate_certs = False + self.ca_certs = None + self.host = "alpineqa2.alpinenow.local" + self.port = "8443" + self.regex_alpine_version_string = "6.4.*" self.username = "demoadmin" self.password = "4*DemoAdmin" diff --git a/tests/api/test_alpine.py b/tests/api/test_alpine.py index dc79f7d..22dbff6 100644 --- a/tests/api/test_alpine.py +++ b/tests/api/test_alpine.py @@ -11,7 +11,10 @@ def setUp(self): # Creating Alpine Client in setUp Function for tests global alpine_client global login_info - alpine_client = APIClient(self.host, self.port) + alpine_client = APIClient(self.host, self.port, + is_secure=self.is_secure, + validate_certs=self.validate_certs, + ca_certs=self.ca_certs) login_info = alpine_client.login(self.username, self.password) def tearDown(self): diff --git a/tests/api/test_dataSource.py b/tests/api/test_dataSource.py index cdcefb7..cdb7c3c 100644 --- a/tests/api/test_dataSource.py +++ b/tests/api/test_dataSource.py @@ -12,7 +12,10 @@ def setUp(self): # Creating Alpine Client in setUp Function for tests global alpine_client global login_info - alpine_client = APIClient(self.host, self.port) + alpine_client = APIClient(self.host, self.port, + is_secure=self.is_secure, + validate_certs=self.validate_certs, + ca_certs=self.ca_certs) login_info = alpine_client.login(self.username, self.password) global db_datasource_id diff --git a/tests/api/test_job.py b/tests/api/test_job.py index 8ac9993..64e55bc 100644 --- a/tests/api/test_job.py +++ b/tests/api/test_job.py @@ -16,7 +16,10 @@ def setUp(self): # Creating Alpine Client in setUp Function for tests global alpine_client global login_info - alpine_client = APIClient(self.host, self.port) + alpine_client = APIClient(self.host, self.port, + is_secure=self.is_secure, + validate_certs=self.validate_certs, + ca_certs=self.ca_certs) login_info = alpine_client.login(self.username, self.password) global workspace_id diff --git a/tests/api/test_user.py b/tests/api/test_user.py index 2115090..be06c4e 100644 --- a/tests/api/test_user.py +++ b/tests/api/test_user.py @@ -13,7 +13,10 @@ def setUp(self): # Creating Alpine Client in setUp Function for tests global alpine_client global login_info - alpine_client = APIClient(self.host, self.port) + alpine_client = APIClient(self.host, self.port, + is_secure=self.is_secure, + validate_certs=self.validate_certs, + ca_certs=self.ca_certs) login_info = alpine_client.login(self.username, self.password) def test_create_user(self): diff --git a/tests/api/test_workfile.py b/tests/api/test_workfile.py index bc1ea5f..e6bf64c 100644 --- a/tests/api/test_workfile.py +++ b/tests/api/test_workfile.py @@ -17,7 +17,10 @@ def setUp(self): # Creating Alpine Client in setUp Function for tests global alpine_client global login_info - alpine_client = APIClient(self.host, self.port) + alpine_client = APIClient(self.host, self.port, + is_secure=self.is_secure, + validate_certs=self.validate_certs, + ca_certs=self.ca_certs) login_info = alpine_client.login(self.username, self.password) global workspace_name @@ -126,6 +129,13 @@ def test_run_workflow_variable_quote(self): workfile_id = alpine_client.workfile.get_id(workfile_name, workspace_id) process_id = alpine_client.workfile.process.run(workfile_id, variables) alpine_client.workfile.process.wait_until_finished(workfile_id, process_id) + + def test_run_workflow_variable_single_quote_in_variable(self): + variables = [{"name": "@min_credit_line", "value": "7"}, {"name": "@outlook", "value": "'su\'nny'"}] + workfile_id = alpine_client.workfile.get_id(workfile_name, workspace_id) + process_id = alpine_client.workfile.process.run(workfile_id, variables) + alpine_client.workfile.process.wait_until_finished(workfile_id, process_id) + def test_query_workflow_status(self): valid_workfile_status = ["WORKING", "FINISHED"] @@ -151,7 +161,21 @@ def test_download_workflow_results(self): while workfile_status != "FINISHED": time.sleep(1) workfile_status = alpine_client.workfile.process.query_status(process_id) - response = alpine_client.workfile.process.download_results(workfile_id, process_id) + results = alpine_client.workfile.process.download_results(workfile_id, process_id) + results_metadata = alpine_client.workfile.process.get_metadata(results) + start_time = results_metadata['startTime'] #u'2018-03-14T06:15:42.828-0700' + end_time = results_metadata['endTime'] #u'2018-03-14T06:15:51.480-0700' + status = results_metadata['status'] #Could be either u'FAILURE' or u'SUCCESS' + print(status) + numberOfError = results_metadata['noOfError'] + if results_metadata['noOfError'] != 0: + for log_step in results["logs"]: + errorMessage = log_step["errMessage"] + if errorMessage != 'null': + nodeName = log_step["nodeName"] + uuid = log_step["uuid"] + print("Error Message of Node {0} is: {1}".format(uuid, errorMessage)) + print (status) def test_stop_workflow(self): variables = [{"name": "@min_credit_line", "value": "7"}] diff --git a/tests/api/test_workspace.py b/tests/api/test_workspace.py index f33d8d7..b2f67ad 100644 --- a/tests/api/test_workspace.py +++ b/tests/api/test_workspace.py @@ -12,7 +12,10 @@ def setUp(self): # Creating Alpine Client in setUp Function for tests global alpine_client global login_info - alpine_client = APIClient(self.host, self.port) + alpine_client = APIClient(self.host, self.port, + is_secure=self.is_secure, + validate_certs=self.validate_certs, + ca_certs=self.ca_certs) login_info = alpine_client.login(self.username, self.password) def test_create_new_workspace(self):