bifrostsdk 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bifrostsdk-1.0.0.dist-info/LICENSE +21 -0
- bifrostsdk-1.0.0.dist-info/METADATA +124 -0
- bifrostsdk-1.0.0.dist-info/RECORD +48 -0
- bifrostsdk-1.0.0.dist-info/WHEEL +5 -0
- bifrostsdk-1.0.0.dist-info/top_level.txt +1 -0
- byfrost/__init__.py +46 -0
- byfrost/__init__.pyi +81 -0
- byfrost/bifrost.py +148 -0
- byfrost/bifrost.pyi +36 -0
- byfrost/gcs/__init__.py +3 -0
- byfrost/gcs/__init__.pyi +3 -0
- byfrost/gcs/gcs.py +189 -0
- byfrost/gcs/gcs.pyi +65 -0
- byfrost/pinata/__init__.py +0 -0
- byfrost/pinata/__init__.pyi +0 -0
- byfrost/pinata/pinata.py +221 -0
- byfrost/pinata/pinata.pyi +54 -0
- byfrost/s3/__init__.py +0 -0
- byfrost/s3/__init__.pyi +0 -0
- byfrost/s3/s3.py +188 -0
- byfrost/s3/s3.pyi +65 -0
- byfrost/shared/__init__.py +3 -0
- byfrost/shared/config/__init__.py +29 -0
- byfrost/shared/config/__init__.pyi +29 -0
- byfrost/shared/config/option.py +21 -0
- byfrost/shared/config/provider.py +22 -0
- byfrost/shared/config/request.py +24 -0
- byfrost/shared/config/url.py +24 -0
- byfrost/shared/errors/__init__.py +16 -0
- byfrost/shared/errors/__init__.pyi +16 -0
- byfrost/shared/errors/color.py +18 -0
- byfrost/shared/errors/constant.py +30 -0
- byfrost/shared/errors/interface.py +21 -0
- byfrost/shared/errors/interface.pyi +21 -0
- byfrost/shared/errors/loga.py +28 -0
- byfrost/shared/errors/loga.pyi +21 -0
- byfrost/shared/request/__init__.py +1 -0
- byfrost/shared/request/__init__.pyi +1 -0
- byfrost/shared/request/builder.py +51 -0
- byfrost/shared/types/__init__.py +1 -0
- byfrost/shared/types/dataclass/__init__.py +4 -0
- byfrost/shared/types/dataclass/__init__.pyi +4 -0
- byfrost/shared/types/dataclass/bridge.py +155 -0
- byfrost/shared/types/dataclass/file.py +222 -0
- byfrost/shared/types/typeddict/__init__.py +12 -0
- byfrost/shared/types/typeddict/__init__.pyi +12 -0
- byfrost/shared/types/typeddict/bridge.py +85 -0
- byfrost/shared/types/typeddict/file.py +203 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Ifihanagbara Olusheye
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: bifrostsdk
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Rainbow Bridge for shipping your files to any cloud storage service with the same function calls
|
|
5
|
+
Author-email: ifihan <victoriaolusheye@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Ifihan/byfrost
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/Ifihan/byfrost/issues
|
|
9
|
+
Project-URL: Documentation, https://github.com/Ifihan/byfrost/blob/main/README.md
|
|
10
|
+
Project-URL: Source Code, https://github.com/Ifihan/byfrost
|
|
11
|
+
Keywords: cloud,storage,gcs,s3,pinata,upload,aws,google-cloud,bifrost
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
+
Classifier: Topic :: Internet
|
|
23
|
+
Requires-Python: >=3.8
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: google-cloud-storage>=2.5.0
|
|
27
|
+
Requires-Dist: boto3>=1.34.0
|
|
28
|
+
Requires-Dist: requests>=2.25.0
|
|
29
|
+
Requires-Dist: requests-toolbelt>=1.0.0
|
|
30
|
+
|
|
31
|
+
# Bifrost
|
|
32
|
+
|
|
33
|
+
Rainbow Bridge for shipping your files to any cloud storage service with the same function calls.
|
|
34
|
+
|
|
35
|
+
<img src="https://user-images.githubusercontent.com/59074379/226159115-1cfcb221-127f-4574-87ed-b74b4b2c4591.png" width="1000" />
|
|
36
|
+
|
|
37
|
+
# Table of contents
|
|
38
|
+
|
|
39
|
+
- [Bifrost](#bifrost)
|
|
40
|
+
- [Problem Statement](#problem-statement)
|
|
41
|
+
- [Google Cloud Storage using GCS SDK](#google-cloud-storage-using-gcs-sdk)
|
|
42
|
+
- [Pinata Cloud using Pinata API](#pinata-cloud-using-pinata-api)
|
|
43
|
+
- [Using Bifrost](#using-bifrost)
|
|
44
|
+
- [Installation](#installation)
|
|
45
|
+
- [Usage](#usage)
|
|
46
|
+
- [Contributing](#contributing)
|
|
47
|
+
- [License](#license)
|
|
48
|
+
- [Changelog](#changelog)
|
|
49
|
+
- [Contributors](#contributors)
|
|
50
|
+
|
|
51
|
+
# Problem Statement
|
|
52
|
+
|
|
53
|
+
Many projects need to store files in the cloud and different projects might use different cloud storage providers or, sometimes, multiple cloud providers all at once. Using different SDKs with different implementations for each provider can be tedious and time-consuming. Bifrost aims to simplify the process of working with multiple cloud storage providers by providing a consistent API for all of them.
|
|
54
|
+
|
|
55
|
+
To gain a better understanding of how Bifrost addresses this issue, let's take you on a ride with Thor by comparing two different code samples for working with Google Cloud Storage and Pinata Cloud in a single project: one using a conventional approach and the other using Bifrost.
|
|
56
|
+
|
|
57
|
+
## Google Cloud Storage using GCS SDK
|
|
58
|
+
|
|
59
|
+
Without Bifrost, the process of uploading a file to GCS using the Google Cloud Storage client library for Python would typically involve the following steps:
|
|
60
|
+
|
|
61
|
+
```py
|
|
62
|
+
# to be added
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Pinata Cloud using Pinata API
|
|
66
|
+
|
|
67
|
+
...and for Pinata Cloud, the usual way of uploading a file in Python would be something along the following steps:
|
|
68
|
+
|
|
69
|
+
```py
|
|
70
|
+
# to be added
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
We can already see the challenges of the conventional methods since they require you to learn to use multiple packages with separate implementation patterns. Now this is why `Bifrost` comes in! With Bifrost, you can mount rainbow bridges to the providers you want and use the same set of functions to upload files through any of these mounted bridges. This makes it much easier to work with multiple providers and streamlines the development process to just one learning curve.
|
|
74
|
+
|
|
75
|
+
Now, let's see how we can revamp the two samples above into something much more exciting with Bifrost.
|
|
76
|
+
|
|
77
|
+
## Using Bifrost
|
|
78
|
+
|
|
79
|
+
```py
|
|
80
|
+
# to be added
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
The above example clearly demonstrates the speed, simplicity, and ease of use that Bifrost offers. Now you know what it feels like to ride with Thor!
|
|
84
|
+
|
|
85
|
+
# Installation
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
pip install byfrost
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
# Usage
|
|
92
|
+
|
|
93
|
+
If you want to learn more about how Bifrost is creating different methods to make it easier to use different cloud providers, you can follow these links:
|
|
94
|
+
|
|
95
|
+
- [Google Cloud Storage (GCS)](gcs\doc.md)
|
|
96
|
+
- [Amazon S3](s3\doc.md)
|
|
97
|
+
- [Pinata Cloud](pinata\doc.md)
|
|
98
|
+
|
|
99
|
+
# Variants
|
|
100
|
+
|
|
101
|
+
Bifrost also exists in other forms and languages and you are free to start a new variant of bifrost in any other form or language of your choice. For now, below are the know variants of bifrost.
|
|
102
|
+
|
|
103
|
+
- [x] [Bifrost in Golang](https://github.com/opensaucerer/bifrost)
|
|
104
|
+
- [x] [Bifrost CLI](https://github.com/showbaba/bifrost-cli)
|
|
105
|
+
|
|
106
|
+
# Contributing
|
|
107
|
+
|
|
108
|
+
Bifrost is an open source project and we welcome contributions of all kinds. Please read our [contributing guide](./contributing.md) to learn about our development process, how to propose bug fixes and improvements, and how to build and test your changes to Bifrost.
|
|
109
|
+
|
|
110
|
+
# License
|
|
111
|
+
|
|
112
|
+
Bifrost is [MIT licensed](./LICENSE).
|
|
113
|
+
|
|
114
|
+
# Changelog
|
|
115
|
+
|
|
116
|
+
See [changelog](./changelog.md) for more details.
|
|
117
|
+
|
|
118
|
+
# Contributors
|
|
119
|
+
|
|
120
|
+
<a href="https://github.com/ifihan/byfrost/graphs/contributors">
|
|
121
|
+
<img src="https://contrib.rocks/image?repo=ifihan/byfrost" />
|
|
122
|
+
</a>
|
|
123
|
+
|
|
124
|
+
Made with [contrib.rocks](https://contrib.rocks).
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
byfrost/__init__.py,sha256=1pr8h2B0pg5L4WpUR4rLdKySURqd8C9jJOOBNpni2bk,1007
|
|
2
|
+
byfrost/__init__.pyi,sha256=DT5W9Btl9rLCx1I1FJTFlxnKiePg7tEXMzDCOJRjD7s,1734
|
|
3
|
+
byfrost/bifrost.py,sha256=VlL9cKEyTbisP0HsSmeJDYRA0QlnpXp_eYFlWhRj0to,5550
|
|
4
|
+
byfrost/bifrost.pyi,sha256=69Bn2JPFpvbJy3vN3NnyN5DdOyoaEqwxOijp_nOrkfk,1145
|
|
5
|
+
byfrost/gcs/__init__.py,sha256=BqwDK2qFtsuETTA7brYvKsrwzn61F7SbRxLCLgcM8gI,61
|
|
6
|
+
byfrost/gcs/__init__.pyi,sha256=30FbMGSTtfO7j8numKz6Y-w9U2Rul_aYt_2MOzhS5t4,62
|
|
7
|
+
byfrost/gcs/gcs.py,sha256=jEcugvz-_R1ZfxJcVDCC_OIQhxK_Vra-6N8NZxQYqh8,7070
|
|
8
|
+
byfrost/gcs/gcs.pyi,sha256=_YmIxcQp8p8iEygdNSuO0amBwbKLGxb2nN3OG84HWYk,2427
|
|
9
|
+
byfrost/pinata/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
|
+
byfrost/pinata/__init__.pyi,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
|
+
byfrost/pinata/pinata.py,sha256=qB1qAwV15AuA_BPAETdKJ9glTDFoaN7DddWWxZlAUm8,8567
|
|
12
|
+
byfrost/pinata/pinata.pyi,sha256=QrUdAfGcC1P-S7CIMWqo7dhgBIvaImbXElEfTLYN5Xw,2053
|
|
13
|
+
byfrost/s3/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
14
|
+
byfrost/s3/__init__.pyi,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
15
|
+
byfrost/s3/s3.py,sha256=llSDKl5GjVF6zIf8vhjOe-Bld8Avz-rXhNSMM-Arozs,7506
|
|
16
|
+
byfrost/s3/s3.pyi,sha256=jTLGi0xR49NEi1lDDAZhb45tByW90mnic_zH4oWYjVE,2393
|
|
17
|
+
byfrost/shared/__init__.py,sha256=qQKiq7IZkXJb0cxtDEbr9yE3vYEzeAUNwbCTPHnphRU,82
|
|
18
|
+
byfrost/shared/config/__init__.py,sha256=JpD4txuKahBG3NdpybAuOOKlif_Ew8PYdkwnTCQWtsE,554
|
|
19
|
+
byfrost/shared/config/__init__.pyi,sha256=JpD4txuKahBG3NdpybAuOOKlif_Ew8PYdkwnTCQWtsE,554
|
|
20
|
+
byfrost/shared/config/option.py,sha256=i0M1iBnSLghbb6xvQjj9n3pd-FX7ftpxkSHK2H-d0Nc,583
|
|
21
|
+
byfrost/shared/config/provider.py,sha256=cs3uFslpy3mZxy105AUx3hlets4FQhivZULrHB9TDeA,561
|
|
22
|
+
byfrost/shared/config/request.py,sha256=ZbPRXbBMaeMTkOWFXa2LmceWBdJopATjjdqodGiB3BE,599
|
|
23
|
+
byfrost/shared/config/url.py,sha256=o2ewH5U6mSWNXjApCRDt-DIQJj8eKPFMYtx-ZFpYzPI,1055
|
|
24
|
+
byfrost/shared/errors/__init__.py,sha256=NvptpP9r4UceLt3IREmmRrhuIwN2SM26HCmi1IDpZ6o,397
|
|
25
|
+
byfrost/shared/errors/__init__.pyi,sha256=NvptpP9r4UceLt3IREmmRrhuIwN2SM26HCmi1IDpZ6o,397
|
|
26
|
+
byfrost/shared/errors/color.py,sha256=ayOmZ9fN_LDHQ3sMCpzxWASdCq-e0v9-7KCtCtbImmU,266
|
|
27
|
+
byfrost/shared/errors/constant.py,sha256=pKWdffk3Q4PiBYie3KJ1_7BU0E7uZYPgH-PNMN66AfA,1103
|
|
28
|
+
byfrost/shared/errors/interface.py,sha256=yx9dGWvZw9moWENXFxzlvO85fFMHrVNtaLEMY_hiNa0,499
|
|
29
|
+
byfrost/shared/errors/interface.pyi,sha256=qrxY4uwTGvdYVBSWZtEf6YNalF6Y8MIH2vJq9gvKxr0,533
|
|
30
|
+
byfrost/shared/errors/loga.py,sha256=BJ1UQIJhfrRzgDigW8PNWaKUFO3mS6Kjf-YpSAwPRJY,636
|
|
31
|
+
byfrost/shared/errors/loga.pyi,sha256=cJhOaBUS1qDcjtj3QFu87wR1P_YY3KplAdyllJZlUuk,509
|
|
32
|
+
byfrost/shared/request/__init__.py,sha256=shiW_0dDtAqrYG1DPDUorcpw72bCdw-LuF8CmU1Omp8,40
|
|
33
|
+
byfrost/shared/request/__init__.pyi,sha256=shiW_0dDtAqrYG1DPDUorcpw72bCdw-LuF8CmU1Omp8,40
|
|
34
|
+
byfrost/shared/request/builder.py,sha256=QRB46ZCEsHhw8a3oSN-zON2WBH3TOXiVLlG-sF0cG9Q,1607
|
|
35
|
+
byfrost/shared/types/__init__.py,sha256=9YNyE-o_Qrl7h2Ep-Oe3da3EEvxrZW6KfznRw85o6s8,57
|
|
36
|
+
byfrost/shared/types/dataclass/__init__.py,sha256=yRwLB510YdjHbuSy05d5rvi_ymCWQMDHPi-XBwDUts8,157
|
|
37
|
+
byfrost/shared/types/dataclass/__init__.pyi,sha256=yRwLB510YdjHbuSy05d5rvi_ymCWQMDHPi-XBwDUts8,157
|
|
38
|
+
byfrost/shared/types/dataclass/bridge.py,sha256=7mbaBxk0peA-pmbFVceQXDFkf3N1CwdZXWtKtwKQ5mw,5946
|
|
39
|
+
byfrost/shared/types/dataclass/file.py,sha256=j8sS0ylmjNeAtxUgLqLMM4JKEgoSan1QXpaNrcL9KJo,6940
|
|
40
|
+
byfrost/shared/types/typeddict/__init__.py,sha256=hwqGw9bWkCg0rTvh6Grv8aKsXs0-Eg_p73YjDCgtoK8,207
|
|
41
|
+
byfrost/shared/types/typeddict/__init__.pyi,sha256=hwqGw9bWkCg0rTvh6Grv8aKsXs0-Eg_p73YjDCgtoK8,207
|
|
42
|
+
byfrost/shared/types/typeddict/bridge.py,sha256=_8knfRJ1Ga7dia6JX1pTmFf3Tcdpsoql9_olY_mHDvE,3048
|
|
43
|
+
byfrost/shared/types/typeddict/file.py,sha256=_3Cq8lsXFmLGFyevtU0D-Ivn_J-mOIQAiEUELFyi9sM,6408
|
|
44
|
+
bifrostsdk-1.0.0.dist-info/LICENSE,sha256=gukzCu68-M_u6bkG_omJ_C1OkcMiHRwmSJcmvc_QTNQ,1078
|
|
45
|
+
bifrostsdk-1.0.0.dist-info/METADATA,sha256=o4WDm_frxqtTkDG8rPZBNm-wzBet57FuwQDwALCFjAw,5137
|
|
46
|
+
bifrostsdk-1.0.0.dist-info/WHEEL,sha256=pL8R0wFFS65tNSRnaOVrsw9EOkOqxLrlUPenUYnJKNo,91
|
|
47
|
+
bifrostsdk-1.0.0.dist-info/top_level.txt,sha256=iTb_8hhhNCRAjPZzTK2M33AUEoJWwGJY-p1NffHcFk4,8
|
|
48
|
+
bifrostsdk-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
byfrost
|
byfrost/__init__.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
from .shared.types.dataclass.bridge import BridgeConfig, RainbowBridge
|
|
4
|
+
from .shared.types.dataclass.file import File, MultiFile, Options
|
|
5
|
+
|
|
6
|
+
from .shared.types.typeddict.bridge import BridgeConfigDict
|
|
7
|
+
from .shared.types.typeddict.file import (
|
|
8
|
+
OptionsDict,
|
|
9
|
+
FileDict,
|
|
10
|
+
MultiFileDict,
|
|
11
|
+
ParamFileDict,
|
|
12
|
+
ParamDataDict,
|
|
13
|
+
ParamDict,
|
|
14
|
+
UploadedFileDict,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
from .shared.errors.constant import (
|
|
18
|
+
ErrBadRequest,
|
|
19
|
+
ErrClientError,
|
|
20
|
+
ErrIncompleteMultiFileUpload,
|
|
21
|
+
ErrInvalidBucket,
|
|
22
|
+
ErrInvalidConfig,
|
|
23
|
+
ErrInvalidCredentials,
|
|
24
|
+
ErrInvalidProvider,
|
|
25
|
+
ErrUnauthorized,
|
|
26
|
+
ErrFileOperationFailed,
|
|
27
|
+
)
|
|
28
|
+
from .shared.errors.interface import BifrostError
|
|
29
|
+
from .shared.config.provider import (
|
|
30
|
+
GoogleCloudStorage,
|
|
31
|
+
PinataCloud,
|
|
32
|
+
SimpleStorageService,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
from .shared.config.option import (
|
|
36
|
+
OptACL,
|
|
37
|
+
ACLPublicRead,
|
|
38
|
+
ACLPrivate,
|
|
39
|
+
OptContentType,
|
|
40
|
+
OptMetadata,
|
|
41
|
+
OptPinata,
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
from .bifrost import new_rainbow_bridge
|
|
45
|
+
|
|
46
|
+
__name__ = "byfrost"
|
byfrost/__init__.pyi
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#!usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
from .shared.types.dataclass.bridge import BridgeConfig, RainbowBridge
|
|
4
|
+
from .shared.types.dataclass.file import File, MultiFile, Options
|
|
5
|
+
|
|
6
|
+
from .shared.types.typeddict.bridge import BridgeConfigDict
|
|
7
|
+
from .shared.types.typeddict.file import (
|
|
8
|
+
OptionsDict,
|
|
9
|
+
FileDict,
|
|
10
|
+
MultiFileDict,
|
|
11
|
+
ParamFileDict,
|
|
12
|
+
ParamDataDict,
|
|
13
|
+
ParamDict,
|
|
14
|
+
UploadedFileDict,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
from .shared.errors.constant import (
|
|
18
|
+
ErrBadRequest,
|
|
19
|
+
ErrClientError,
|
|
20
|
+
ErrIncompleteMultiFileUpload,
|
|
21
|
+
ErrInvalidBucket,
|
|
22
|
+
ErrInvalidConfig,
|
|
23
|
+
ErrInvalidCredentials,
|
|
24
|
+
ErrInvalidProvider,
|
|
25
|
+
ErrUnauthorized,
|
|
26
|
+
ErrFileOperationFailed,
|
|
27
|
+
)
|
|
28
|
+
from .shared.errors.interface import BifrostError
|
|
29
|
+
from .shared.config.provider import (
|
|
30
|
+
GoogleCloudStorage,
|
|
31
|
+
PinataCloud,
|
|
32
|
+
SimpleStorageService,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
from .shared.config.option import (
|
|
36
|
+
OptACL,
|
|
37
|
+
ACLPublicRead,
|
|
38
|
+
ACLPrivate,
|
|
39
|
+
OptContentType,
|
|
40
|
+
OptMetadata,
|
|
41
|
+
OptPinata,
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
from .bifrost import new_rainbow_bridge
|
|
45
|
+
|
|
46
|
+
__name__ = "byfrost"
|
|
47
|
+
__all__ = [
|
|
48
|
+
"BridgeConfig",
|
|
49
|
+
"RainbowBridge",
|
|
50
|
+
"File",
|
|
51
|
+
"Options",
|
|
52
|
+
"MultiFile",
|
|
53
|
+
"BridgeConfigDict",
|
|
54
|
+
"OptionsDict",
|
|
55
|
+
"FileDict",
|
|
56
|
+
"MultiFileDict",
|
|
57
|
+
"ParamFileDict",
|
|
58
|
+
"ParamDataDict",
|
|
59
|
+
"ParamDict",
|
|
60
|
+
"UploadedFileDict",
|
|
61
|
+
"ErrBadRequest",
|
|
62
|
+
"ErrClientError",
|
|
63
|
+
"ErrIncompleteMultiFileUpload",
|
|
64
|
+
"ErrInvalidBucket",
|
|
65
|
+
"ErrInvalidConfig",
|
|
66
|
+
"ErrInvalidCredentials",
|
|
67
|
+
"ErrInvalidProvider",
|
|
68
|
+
"ErrUnauthorized",
|
|
69
|
+
"ErrFileOperationFailed",
|
|
70
|
+
"BifrostError",
|
|
71
|
+
"GoogleCloudStorage",
|
|
72
|
+
"PinataCloud",
|
|
73
|
+
"SimpleStorageService",
|
|
74
|
+
"new_rainbow_bridge",
|
|
75
|
+
"OptACL",
|
|
76
|
+
"ACLPublicRead",
|
|
77
|
+
"ACLPrivate",
|
|
78
|
+
"OptContentType",
|
|
79
|
+
"OptMetadata",
|
|
80
|
+
"OptPinata",
|
|
81
|
+
]
|
byfrost/bifrost.py
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
# from byfrost.gcs.gcs import GoogleCloudStorage
|
|
4
|
+
from .gcs.gcs import GoogleCloudStorage
|
|
5
|
+
from .s3.s3 import SimpleStorageService
|
|
6
|
+
from .shared.types.dataclass import bridge
|
|
7
|
+
from .shared.errors.interface import BifrostError
|
|
8
|
+
from typing import Tuple, Union
|
|
9
|
+
from .shared.errors import constant as errors
|
|
10
|
+
from .shared.config import provider, url
|
|
11
|
+
from .shared.errors import loga
|
|
12
|
+
from google.cloud import storage
|
|
13
|
+
import requests
|
|
14
|
+
from .pinata.pinata import PinataCloud
|
|
15
|
+
from .shared.request import builder
|
|
16
|
+
import boto3
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def new_rainbow_bridge(
|
|
20
|
+
bc: bridge.BridgeConfig,
|
|
21
|
+
) -> Tuple[bridge.RainbowBridge, BifrostError]:
|
|
22
|
+
"""Returns a new Rainbow Bridge for shipping files to your specified cloud storage service and an error if one occurs."""
|
|
23
|
+
if bc is None:
|
|
24
|
+
return None, BifrostError("config is none", errors.ErrInvalidConfig)
|
|
25
|
+
|
|
26
|
+
# verify that the config is derived from BridgeConfig
|
|
27
|
+
if not isinstance(bc, bridge.BridgeConfig):
|
|
28
|
+
return None, BifrostError(
|
|
29
|
+
"invalid config type: {}".format(type(bc)), errors.ErrInvalidConfig
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
# verify that the config dataclass has a valid provider
|
|
33
|
+
if bc.provider is None or bc.provider == "":
|
|
34
|
+
return None, BifrostError("no provider specified", errors.ErrInvalidProvider)
|
|
35
|
+
|
|
36
|
+
# verify that the provider is valid
|
|
37
|
+
if bc.provider not in provider.providers:
|
|
38
|
+
return None, BifrostError(
|
|
39
|
+
"invalid provider: {}".format(bc.provider), errors.ErrInvalidProvider
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
# verify that the config dataclass has a valid bucket
|
|
43
|
+
if bc.default_bucket is None or bc.default_bucket == "":
|
|
44
|
+
# some providers might not require a bucket
|
|
45
|
+
# just log a warning
|
|
46
|
+
if bc.enable_debug is True:
|
|
47
|
+
loga.warn(
|
|
48
|
+
"WARN: No bucket specified for provider: {}. This might cause errors or require you to specify a bucket for each operation.".format(
|
|
49
|
+
bc.provider
|
|
50
|
+
)
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
# create a new bridge based on the provider
|
|
54
|
+
if bc.provider == provider.GoogleCloudStorage:
|
|
55
|
+
return new_google_cloud_storage(bc)
|
|
56
|
+
|
|
57
|
+
if bc.provider == provider.PinataCloud:
|
|
58
|
+
return new_pinata_cloud_storage(bc)
|
|
59
|
+
|
|
60
|
+
if bc.provider == provider.SimpleStorageService:
|
|
61
|
+
return new_simple_storage_service(bc)
|
|
62
|
+
|
|
63
|
+
return None, BifrostError(
|
|
64
|
+
"invalid provider: {}".format(bc.provider), errors.ErrInvalidProvider
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def new_google_cloud_storage(
|
|
69
|
+
bc: bridge.BridgeConfig,
|
|
70
|
+
) -> Tuple[bridge.RainbowBridge, BifrostError]:
|
|
71
|
+
"""Returns a new client for Google Cloud Storage."""
|
|
72
|
+
client: storage.Client = None
|
|
73
|
+
|
|
74
|
+
# attempting to authenticate with credentials file
|
|
75
|
+
if bc.credentials_file is not None and bc.credentials_file != "":
|
|
76
|
+
try:
|
|
77
|
+
client = storage.Client.from_service_account_json(bc.credentials_file)
|
|
78
|
+
except Exception as e:
|
|
79
|
+
return None, BifrostError(str(e), errors.ErrUnauthorized)
|
|
80
|
+
return GoogleCloudStorage(bc, client), None
|
|
81
|
+
else:
|
|
82
|
+
# attempt to authenticate without credentials file
|
|
83
|
+
try:
|
|
84
|
+
client = storage.Client()
|
|
85
|
+
except Exception as e:
|
|
86
|
+
return None, BifrostError(str(e), errors.ErrUnauthorized)
|
|
87
|
+
|
|
88
|
+
# return a new Google Cloud Storage client (the bifrost version)
|
|
89
|
+
return GoogleCloudStorage(bc, client), None
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def new_pinata_cloud_storage(
|
|
93
|
+
bc: bridge.BridgeConfig,
|
|
94
|
+
) -> Tuple[bridge.RainbowBridge, BifrostError]:
|
|
95
|
+
"""new_pinata_cloud_storage returns a new client for Pinata Cloud Storage"""
|
|
96
|
+
# TODO: add support for API key and API secret
|
|
97
|
+
client: builder.new_client = None
|
|
98
|
+
|
|
99
|
+
# attempting to authenticate with JWT token
|
|
100
|
+
if bc.pinata_jwt is not None and bc.pinata_jwt != "":
|
|
101
|
+
try:
|
|
102
|
+
client = builder.new_client(
|
|
103
|
+
url.URLPinataAuth, bc.pinata_jwt, bc.default_timeout
|
|
104
|
+
)
|
|
105
|
+
pc = PinataCloud(bc, client)
|
|
106
|
+
error = pc.preflight()
|
|
107
|
+
if error is not None:
|
|
108
|
+
return None, error
|
|
109
|
+
except Exception as e:
|
|
110
|
+
return None, BifrostError(str(e), errors.ErrUnauthorized)
|
|
111
|
+
return pc, None
|
|
112
|
+
return None, BifrostError("pinata JWT is required", errors.ErrUnauthorized)
|
|
113
|
+
|
|
114
|
+
# return a new Pinata Cloud client (the bifrost version)
|
|
115
|
+
return PinataCloud(bc, client), None
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def new_simple_storage_service(
|
|
119
|
+
bc: bridge.BridgeConfig,
|
|
120
|
+
) -> Tuple[bridge.RainbowBridge, BifrostError]:
|
|
121
|
+
"""new_simple_storage_service returns a new client for Simple Storage Service."""
|
|
122
|
+
client: boto3.session.resource("s3")
|
|
123
|
+
|
|
124
|
+
# attempting to authenticate with access and secret key
|
|
125
|
+
if (
|
|
126
|
+
bc.access_key is not None
|
|
127
|
+
and bc.access_key != ""
|
|
128
|
+
and bc.secret_key is not None
|
|
129
|
+
and bc.secret_key != ""
|
|
130
|
+
and bc.region is not None
|
|
131
|
+
and bc.region != ""
|
|
132
|
+
):
|
|
133
|
+
try:
|
|
134
|
+
session = boto3.session.Session(access_key, secret_key, region_name)
|
|
135
|
+
client = session.resource("s3")
|
|
136
|
+
except Exception as e:
|
|
137
|
+
return None, BifrostError(str(e), errors.ErrUnauthorized)
|
|
138
|
+
return SimpleStorageService(bc, client), None
|
|
139
|
+
else:
|
|
140
|
+
# attempt to authenticate without access key and secret key
|
|
141
|
+
try:
|
|
142
|
+
session = boto3.session.Session()
|
|
143
|
+
client = session.resource("s3")
|
|
144
|
+
except Exception as e:
|
|
145
|
+
return None, BifrostError(str(e), errors.ErrUnauthorized)
|
|
146
|
+
|
|
147
|
+
# return a new Amazon Simple Storage Service client (the bifrost version)
|
|
148
|
+
return SimpleStorageService(bc, client), None
|
byfrost/bifrost.pyi
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
Byfrost provides a rainbow bridge for shipping files to any cloud storage service.
|
|
5
|
+
|
|
6
|
+
It's like bifrost from marvel comics, but for files.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from .shared.types.dataclass import bridge
|
|
10
|
+
from typing import Tuple
|
|
11
|
+
from .shared.errors.interface import BifrostError
|
|
12
|
+
|
|
13
|
+
def new_rainbow_bridge(
|
|
14
|
+
bc: bridge.BridgeConfig,
|
|
15
|
+
) -> Tuple[bridge.RainbowBridge, BifrostError]:
|
|
16
|
+
"""
|
|
17
|
+
new_rainbow_bridge returns a new Rainbow Bridge for shipping files to your specified cloud storage service and an error if one occurs.
|
|
18
|
+
"""
|
|
19
|
+
...
|
|
20
|
+
|
|
21
|
+
def new_google_cloud_storage(
|
|
22
|
+
bc: bridge.BridgeConfig,
|
|
23
|
+
) -> Tuple[bridge.RainbowBridge, BifrostError]:
|
|
24
|
+
"""new_google_cloud_storage returns a new client for Google Cloud Storage."""
|
|
25
|
+
...
|
|
26
|
+
|
|
27
|
+
def new_pinata_cloud_storage(
|
|
28
|
+
bc: bridge.BridgeConfig,
|
|
29
|
+
) -> Tuple[bridge.RainbowBridge, BifrostError]:
|
|
30
|
+
"""new_pinata_cloud_storage returns a new client for Pinata Cloud Storage."""
|
|
31
|
+
|
|
32
|
+
def new_simple_storage_service(
|
|
33
|
+
bc: bridge.BridgeConfig,
|
|
34
|
+
) -> Tuple[bridge.RainbowBridge, BifrostError]:
|
|
35
|
+
"""new_simple_storage_service returns a new client for Simple Storage Service."""
|
|
36
|
+
...
|
byfrost/gcs/__init__.py
ADDED
byfrost/gcs/__init__.pyi
ADDED