Skip to content

Commit 6bf349a

Browse files
authored
Enabling the ability to disable SSL certificate requirements for mgmt API endpoints (#103)
* using 1.3.1 of the python API client; this now works properly to skip SSL cert requirements * added a functioning test, removed print statements * fixed path issue and adjusted version range for api client to the specific working version * fixed requirements.txt and small bug in client logic
1 parent 61ddedb commit 6bf349a

File tree

6 files changed

+21
-5
lines changed

6 files changed

+21
-5
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#Eclipse
22
.project
33

4+
TestFiles
5+
test.txt
6+
47
# Byte-compiled / optimized / DLL files
58
__pycache__/
69
*.py[cod]

Algorithmia/client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class Client(object):
2626

2727
def __init__(self, apiKey = None, apiAddress = None, caCert = None):
2828
# Override apiKey with environment variable
29+
config = None
2930
self.requestSession = requests.Session()
3031
if apiKey is None and 'ALGORITHMIA_API_KEY' in os.environ:
3132
apiKey = os.environ['ALGORITHMIA_API_KEY']
@@ -36,6 +37,7 @@ def __init__(self, apiKey = None, apiAddress = None, caCert = None):
3637
self.apiAddress = Algorithmia.getApiAddress()
3738
if caCert == False:
3839
self.requestSession.verify = False
40+
config = Configuration(use_ssl=False)
3941
elif caCert is None and 'REQUESTS_CA_BUNDLE' in os.environ:
4042
caCert = os.environ.get('REQUESTS_CA_BUNDLE')
4143
self.catCerts(caCert)
@@ -48,8 +50,8 @@ def __init__(self, apiKey = None, apiAddress = None, caCert = None):
4850
self.catCerts(caCert)
4951
self.requestSession.verify = self.ca_cert
5052

51-
52-
config = Configuration()
53+
if not config:
54+
config = Configuration()
5355
config.api_key['Authorization'] = self.apiKey
5456
config.host = "{}/v1".format(self.apiAddress)
5557
self.manageApi = DefaultApi(ApiClient(config))

Test/client_test.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def test_create_org(self):
3535
response = self.c.create_org({"org_name": self.orgname, "org_label": "some label", "org_contact_name": "Some owner", "org_email": self.orgname+"@algo.com","type_id":"basic"})
3636
self.assertEqual(self.orgname,response['org_name'])
3737

38+
3839
def test_get_org(self):
3940
response = self.c.get_org("a_myOrg84")
4041
self.assertEqual("a_myOrg84",response['org_name'])
@@ -56,6 +57,15 @@ def test_get_build_logs(self):
5657
print(result)
5758
self.assertTrue("error" not in result)
5859

60+
def test_get_build_logs_no_ssl(self):
61+
client = Algorithmia.client(api_key=os.environ.get('ALGORITHMIA_API_KEY'), ca_cert=False)
62+
user = os.environ.get('ALGO_USER_NAME')
63+
algo = "Echo"
64+
result = client.algo(user + '/' + algo).build_logs()
65+
if "error" in result:
66+
print(result)
67+
self.assertTrue("error" not in result)
68+
5969

6070
def test_edit_org(self):
6171
orgname="a_myOrg84"
@@ -95,6 +105,7 @@ def test_get_supported_languages(self):
95105
self.assertTrue(response is not None and language_found)
96106

97107

108+
98109
def test_invite_to_org(self):
99110
response = self.c.invite_to_org("a_myOrg38","a_Mrtest4")
100111
self.assertEqual(200,response.status_code)

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ six
33
enum-compat
44
toml
55
argparse
6-
algorithmia-api-client>=1.3,<1.4
6+
algorithmia-api-client==1.5.1
77
algorithmia-adk>=1.0.2,<1.1
88
numpy<2
99
uvicorn==0.14.0

requirements27.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ six
33
enum-compat
44
toml
55
argparse
6-
algorithmia-api-client>=1.3,<1.4
6+
algorithmia-api-client==1.5.1
77
algorithmia-adk>=1.0.2,<1.1
88
numpy<2

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
'enum-compat',
2222
'toml',
2323
'argparse',
24-
'algorithmia-api-client>=1.3,<1.4',
24+
'algorithmia-api-client==1.5.1',
2525
'algorithmia-adk>=1.0.2,<1.1'
2626
],
2727
include_package_data=True,

0 commit comments

Comments
 (0)