Skip to content

get available SCMs support #128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions Algorithmia/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,15 @@ def set_options(self, timeout=300, stdout=False, output=OutputType.default, **qu
return self

# Create a new algorithm
def create(self, details={}, settings={}, version_info={}, source={}, scmsCredentials={}):
def create(self, details, settings, version_info=None, source=None, scmsCredentials=None):
url = "/v1/algorithms/" + self.username
create_parameters = {"name": self.algoname, "details": details, "settings": settings,
"version_info": version_info, "source": source, "scmsCredentials": scmsCredentials}
create_parameters = {"name": self.algoname, "details": details, "settings": settings}
if version_info:
create_parameters['version_info'] = version_info
if source:
create_parameters['source'] = source
if scmsCredentials:
create_parameters['scmsCredentials'] = scmsCredentials

api_response = self.client.postJsonHelper(url, create_parameters, parse_response_as_json=True)
return api_response
Expand Down
5 changes: 5 additions & 0 deletions Algorithmia/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ def username(self):
username = next(self.dir("").list()).path
return username

def scms(self):
url = "/v1/scms"
response = self.getJsonHelper(url)
return response

def file(self, dataUrl, cleanup=False):
if dataUrl.startswith('file://'):
return LocalDataFile(self, dataUrl)
Expand Down
31 changes: 30 additions & 1 deletion Test/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ async def process_get_algo(request: Request, username, algoname):
"resource_type": "algorithm"}
elif algoname == "echo":
return JSONResponse(content={"error": {"id": "1cfb98c5-532e-4cbf-9192-fdd45b86969c", "code": 2001,
"message": "Caller is not authorized to perform the operation"}}, status_code=403)
"message": "Caller is not authorized to perform the operation"}},
status_code=403)
else:
return JSONResponse(content={"error": "No such algorithm"}, status_code=404)

Expand All @@ -102,6 +103,34 @@ async def get_scm_status(username, algoname):
return {"scm_connection_status": "active"}


@regular_app.get("/v1/scms")
async def get_scms():
return {'results': [{'default': True, 'enabled': True, 'id': 'internal', 'name': '', 'provider': 'internal'},
{'default': False, 'enabled': True, 'id': 'github', 'name': 'https://github.com',
'provider': 'github', 'scm': {'client_id': '0ff25ba21ec67dbed6e2'},
'oauth': {'client_id': '0ff25ba21ec67dbed6e2'},
'urls': {'web': 'https://github.com', 'api': 'https://api.github.com',
'ssh': 'ssh://git@github.com'}},
{'default': False, 'enabled': True, 'id': 'aadebe70-007f-48ff-ba38-49007c6e0377',
'name': 'https://gitlab.com', 'provider': 'gitlab',
'scm': {'client_id': 'ca459576279bd99ed480236a267cc969f8322caad292fa5147cc7fdf7b530a7e'},
'oauth': {'client_id': 'ca459576279bd99ed480236a267cc969f8322caad292fa5147cc7fdf7b530a7e'},
'urls': {'web': 'https://gitlab.com', 'api': 'https://gitlab.com',
'ssh': 'ssh://git@gitlab.com'}},
{'default': False, 'enabled': True, 'id': '24ad1496-5a1d-43e2-9d96-42fce8e5484f',
'name': 'IQIVA Public GitLab', 'provider': 'gitlab',
'scm': {'client_id': '3341c989f9d28043d2597388aa4f43ce60a74830b981c4b7d79becf641959376'},
'oauth': {'client_id': '3341c989f9d28043d2597388aa4f43ce60a74830b981c4b7d79becf641959376'},
'urls': {'web': 'https://gitlab.com', 'api': 'https://gitlab.com',
'ssh': 'ssh://git@gitlab.com'}},
{'default': False, 'enabled': False, 'id': '83cd96ae-b1f4-4bd9-b9ca-6f7f25c37708',
'name': 'GitlabTest', 'provider': 'gitlab',
'scm': {'client_id': '5e257d6e168d579d439b7d38cdfa647e16573ae1dace6d93a30c5c60b4e5dd32'},
'oauth': {'client_id': '5e257d6e168d579d439b7d38cdfa647e16573ae1dace6d93a30c5c60b4e5dd32'},
'urls': {'web': 'https://gitlab.com', 'api': 'https://gitlab.com',
'ssh': 'ssh://git@gitlab.com'}}]}


@regular_app.get("/v1/algorithms/{algo_id}/errors")
async def get_algo_errors(algo_id):
return JSONResponse(content={"error": {"message": "not found"}}, status_code=404)
Expand Down
12 changes: 9 additions & 3 deletions Test/regular/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class ClientDummyTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.client = Algorithmia.client(api_address="http://localhost:8080", api_key="simabcd123")

admin_username = "a_Mrtest"
admin_org_name = "a_myOrg"
environment_name = "Python 3.9"
Expand All @@ -28,7 +29,6 @@ def setUp(self):
self.admin_username = self.admin_username + str(int(random() * 10000))
self.admin_org_name = self.admin_org_name + str(int(random() * 10000))


def test_create_user(self):
response = self.client.create_user(
{"username": self.admin_username, "email": self.admin_username + "@algo.com", "passwordHash": "",
Expand Down Expand Up @@ -60,6 +60,12 @@ def test_get_environment(self):
if u'error' not in response:
self.assertTrue(response is not None and u'environments' in response)

def test_get_scms(self):
response = self.client.scms()
results = response['results']
internal = [result for result in results if result['id'] == 'internal']
self.assertTrue(len(internal) == 1)

def test_edit_org(self):
org_name = "a_myOrg84"

Expand Down Expand Up @@ -120,7 +126,6 @@ def test_get_algorithm_errors(self):
except AlgorithmException as e:
self.assertTrue(e.message == "No such algorithm")


def test_no_auth_client(self):

key = os.environ.get('ALGORITHMIA_API_KEY', "")
Expand All @@ -135,6 +140,7 @@ def test_no_auth_client(self):
error = e
finally:
os.environ['ALGORITHMIA_API_KEY'] = key
self.assertEqual(str(error), str(AlgorithmException(message="authorization required", stack_trace=None, error_type=None)))
self.assertEqual(str(error), str(AlgorithmException(message="authorization required", stack_trace=None,
error_type=None)))
if __name__ == '__main__':
unittest.main()