forked from openml-labs/server-demo
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
138 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
examples/authentication/example_authenticate_with_service_account.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/bin/bash | ||
# This minimal example is for back-end services that want to authenticate as a server. | ||
# Use this example if you want to upload data in the name of the service, not in the name | ||
# of a user. | ||
# Another option for back-end services would be to let users login / to impersonate users. | ||
|
||
|
||
|
||
# Ask admin of https://aiod-dev.i3a.es/aiod-auth keycloak, e.g. Rafael, for a secret | ||
CLIENT_ID="PUT CLIENT ID HERE" | ||
SECRET="PUT THE SECRET HERE" | ||
|
||
|
||
if [ "${CLIENT_ID}" = "PUT CLIENT ID HERE" ]; then | ||
echo "Error: put the correct client id in the script" | ||
exit 1 | ||
fi | ||
if [ "${SECRET}" = "PUT THE SECRET HERE" ]; then | ||
echo "Error: put the correct secret in the script" | ||
exit 1 | ||
fi | ||
|
||
|
||
TOKEN_DICT=$(curl \ | ||
-d "client_id=${CLIENT_ID}" \ | ||
-d "client_secret=${SECRET}" \ | ||
-d "grant_type=client_credentials" \ | ||
-d "scope=openid profile roles" \ | ||
"https://aiod-dev.i3a.es/aiod-auth/realms/aiod/protocol/openid-connect/token" \ | ||
| python3 -m json.tool | ||
) | ||
|
||
TOKEN=$( | ||
echo $TOKEN_DICT \ | ||
| jq .access_token \ | ||
| tr -d '"' | ||
) | ||
|
||
echo "TOKEN: " | ||
echo $TOKEN | ||
echo "(should not be null)" | ||
|
||
RESULT=$( | ||
curl -X 'GET' \ | ||
-H "Accept: application/json" \ | ||
-H "Authorization: Bearer ${TOKEN}" \ | ||
-H "Content-Type: application/json" \ | ||
https://aiod-dev.i3a.es/authorization_test | ||
) | ||
|
||
|
||
echo "Result of auth test:" | ||
echo $RESULT |
77 changes: 77 additions & 0 deletions
77
examples/upload/example_upload_dataset_with_service_account.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#!/bin/bash | ||
# This minimal example uses service authentication. | ||
|
||
|
||
|
||
# Ask admin of https://aiod-dev.i3a.es/aiod-auth keycloak, e.g. Rafael, for a secret | ||
CLIENT_ID="PUT CLIENT ID HERE" | ||
SECRET="PUT THE SECRET HERE" | ||
|
||
|
||
if [ "${CLIENT_ID}" = "PUT CLIENT ID HERE" ]; then | ||
echo "Error: put the correct client id in the script" | ||
exit 1 | ||
fi | ||
if [ "${SECRET}" = "PUT THE SECRET HERE" ]; then | ||
echo "Error: put the correct secret in the script" | ||
exit 1 | ||
fi | ||
|
||
|
||
TOKEN_DICT=$(curl \ | ||
-d "client_id=${CLIENT_ID}" \ | ||
-d "client_secret=${SECRET}" \ | ||
-d "grant_type=client_credentials" \ | ||
-d "scope=openid profile roles" \ | ||
"https://aiod-dev.i3a.es/aiod-auth/realms/aiod/protocol/openid-connect/token" \ | ||
| python3 -m json.tool | ||
) | ||
|
||
TOKEN=$( | ||
echo $TOKEN_DICT \ | ||
| jq .access_token \ | ||
| tr -d '"' | ||
) | ||
|
||
|
||
echo "POSTING a new dataset..." | ||
|
||
# Only a name is added for this dataset. See https://aiod-dev.i3a.es/docs#/ for all possible fields. | ||
RESULT=$( | ||
curl -X 'POST' \ | ||
-H "Accept: application/json" \ | ||
-H "Authorization: Bearer ${TOKEN}" \ | ||
-H "Content-Type: application/json" \ | ||
-d '{"name": "test"}' \ | ||
https://aiod-dev.i3a.es/datasets/v1 | ||
) | ||
|
||
|
||
|
||
IDENTIFIER=$( | ||
echo $RESULT \ | ||
| jq .identifier \ | ||
| tr -d '"' | ||
) | ||
echo "Identifier of the new dataset (should not be null):" | ||
echo $IDENTIFIER | ||
|
||
|
||
echo "Trying to retrieve the just posted dataset of the platform..." | ||
NEW_DATASET=$( | ||
curl -X 'GET' \ | ||
-H "Accept: application/json" \ | ||
https://aiod-dev.i3a.es/datasets/v1/${IDENTIFIER} | ||
) | ||
echo "New dataset as found on the platform:" | ||
echo $NEW_DATASET | jq . | ||
|
||
|
||
echo "Deleting the dataset again, because it was just a test..." | ||
DELETED=$( | ||
curl -X 'DELETE' \ | ||
-H "Authorization: Bearer ${TOKEN}" \ | ||
-H "Accept: application/json" \ | ||
https://aiod-dev.i3a.es/datasets/v1/${IDENTIFIER} | ||
) | ||
echo "Done." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
[project] | ||
name = "ai4eu_server_demo" | ||
description = "A containerized demo application for AI on demand (previously AI4EU) " | ||
version = "0.4.20230627" | ||
version = "1.0.20230911" | ||
requires-python = ">=3.11" | ||
authors = [ | ||
|
||
|
@@ -13,10 +13,10 @@ authors = [ | |
{name = "Taniya Das", email = "[email protected]"} | ||
] | ||
dependencies = [ | ||
"urllib3== 2.0.4", | ||
"bibtexparser==1.4.0", | ||
"datasets==2.14.4", | ||
"fastapi==0.103.1", | ||
"urllib3== 2.0.7", | ||
"bibtexparser==1.4.1", | ||
"datasets==2.14.5", | ||
"fastapi==0.104.0", | ||
"uvicorn==0.23.2", | ||
"requests==2.31.0", | ||
"mysqlclient==2.2.0", | ||
|
@@ -26,7 +26,7 @@ dependencies = [ | |
"pydantic_schemaorg==1.0.6", | ||
"python-dateutil==2.8.2", | ||
"sqlmodel==0.0.8", | ||
"httpx==0.24.1", | ||
"httpx==0.25.0", | ||
"sickle==0.7.0", | ||
"xmltodict==0.13.0", | ||
"python-multipart==0.0.6", | ||
|
@@ -40,7 +40,7 @@ dev = [ | |
"pytest==7.4.2", | ||
"pytest-dotenv==0.5.2", | ||
"pytest-xdist==3.3.1", | ||
"pre-commit==3.4.0", | ||
"pre-commit==3.5.0", | ||
"responses==0.23.3", | ||
"starlette==0.27.0" | ||
] | ||
|