Skip to content

Commit 13886e1

Browse files
authored
Merge pull request #12 from elfkuzco/http-timeouts
configure resources with timeouts
2 parents fbd3f0f + a33010b commit 13886e1

File tree

3 files changed

+61
-49
lines changed

3 files changed

+61
-49
lines changed

CHANGELOG.md

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@
33
All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6-
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html),
77
as of 0.8.2
88

9+
## [Unreleased]
10+
11+
### Added
12+
13+
- configure resources with user-specified timeouts
14+
915
## [0.9.0]
1016

1117
### Added
@@ -40,7 +46,6 @@ as of 0.8.2
4046

4147
- Fixed `delete_object()` which contained a typo.
4248

43-
4449
## [0.8.1]
4550

4651
- Added `download_matching_file()` and `download_matching_fileobj()` to download a key
@@ -61,54 +66,53 @@ as of 0.8.2
6166

6267
## [0.5]
6368

64-
* fixed `allow_public_downloads_on()` when not specifying bucket
65-
* using less-specified boto3 dependency version to prevent urllib dep version clash with requests
69+
- fixed `allow_public_downloads_on()` when not specifying bucket
70+
- using less-specified boto3 dependency version to prevent urllib dep version clash with requests
6671

6772
## [0.4]
6873

69-
* progress report uses humanfriendly if available
70-
* added `get_wasabi_compliance()` to retrieve an XML bucket or object compliance
74+
- progress report uses humanfriendly if available
75+
- added `get_wasabi_compliance()` to retrieve an XML bucket or object compliance
7176

7277
## [0.3]
7378

74-
* added `has_object_matching()` to check an object with multiple key/value pairs
79+
- added `has_object_matching()` to check an object with multiple key/value pairs
7580

7681
## [0.2]
7782

78-
* more flexible requirements for requests
79-
* removed some debug prints
80-
* don't fail if `AWS_PROFILE` environ is present
81-
* added `s3_test_url` script to test an URL
82-
* added `delete_object()` shortcut
83+
- more flexible requirements for requests
84+
- removed some debug prints
85+
- don't fail if `AWS_PROFILE` environ is present
86+
- added `s3_test_url` script to test an URL
87+
- added `delete_object()` shortcut
8388

8489
## [0.1]
8590

86-
* Initial version featuring:
87-
* URL parsing
88-
* Visual transfer progress hook
89-
* wasabi detection
90-
* configured S3 resource (`.resource`)
91-
* configured S3 client (`.client`)
92-
* requests auth module (`.aws_auth`)
93-
* credentials check (list bucket, read, write)
94-
* configured generic service (`iam` for ex.)
95-
* direct bucket names
96-
* direct bucket access
97-
* test bucket existence
98-
* bucket creation
99-
* test object exitence
100-
* direct object head access
101-
* direct object stats access
102-
* test object with etag exitence
103-
* test object with meta existence
104-
* set policy on bucket (allow external downloads)
105-
* set wasabi auto delete on bucket (retention)
106-
* set wasabi auto delete on object (retention extension)
107-
* delete bucket (with wasabi force)
108-
* wasabi rename bucket
109-
* wasabi object rename (with prefix)
110-
* set wasabi compliance
111-
* direct object download
112-
* object download url
113-
* validate file etag (mono and multipart)
114-
91+
- Initial version featuring:
92+
- URL parsing
93+
- Visual transfer progress hook
94+
- wasabi detection
95+
- configured S3 resource (`.resource`)
96+
- configured S3 client (`.client`)
97+
- requests auth module (`.aws_auth`)
98+
- credentials check (list bucket, read, write)
99+
- configured generic service (`iam` for ex.)
100+
- direct bucket names
101+
- direct bucket access
102+
- test bucket existence
103+
- bucket creation
104+
- test object exitence
105+
- direct object head access
106+
- direct object stats access
107+
- test object with etag exitence
108+
- test object with meta existence
109+
- set policy on bucket (allow external downloads)
110+
- set wasabi auto delete on bucket (retention)
111+
- set wasabi auto delete on object (retention extension)
112+
- delete bucket (with wasabi force)
113+
- wasabi rename bucket
114+
- wasabi object rename (with prefix)
115+
- set wasabi compliance
116+
- direct object download
117+
- object download url
118+
- validate file etag (mono and multipart)

src/kiwixstorage/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.9.0
1+
0.9.1

src/kiwixstorage/__init__.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
# -*- coding: utf-8 -*-
33
# vim: ai ts=4 sts=4 et sw=4 nu
44

5-
""" Kiwix/OpenZIM S3 interface
5+
"""Kiwix/OpenZIM S3 interface
66
7-
helpers for S3 storage, autoconf from URL + Wasabi (wasabisys.com) extras
7+
helpers for S3 storage, autoconf from URL + Wasabi (wasabisys.com) extras
88
9-
Goal is mainly to provide a configured s3.client and s3.resource from an URL
10-
Users could limit usage to this and use boto3 directly from there.
9+
Goal is mainly to provide a configured s3.client and s3.resource from an URL
10+
Users could limit usage to this and use boto3 directly from there.
1111
12-
A few additional wrappers are in place to simplify common actions.
13-
Also, non-S3, wasabi-specific features are exposed directly. """
12+
A few additional wrappers are in place to simplify common actions.
13+
Also, non-S3, wasabi-specific features are exposed directly."""
1414

1515
import os
1616
import io
@@ -26,6 +26,7 @@
2626

2727
import boto3
2828
import botocore
29+
from botocore.config import Config
2930
import requests
3031
from aws_requests_auth.aws_auth import AWSRequestsAuth
3132

@@ -155,7 +156,6 @@ class NotFoundError(Exception):
155156

156157

157158
class KiwixStorage:
158-
159159
BUCKET_NAME = "bucketname"
160160
KEY_ID = "keyid"
161161
SECRET_KEY = "secretaccesskey" # nosec
@@ -187,6 +187,12 @@ def __init__(self, url, **kwargs):
187187
self._resource = self._bucket = None
188188
self._params = {}
189189
self._parse_url(url, **kwargs)
190+
# set configuration params with defaults being the same as if it were missing
191+
# https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html
192+
self._config = Config(
193+
connect_timeout=kwargs.get("connect_timeout", 60),
194+
read_timeout=kwargs.get("read_timeout", 60),
195+
)
190196

191197
def _parse_url(self, url, **kwargs):
192198
try:
@@ -260,6 +266,7 @@ def get_resource(self):
260266
aws_access_key_id=self.params.get(self.KEY_ID),
261267
aws_secret_access_key=self.params.get(self.SECRET_KEY),
262268
endpoint_url=self.params.get(self.ENDPOINT_URL),
269+
config=self._config,
263270
)
264271
except Exception as exc:
265272
raise AuthenticationError(str(exc))
@@ -282,6 +289,7 @@ def get_service(self, service_name, use_default_region=True):
282289
if self.is_wasabi and use_default_region
283290
else self.region
284291
),
292+
config=self._config,
285293
)
286294
except Exception as exc:
287295
raise AuthenticationError(str(exc))

0 commit comments

Comments
 (0)