Skip to content

Commit c4e40cf

Browse files
imhysWX1071736
authored andcommitted
Added basic functionality for read and write to HUAWEI Object Storage Service (OBS)
1 parent 5a82613 commit c4e40cf

File tree

8 files changed

+691
-16
lines changed

8 files changed

+691
-16
lines changed

README.rst

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ Other examples of URLs that ``smart_open`` accepts::
9393
s3://my_key:my_secret@my_server:my_port@my_bucket/my_key
9494
gs://my_bucket/my_blob
9595
azure://my_bucket/my_blob
96+
obs://bucket_id.server:port/object_key
9697
hdfs:///path/file
9798
hdfs://path/file
9899
webhdfs://host:port/path/file
@@ -290,6 +291,7 @@ Transport-specific Options
290291
- WebHDFS
291292
- GCS
292293
- Azure Blob Storage
294+
- OBS (Huawei Object Storage)
293295

294296
Each option involves setting up its own set of parameters.
295297
For example, for accessing S3, you often need to set up authentication, like API keys or a profile name.
@@ -455,6 +457,55 @@ Additional keyword arguments can be propagated to the ``commit_block_list`` meth
455457
kwargs = {'metadata': {'version': 2}}
456458
fout = open('azure://container/key', 'wb', transport_params={'blob_kwargs': kwargs})
457459
460+
OBS Credentials
461+
---------------
462+
``smart_open`` uses the ``esdk-obs-python`` library to talk to OBS.
463+
Please see `esdk-obs-python docs <https://support.huaweicloud.com/intl/en-us/sdk-python-devg-obs/obs_22_0500.html>`__.
464+
465+
There are several ways to provide Access key, Secret Key and Security Token
466+
467+
- Using env variables
468+
- Using custom client params
469+
470+
AK, SK, ST can be encrypted in this case You need install and configure `security provider <https://support.huawei.com/enterprise/en/software/260510077-ESW2000847337>`__.
471+
472+
473+
OBS Advanced Usage
474+
--------------------
475+
- Supported env variables:
476+
477+
OBS_ACCESS_KEY_ID,
478+
OBS_SECRET_ACCESS_KEY,
479+
OBS_SECURITY_TOKEN,
480+
SMART_OPEN_OBS_USE_CLIENT_WRITE_MODE,
481+
SMART_OPEN_OBS_DECRYPT_AK_SK,
482+
SMART_OPEN_OBS_SCC_LIB_PATH,
483+
SMART_OPEN_OBS_SCC_CONF_PATH
484+
485+
- Configuration via code
486+
.. code-block:: python
487+
488+
client = {'access_key_id': 'ak', 'secret_access_key': 'sk', 'security_token': 'st', 'server': 'server_url'}
489+
headers = []
490+
transport_params = {
491+
>>> # client can be dict with parameters supported by the obs.ObsClient or instance of the obs.ObsClient
492+
>>> 'client': client,
493+
>>> # additional header for request, please see esdk-obs-python docs
494+
>>> 'headers': headers,
495+
>>> # if True obs.ObsClient will be take write method argument as readable object to get bytes. For writing mode only.
496+
>>> # Please see docs for ObsClient.putContent api.
497+
>>> 'use_obs_client_write_mode': True,
498+
>>> # True if need decrypt Ak, Sk, St
499+
>>> # It required to install CryptoAPI libs.
500+
>>> # https://support.huawei.com/enterprise/en/software/260510077-ESW2000847337
501+
>>> 'decrypt_ak_sk' : True,
502+
>>> # path to python libs of the Crypto provider
503+
>>> 'scc_lib_path': '/usr/lib/scc',
504+
>>> # path to config file of the Crypto provider
505+
>>> 'scc_conf_path': '/home/user/scc.conf'}
506+
507+
fout = open('obs://bucket_id.server:port/object_key', 'wb', transport_params=transport_params)
508+
458509
Drop-in replacement of ``pathlib.Path.open``
459510
--------------------------------------------
460511

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ def read(fname):
4242
http_deps = ['requests']
4343
ssh_deps = ['paramiko']
4444
zst_deps = ['zstandard']
45+
obs_deps = ['esdk-obs-python']
4546

46-
all_deps = aws_deps + gcs_deps + azure_deps + http_deps + ssh_deps + zst_deps
47+
all_deps = aws_deps + gcs_deps + azure_deps + http_deps + ssh_deps + zst_deps + obs_deps
4748
tests_require = all_deps + [
4849
'moto[server]',
4950
'responses',
@@ -83,6 +84,7 @@ def read(fname):
8384
'webhdfs': http_deps,
8485
'ssh': ssh_deps,
8586
'zst': zst_deps,
87+
'obs': obs_deps,
8688
},
8789
python_requires=">=3.7,<4.0",
8890

0 commit comments

Comments
 (0)