Skip to content

Commit fed98de

Browse files
python: Switch to HTTP API (#809)
Newer, simpler API --------- Co-authored-by: Max <[email protected]>
1 parent ec3ebb9 commit fed98de

36 files changed

+1633
-735
lines changed

.github/workflows/ci-python.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
run: |
5454
echo "CLIENT_ID=${{ secrets.STAGING_CLIENT_ID }}" >> $GITHUB_ENV
5555
echo "CLIENT_SECRET=${{ secrets.STAGING_CLIENT_SECRET }}" >> $GITHUB_ENV
56-
echo "VAAS_URL=wss://gateway.staging.vaas.gdatasecurity.de" >> $GITHUB_ENV
56+
echo "VAAS_URL=https://gateway.staging.vaas.gdatasecurity.de" >> $GITHUB_ENV
5757
echo "TOKEN_URL=https://account-staging.gdata.de/realms/vaas-staging/protocol/openid-connect/token" >> $GITHUB_ENV
5858
echo "VAAS_CLIENT_ID=${{ secrets.STAGING_VAAS_CLIENT_ID }}" >> $GITHUB_ENV
5959
echo "VAAS_USER_NAME=${{ secrets.STAGING_VAAS_USER_NAME }}" >> $GITHUB_ENV
@@ -64,7 +64,7 @@ jobs:
6464
run: |
6565
echo "CLIENT_ID=${{ secrets.DEVELOP_CLIENT_ID }}" >> $GITHUB_ENV
6666
echo "CLIENT_SECRET=${{ secrets.DEVELOP_CLIENT_SECRET }}" >> $GITHUB_ENV
67-
echo "VAAS_URL=wss://gateway.develop.vaas.gdatasecurity.de" >> $GITHUB_ENV
67+
echo "VAAS_URL=https://gateway.develop.vaas.gdatasecurity.de" >> $GITHUB_ENV
6868
echo "TOKEN_URL=https://account-staging.gdata.de/realms/vaas-develop/protocol/openid-connect/token" >> $GITHUB_ENV
6969
echo "VAAS_CLIENT_ID=${{ secrets.DEVELOP_VAAS_CLIENT_ID }}" >> $GITHUB_ENV
7070
echo "VAAS_USER_NAME=${{ secrets.DEVELOP_VAAS_USER_NAME }}" >> $GITHUB_ENV
@@ -73,15 +73,15 @@ jobs:
7373
- name: set up Python
7474
uses: actions/setup-python@v5
7575
with:
76-
python-version: 3.x
76+
python-version: 3.12
7777
- name: install dependencies
7878
run: |
7979
python -m pip install --upgrade pip
8080
pip install -r requirements.txt
8181
working-directory: python
8282

8383
- name: run tests
84-
run: python -m unittest -v tests/test_*
84+
run: pytest -v --tb=short
8585
working-directory: python
8686

8787
- name: install example requirements

python/.vscode/settings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
"-p",
77
"test_*.py"
88
],
9-
"python.testing.pytestEnabled": false,
10-
"python.testing.unittestEnabled": true
9+
"python.testing.pytestEnabled": true,
10+
"python.testing.unittestEnabled": false
1111
}

python/examples/VaasExample/authentication_example.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@
66

77
async def main():
88
token_url = os.getenv("TOKEN_URL")
9-
vaas_url = os.getenv("VAAS_URL")
109

1110
if token_url is None:
1211
token_url = "https://account.gdata.de/realms/vaas-production/protocol/openid-connect/token"
13-
if vaas_url is None:
14-
vaas_url = "wss://gateway.production.vaas.gdatasecurity.de"
1512

1613
# If you got a username and password from us, you can use the ResourceOwnerPasswordAuthenticator like this
1714
if USE_RESOURCE_OWNER_PASSWORD_GRANT_AUTHENTICATOR:
@@ -32,11 +29,8 @@ async def main():
3229
token_endpoint=token_url
3330
)
3431

35-
async with Vaas(url=vaas_url) as vaas:
36-
await vaas.connect(await authenticator.get_token())
37-
url = "https://secure.eicar.org/eicar.com"
38-
verdict = await vaas.for_url(url)
39-
print(f"Url {url} is detected as {verdict['Verdict']}")
32+
# Use the authenticator in VaaS
33+
# Vaas(authenticator=authenticator)
4034

4135

4236
if __name__ == "__main__":

python/examples/VaasExample/main.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,30 @@
11
from argparse import _AttributeHolder
22
import asyncio
33
import os
4+
import dotenv
45
from vaas import Vaas, ClientCredentialsGrantAuthenticator
56

67

78
async def main():
9+
dotenv.load_dotenv()
810
token_url = os.getenv("TOKEN_URL")
911
vaas_url = os.getenv("VAAS_URL")
1012

