Skip to content

Commit f11fff6

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

File tree

8 files changed

+689
-16
lines changed

8 files changed

+689
-16
lines changed

README.rst

Lines changed: 49 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,53 @@ 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+
- Using env variables
467+
- Using custom client params
468+
469+
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>`__.
470+
471+
472+
OBS Advanced Usage
473+
--------------------
474+
- Supported env variables:
475+
OBS_ACCESS_KEY_ID,
476+
OBS_SECRET_ACCESS_KEY,
477+
OBS_SECURITY_TOKEN,
478+
SMART_OPEN_OBS_USE_CLIENT_WRITE_MODE,
479+
SMART_OPEN_OBS_DECRYPT_AK_SK,
480+
SMART_OPEN_OBS_SCC_LIB_PATH,
481+
SMART_OPEN_OBS_SCC_CONF_PATH
482+
483+
- Configuration via code
484+
.. code-block:: python
485+
486+
client = {'access_key_id': 'ak', 'secret_access_key': 'sk', 'security_token': 'st', 'server': 'server_url'}
487+
headers = []
488+
transport_params = {
489+
>>> # client can be dict with parameters supported by the obs.ObsClient or instance of the obs.ObsClient
490+
>>> 'client': client,
491+
>>> # additional header for request, please see esdk-obs-python docs
492+
>>> 'headers': headers,
493+
>>> # if True obs.ObsClient will be take write method argument as readable object to get bytes. For writing mode only.
494+
>>> # Please see docs for ObsClient.putContent api.
495+
>>> 'use_obs_client_write_mode': True,
496+
>>> # True if need decrypt Ak, Sk, St
497+
>>> # It required to install CryptoAPI libs.
498+
>>> # https://support.huawei.com/enterprise/en/software/260510077-ESW2000847337
499+
>>> 'decrypt_ak_sk' : True,
500+
>>> # path to python libs of the Crypto provider
501+
>>> 'scc_lib_path': '/usr/lib/scc',
502+
>>> # path to config file of the Crypto provider
503+
>>> 'scc_conf_path': '/home/user/scc.conf'}
504+
505+
fout = open('obs://bucket_id.server:port/object_key', 'wb', transport_params=transport_params)
506+
458507
Drop-in replacement of ``pathlib.Path.open``
459508
--------------------------------------------
460509

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)