Skip to content

Commit 500754e

Browse files
committed
feat: support for async polling
1 parent 96a2b15 commit 500754e

41 files changed

Lines changed: 825 additions & 225 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

DEV.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ rm -fR sdk/
1111
To generate the SDK use the following command. Don't forget to update the `packageVersion`.
1212

1313
```
14-
openapi-generator generate -i api.yml -g python -o ./sdk --additional-properties=packageName=attachmentav,packageVersion=0.3.0,projectName=attachmentav-virus-scan-sdk
14+
openapi-generator generate -i api.yml -g python -o ./sdk --additional-properties=packageName=attachmentav,packageVersion=0.4.0,projectName=attachmentav-virus-scan-sdk
1515
```
1616

1717
The `pyproject.toml` needs to be modified manually, as the generator does not provide the necessary properties.

README.md

Lines changed: 94 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@ Third, send a scan request. Make sure to replace the `<API_KEY_PLACEHOLDER>` pla
1818
import attachmentav
1919

2020
configuration = attachmentav.Configuration()
21+
# When using the SaaS offering
2122
configuration.api_key['apiKeyAuth'] = "<API_KEY_PLACEHOLDER>"
23+
# When using the self-hosted offering, replace attachmentav.yourcompany.com with the domain name of your attachmentAV API installation: https://attachmentav.com/help/virus-malware-scan-api-aws/developer/definition.html#domain-name
24+
#configuration.access_token = "<API_KEY_PLACEHOLDER>"
25+
#configuration.host = "https://attachmentav.yourcompany.com/api/v1"
2226

2327
with attachmentav.ApiClient(configuration) as api_client:
2428
api_instance = attachmentav.AttachmentAVApi(api_client)
2529

26-
with open("path/to/file", "rb") as file:
30+
with open("/path/to/file", "rb") as file:
2731
file_content = file.read()
2832
scan_result = api_instance.scan_sync_binary_post(file_content)
2933
print(scan_result)
@@ -96,10 +100,10 @@ The maximum file size is 10 MB. The request timeout is 60 seconds.
96100

97101

98102
```python
99-
with open("path/to/file", "rb") as file:
100-
file_content = file.read()
101-
scan_result = api_instance.scan_sync_binary_post(file_content)
102-
print(scan_result)
103+
with open("/path/to/file", "rb") as file:
104+
file_content = file.read()
105+
scan_result = api_instance.scan_sync_binary_post(file_content)
106+
print(scan_result)
103107
```
104108

105109
### Sync Scan: Download
@@ -114,7 +118,7 @@ The maximum file size is 10 MB. The request timeout is 60 seconds.
114118

