Skip to content

Commit e7444b4

Browse files
Merge pull request #5 from kerthcet/feat/add-oss-s3
Add support for aliyun oss
2 parents 8d32234 + f3ccb63 commit e7444b4

20 files changed

Lines changed: 829 additions & 55 deletions

.dockerignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

.env.example

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# You should have a .env file locally for testing.
2+
3+
# Aliyun OSS
4+
OSS_ACCESS_KEY_ID=
5+
OSS_ACCESS_KEY_SECRET=
6+
ENDPOINT=
7+
BUCKET=

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ Dockerfile.cross
2626
.DS_Store
2727
artifacts
2828
cache
29+
tmp
30+
.env
2931

3032
__pycache__
3133
*.pyc
34+
.pytest_cache
35+
dist

Dockerfile

Lines changed: 0 additions & 21 deletions
This file was deleted.

Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.PHONY: lint
2+
lint:
3+
black .
4+
5+
.PHONY: test
6+
test: lint
7+
ifdef test_name
8+
pytest tests/unit_tests -v -k $(test_name)
9+
else
10+
pytest tests/unit_tests
11+
endif
12+
13+
.PHONY: test-integration
14+
test-integration: lint
15+
ifdef test_name
16+
pytest tests/integration_tests -v -k $(test_name)
17+
else
18+
pytest tests/integration_tests
19+
endif

kube-workflow-init.yaml

Lines changed: 0 additions & 10 deletions
This file was deleted.

kube-workflow.yaml

Lines changed: 0 additions & 21 deletions
This file was deleted.

omnistore/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from dotenv import load_dotenv
2+
3+
load_dotenv(".env")

omnistore/objstore/__init__.py

Whitespace-only changes.

omnistore/objstore/aliyun_oss.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import oss2
2+
from oss2.credentials import EnvironmentVariableCredentialsProvider
3+
4+
from omnistore.objstore.objstore import ObjStore
5+
6+
7+
class OSS(ObjStore):
8+
def __init__(self, endpoint: str, bucket: str):
9+
"""
10+
Construct a new client to communicate with the provider.
11+
"""
12+
13+
# Make sure environments OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET are exist.
14+
auth = oss2.ProviderAuth(EnvironmentVariableCredentialsProvider())
15+
self._bucket = oss2.Bucket(auth, endpoint, bucket)
16+
17+
def upload(self, src: str, dest: str):
18+
"""
19+
Upload will upload the obj to the provider.
20+
"""
21+
22+
oss2.resumable_upload(self._bucket, dest, src)
23+
24+
def download(self, src: str, dest: str):
25+
"""
26+
Download will download the required obj from the provider.
27+
"""
28+
29+
oss2.resumable_download(self._bucket, src, dest)
30+
31+
def delete(self, filename: str):
32+
"""
33+
Delete will delete the obj from the provider.
34+
"""
35+
36+
return self._bucket.delete_object(filename)
37+
38+
def exists(self, filename: str):
39+
"""
40+
Exists checks whether the obj exists in the provider.
41+
"""
42+
43+
return self._bucket.object_exists(filename)
44+
45+
def accessible(self) -> bool:
46+
"""
47+
Accessible checks whether the obj is visitable.
48+
"""
49+
raise NotImplementedError("OSS not implemented")

0 commit comments

Comments
 (0)