1113
if token_url is None:
1214
token_url = "https://account.gdata.de/realms/vaas-production/protocol/openid-connect/token"
1315
if vaas_url is None:
14-
vaas_url = "wss://gateway.production.vaas.gdatasecurity.de"
16+
vaas_url = "https://gateway.production.vaas.gdatasecurity.de"
1517

1618
authenticator = ClientCredentialsGrantAuthenticator(
1719
os.getenv("CLIENT_ID"),
1820
os.getenv("CLIENT_SECRET"),
1921
token_endpoint=token_url
2022
)
21-
async with Vaas(url=vaas_url) as vaas:
22-
token = await authenticator.get_token()
23-
await vaas.connect(token)
24-
path = os.getenv("SCAN_PATH")
25-
verdict = await vaas.for_file(path)
26-
print(f"{verdict['Sha256']} is detected as {verdict['Verdict']}")
2723

28-
# The scan functions will return the following dict:
29-
# {
30-
# "Sha256": "<Sha256>",
31-
# "Guid": "<Guid>",
32-
# "Verdict": <"Clean"|"Malicious"|"Unknown"|"Pup">,
33-
# "Detection": "<Name of the detected malware if found>",
34-
# "FileType": "<FileType>",
35-
# "MimeType": "<MimeType>"
36-
# }
24+
vaas = Vaas(url=vaas_url, authenticator=authenticator)
25+
path = os.getenv("SCAN_PATH")
26+
verdict = await vaas.for_file(path)
27+
print(f"{verdict.sha256} is detected as {verdict.verdict}")
3728

3829

3930
if __name__ == "__main__":

python/examples/VaasExample/main_url.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,29 @@
11
import asyncio
22
import os
33
from vaas import Vaas, ClientCredentialsGrantAuthenticator
4+
import dotenv
45

56

67
async def main():
8+
dotenv.load_dotenv()
79
token_url = os.getenv("TOKEN_URL")
810
vaas_url = os.getenv("VAAS_URL")
911

1012
if token_url is None:
1113
token_url = "https://account.gdata.de/realms/vaas-production/protocol/openid-connect/token"
1214
if vaas_url is None:
13-
vaas_url = "wss://gateway.production.vaas.gdatasecurity.de"
15+
vaas_url = "https://gateway.production.vaas.gdatasecurity.de"
1416

1517
authenticator = ClientCredentialsGrantAuthenticator(
1618
os.getenv("CLIENT_ID"),
1719
os.getenv("CLIENT_SECRET"),
1820
token_endpoint=token_url
1921
)
20-
async with Vaas(url=vaas_url) as vaas:
21-
await vaas.connect(await authenticator.get_token())
22-
url = "https://secure.eicar.org/eicar.com"
23-
verdict = await vaas.for_url(url)
24-
print(f"Url {url} is detected as {verdict['Verdict']}")
2522

26-
# The scan functions will return the following dict:
27-
# {
28-
# "Sha256": "<Sha256>",
29-
# "Guid": "<Guid>",
30-
# "Verdict": <"Clean"|"Malicious"|"Unknown"|"Pup">,
31-
# "Detection": "<Name of the detected malware if found>",
32-
# "FileType": "<FileType>",
33-
# "MimeType": "<MimeType>"
34-
# }
23+
vaas = Vaas(url=vaas_url, authenticator=authenticator)
24+
url = "https://secure.eicar.org/eicar.com"
25+
verdict = await vaas.for_url(url)
26+
print(f"Url {url} is detected as {verdict.verdict}")
3527

3628

3729
if __name__ == "__main__":
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
gdata-vaas==5.2.0
1+
../../

python/pytest.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[pytest]
2+
asyncio_mode=auto
3+
asyncio_default_fixture_loop_scope = function

python/requirements.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
authlib~=1.3
2-
websockets~=15.0
32
python-dotenv~=1.0
43
httpx[http2]~=0.27
54
build~=1.1
6-
pyjwt~=2.8
75
aiofiles~=24.1
6+
pydantic~=2.11.5
7+
pytest-asyncio~=0.26.0
8+
pytest~=8.3.5
9+
pytest-httpx~=0.35
10+
.

python/setup.cfg

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@ classifiers =
1515
Operating System :: OS Independent
1616

1717
[options]
18-
python_requires = >=3.8
18+
python_requires = >=3.12
1919
install_requires =
20-
websockets>=10.4
21-
httpx[http2]>=0.24.1
22-
pyjwt>=2.0.0
23-
authlib>=1.2.1
24-
aiofiles>=23.1.0
20+
authlib~=1.3
21+
python-dotenv~=1.0
22+
httpx[http2]~=0.27
23+
build~=1.1
24+
aiofiles~=24.1
25+
pydantic~=2.11.5
26+
pytest-asyncio~=0.26.0
27+
pytest~=8.3.5
28+
pytest-httpx~=0.35.0
2529

2630
[options.packages.find]
2731
where = src

python/src/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)