115119
```python
116120
sync_download_scan_request = attachmentav.SyncDownloadScanRequest(
117-
download_url = "https://example.com/demo.txt"
121+
download_url = "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
118122
)
119123
scan_result = api_instance.scan_sync_download_post(sync_download_scan_request)
120124
print(scan_result)
@@ -132,14 +136,14 @@ The maximum file size is 10 MB. The request timeout is 60 seconds.
132136
133137
```python
134138
sync_s3_scan_request = attachmentav.SyncS3ScanRequest(
135-
bucket = "example-bucket",
136-
key = "demo.txt"
139+
bucket = "<BUCKET_NAME_PLACEHOLDER>",
140+
key = "<OBJECT_KEY_PLACEHOLDER>"
137141
)
138142
scan_result = api_instance.scan_sync_s3_post(sync_s3_scan_request)
139143
print(scan_result)
140144
```
141145

142-
### Async Scan: Download
146+
### Async Scan: Download (callback)
143147

144148
Send a URL to the attachmentAV Virus Scan API. attachmentAV will send the scan result to the callback URL. See [callback URL](https://attachmentav.com/help/virus-malware-scan-api/setup-guide/#callback-url) for details.
145149

@@ -151,15 +155,46 @@ The maximum file size is 5 GB. The request timeout is 29 seconds; the asynchrono
151155
152156
```python
153157
async_download_scan_request = attachmentav.AsyncDownloadScanRequest(
154-
download_url = "https://example.com/demo.txt",
155-
callback_url = "https://example.com/callback"
158+
download_url = "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",
159+
callback_url = "https://api.yourcompany.com/attachmentav/callback"
156160
)
157161
api_instance.scan_async_download_post(async_download_scan_request)
162+
print("Async download submitted")
158163
```
159164

160-
### Async Scan: S3
165+
Find full example [here](https://github.com/widdix/attachmentav-sdk-python/blob/main/examples/async-download.py)
166+
167+
### Async Scan: Download (polling)
168+
169+
Send a URL to the attachmentAV Virus Scan API. attachmentAV will download the file and store the scan result for 24 hours.
170+
171+
See [AsyncDownloadScanRequest](sdk/docs/AsyncDownloadScanRequest.md) for details.
172+
173+
The maximum file size is 5 GB. The request timeout is 29 seconds; the asynchronous scan job is not affected by this limit.
161174

162-
Send an S3 bucket name and object key to the attachmentAV Virus Scan API. attachmentAV will send the scan result to the callback URL. See [callback URL](https://attachmentav.com/help/virus-malware-scan-api/setup-guide/#callback-url) for details.
175+
> Not supported by attachmentAV Virus Scan API (Self-hosted on AWS) yet. Contact [[email protected]]([email protected]) to let us know, in case you need this feature.
176+
177+
```python
178+
trace_id = str(uuid.uuid4())
179+
180+
async_download_scan_request = attachmentav.AsyncDownloadScanRequest(
181+
download_url = "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",
182+
trace_id = trace_id
183+
)
184+
api_instance.scan_async_download_post(async_download_scan_request)
185+
print("Async download submitted.")
186+
187+
# wait some time...
188+
189+
scan_result = api_instance.scan_async_result_get(trace_id)
190+
print(scan_result)
191+
```
192+
193+
Find full example [here](https://github.com/widdix/attachmentav-sdk-python/blob/main/examples/async-download-polling.py)
194+
195+
### Async Scan: S3 (callback)
196+
197+
Send an S3 bucket name and object key to the attachmentAV Virus Scan API. attachmentAV will send the scan result to the callback URL. See [callback URL](https://attachmentav.com/help/virus-malware-scan-api/setup-guide/#callback-url) for details.
163198

164199
See [AsyncS3ScanRequest](sdk/docs/AsyncS3ScanRequest.md) for details.
165200

@@ -171,31 +206,52 @@ The maximum file size is 5 GB. The request timeout is 29 seconds; the asynchrono
171206
172207
```python
173208
async_s3_scan_request = attachmentav.AsyncS3ScanRequest(
174-
bucket = "example-bucket",
175-
key = "demo.txt",
176-
callback_url = "https://example.com/callback"
209+
bucket = "<BUCKET_NAME_PLACEHOLDER>",
210+
key = "<OBJECT_KEY_PLACEHOLDER>",
211+
callback_url = "https://api.yourcompany.com/attachmentav/callback"
177212
)
178213
api_instance.scan_async_s3_post(async_s3_scan_request)
214+
print("Async S3 submitted")
179215
```
180216

181-
### Who AM I
217+
Find full example [here](https://github.com/widdix/attachmentav-sdk-python/blob/main/examples/async-s3.py)
182218

183-
Get information abour yourself.
219+
### Async Scan: S3 (polling)
184220

185-
See [Whoami](sdk/models/Whoami.ts) for details.
221+
Send an S3 bucket name and object key to the attachmentAV Virus Scan API. attachmentAV will download the file and store the scan result for 24 hours.
186222

187-
> Not supported by attachmentAV Virus Scan API (Self-hosted on AWS).
223+
See [AsyncS3ScanRequest](sdk/docs/AsyncS3ScanRequest.md) for details.
224+
225+
The maximum file size is 5 GB. The request timeout is 29 seconds; the asynchronous scan job is not affected by this limit.
226+
227+
> A [bucket policy](https://attachmentav.com/help/virus-malware-scan-api/setup-guide/#s3-bucket-policy) is required to grant attachmentAV access to private S3 objects.
228+
229+
> Not supported by attachmentAV Virus Scan API (Self-hosted on AWS) yet. Contact [[email protected]]([email protected]) to let us know, in case you need this feature.
188230
189231
```python
190-
whoami_result = api_instance.whoami_get()
191-
print(whoami_result)
232+
trace_id = str(uuid.uuid4())
233+
234+
async_s3_scan_request = attachmentav.AsyncS3ScanRequest(
235+
bucket = "<BUCKET_NAME_PLACEHOLDER>",
236+
key = "<OBJECT_KEY_PLACEHOLDER>",
237+
trace_id = trace_id
238+
)
239+
api_instance.scan_async_s3_post(async_s3_scan_request)
240+
print("Async S3 submitted. ")
241+
242+
# wait some time...
243+
244+
scan_result = api_instance.scan_async_result_get(trace_id)
245+
print(scan_result)
192246
```
193247

248+
Find full example [here](https://github.com/widdix/attachmentav-sdk-python/blob/main/examples/async-s3-polling.py)
249+
194250
### Usage
195251

196252
Get remaining credits and quota.
197253

198-
See [Usage](sdk/models/Usage.ts) for details.
254+
See [Usage](sdk/docs/Usage.md) for details.
199255

200256
> Not supported by attachmentAV Virus Scan API (Self-hosted on AWS).
201257
@@ -204,6 +260,19 @@ usage_result = api_instance.usage_get()
204260
print(usage_result)
205261
```
206262

263+
### Who am I
264+
265+
Get information abour yourself.
266+
267+
See [Whoami](sdk/docs/Whoami.md) for details.
268+
269+
> Not supported by attachmentAV Virus Scan API (Self-hosted on AWS).
270+
271+
```python
272+
whoami_result = api_instance.whoami_get()
273+
print(whoami_result)
274+
```
275+
207276
## Model
208277

209278
For more details about the data model, please refer to the following pages.
@@ -214,6 +283,8 @@ For more details about the data model, please refer to the following pages.
214283
* [ScanResult](sdk/docs/ScanResult.md)
215284
* [SyncDownloadScanRequest](sdk/docs/SyncDownloadScanRequest.md)
216285
* [SyncS3ScanRequest](sdk/docs/SyncS3ScanRequest.md)
286+
* [Usage](sdk/docs/Usage.md)
287+
* [Whoami](sdk/docs/Whoami.md)
217288

218289
## Need help?
219290

0 commit comments

Comments
 (0)