cloudtoolbox 0.1.0__tar.gz

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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Noverde
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,19 @@
1
+ Metadata-Version: 2.1
2
+ Name: cloudtoolbox
3
+ Version: 0.1.0
4
+ Summary: Toolbox for the cloud.
5
+ Author-email: Dotz Developers <devs-dotz@dotz.com>
6
+ Keywords: cloud,tools,utilities,google,gcp,amazon,aws
7
+ Classifier: Programming Language :: Python :: 3
8
+ Requires-Python: >=3.8
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Provides-Extra: amazon
12
+ Requires-Dist: boto3; extra == "amazon"
13
+ Provides-Extra: google
14
+ Requires-Dist: google-cloud-pubsub; extra == "google"
15
+ Requires-Dist: google-cloud-storage; extra == "google"
16
+
17
+ # Cloud Toolbox
18
+
19
+ Decouple your applications from cloud providers with carefully crafted service interfaces.
@@ -0,0 +1,3 @@
1
+ # Cloud Toolbox
2
+
3
+ Decouple your applications from cloud providers with carefully crafted service interfaces.
File without changes
File without changes
@@ -0,0 +1,11 @@
1
+ from typing import Any
2
+
3
+ import boto3
4
+
5
+
6
+ class Uploader:
7
+ def __init__(self, *args: Any, **kwargs: Any) -> None:
8
+ self.client = boto3.client("s3", *args, **kwargs)
9
+
10
+ def upload(self, bucket_name: str, destination_filename: str, source_filename: str) -> None:
11
+ self.client.upload_file(source_filename, bucket_name, destination_filename)
@@ -0,0 +1,29 @@
1
+ from typing import Any, Callable, Type
2
+
3
+ from cloud.protocols import MessagePublisher, StorageUploader
4
+
5
+ error_message = "%(class)s does not implement %(protocol)s protocol"
6
+
7
+
8
+ def storage_uploader(
9
+ uploader_class: Type[StorageUploader], *args: Any, **kwargs: Any
10
+ ) -> Callable[[], StorageUploader]:
11
+ error = error_message % {"class": uploader_class.__name__, "protocol": "StorageUploader"}
12
+ assert issubclass(uploader_class, StorageUploader), error
13
+
14
+ def maker() -> StorageUploader:
15
+ return uploader_class(*args, **kwargs)
16
+
17
+ return maker
18
+
19
+
20
+ def message_publisher(
21
+ publisher_class: Type[MessagePublisher], *args: Any, **kwargs: Any
22
+ ) -> Callable[[], MessagePublisher]:
23
+ error = error_message % {"class": publisher_class.__name__, "protocol": "MessagePublisher"}
24
+ assert issubclass(publisher_class, MessagePublisher), error
25
+
26
+ def maker() -> MessagePublisher:
27
+ return publisher_class(*args, **kwargs)
28
+
29
+ return maker
File without changes
@@ -0,0 +1,12 @@
1
+ from typing import Any
2
+
3
+ from google.cloud import pubsub_v1
4
+
5
+
6
+ class Publisher:
7
+ def __init__(self, *args: Any, **kwargs: Any) -> None:
8
+ self.client = pubsub_v1.PublisherClient(*args, **kwargs)
9
+
10
+ def publish(self, recipient: str, message: str, **attrs: Any) -> None:
11
+ future = self.client.publish(recipient, data=message.encode(), **attrs)
12
+ future.result()
@@ -0,0 +1,13 @@
1
+ from typing import Any
2
+
3
+ from google.cloud import storage
4
+
5
+
6
+ class Uploader:
7
+ def __init__(self, *args: Any, **kwargs: Any) -> None:
8
+ self.client = storage.Client(*args, **kwargs)
9
+
10
+ def upload(self, bucket_name: str, destination_filename: str, source_filename: str) -> None:
11
+ bucket = self.client.bucket(bucket_name)
12
+ blob = bucket.blob(destination_filename)
13
+ blob.upload_from_filename(source_filename)
@@ -0,0 +1,11 @@
1
+ from typing import Any, Protocol, runtime_checkable
2
+
3
+
4
+ @runtime_checkable
5
+ class StorageUploader(Protocol):
6
+ def upload(self, bucket_name: str, destination_filename: str, source_filename: str) -> None: ...
7
+
8
+
9
+ @runtime_checkable
10
+ class MessagePublisher(Protocol):
11
+ def publish(self, recipient: str, message: str, **attrs: Any) -> None: ...
@@ -0,0 +1,19 @@
1
+ Metadata-Version: 2.1
2
+ Name: cloudtoolbox
3
+ Version: 0.1.0
4
+ Summary: Toolbox for the cloud.
5
+ Author-email: Dotz Developers <devs-dotz@dotz.com>
6
+ Keywords: cloud,tools,utilities,google,gcp,amazon,aws
7
+ Classifier: Programming Language :: Python :: 3
8
+ Requires-Python: >=3.8
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Provides-Extra: amazon
12
+ Requires-Dist: boto3; extra == "amazon"
13
+ Provides-Extra: google
14
+ Requires-Dist: google-cloud-pubsub; extra == "google"
15
+ Requires-Dist: google-cloud-storage; extra == "google"
16
+
17
+ # Cloud Toolbox
18
+
19
+ Decouple your applications from cloud providers with carefully crafted service interfaces.
@@ -0,0 +1,17 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ cloud/__init__.py
5
+ cloud/factory.py
6
+ cloud/protocols.py
7
+ cloud/amazon/__init__.py
8
+ cloud/amazon/s3.py
9
+ cloud/google/__init__.py
10
+ cloud/google/pubsub.py
11
+ cloud/google/storage.py
12
+ cloudtoolbox.egg-info/PKG-INFO
13
+ cloudtoolbox.egg-info/SOURCES.txt
14
+ cloudtoolbox.egg-info/dependency_links.txt
15
+ cloudtoolbox.egg-info/requires.txt
16
+ cloudtoolbox.egg-info/top_level.txt
17
+ tests/test_factory.py
@@ -0,0 +1,7 @@
1
+
2
+ [amazon]
3
+ boto3
4
+
5
+ [google]
6
+ google-cloud-pubsub
7
+ google-cloud-storage
@@ -0,0 +1,45 @@
1
+ [build-system]
2
+ requires = ["setuptools"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "cloudtoolbox"
7
+ version = "0.1.0"
8
+ description = "Toolbox for the cloud."
9
+ readme = {file = "README.md", content-type = "text/markdown"}
10
+ authors = [
11
+ {name = "Dotz Developers", email = "devs-dotz@dotz.com"},
12
+ ]
13
+ keywords = ["cloud", "tools", "utilities", "google", "gcp", "amazon", "aws"]
14
+ classifiers = [
15
+ "Programming Language :: Python :: 3",
16
+ ]
17
+ requires-python = ">=3.8"
18
+ dependencies = []
19
+
20
+ [project.optional-dependencies]
21
+ amazon = ["boto3"]
22
+ google = ["google-cloud-pubsub", "google-cloud-storage"]
23
+
24
+ [tool.ruff]
25
+ exclude = [
26
+ ".git",
27
+ ".venv",
28
+ ".ruff_cache",
29
+ ]
30
+
31
+ line-length = 100
32
+ indent-width = 4
33
+
34
+ [tool.ruff.lint]
35
+ select = ["E", "W", "F", "I", "B", "C4", "UP","ARG001"]
36
+ ignore = ["E402", "E501", "W191", "B904"]
37
+ fixable = ["ALL"]
38
+ unfixable = []
39
+ dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
40
+
41
+ [tool.ruff.format]
42
+ quote-style = "double"
43
+ indent-style = "space"
44
+ skip-magic-trailing-comma = false
45
+ line-ending = "auto"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,57 @@
1
+ import unittest
2
+ from unittest import mock
3
+
4
+ from cloud import factory
5
+ from cloud.amazon import s3
6
+ from cloud.google import pubsub, storage
7
+ from cloud.protocols import MessagePublisher, StorageUploader
8
+
9
+
10
+ class NotStorageUploader:
11
+ def upload_file(self):
12
+ pass
13
+
14
+
15
+ class NotMessagePublisher:
16
+ def send_message(self):
17
+ pass
18
+
19
+
20
+ class TestStorageUploaderFactory(unittest.TestCase):
21
+ @mock.patch("google.cloud.storage.Client")
22
+ def test_google_uploader(self, _):
23
+ Uploader = factory.storage_uploader(storage.Uploader)
24
+ uploader = Uploader()
25
+
26
+ self.assertIsInstance(uploader, StorageUploader)
27
+ self.assertIsInstance(uploader, storage.Uploader)
28
+
29
+ @mock.patch("boto3.client")
30
+ def test_amazon_uploader(self, _):
31
+ Uploader = factory.storage_uploader(s3.Uploader)
32
+ uploader = Uploader()
33
+
34
+ self.assertIsInstance(uploader, StorageUploader)
35
+ self.assertIsInstance(uploader, s3.Uploader)
36
+
37
+ def test_uploader_protocol_validation(self):
38
+ error = "NotStorageUploader does not implement StorageUploader protocol"
39
+
40
+ with self.assertRaisesRegex(AssertionError, error):
41
+ factory.storage_uploader(NotStorageUploader) # type: ignore
42
+
43
+
44
+ class TestMessagePublisherFactory(unittest.TestCase):
45
+ @mock.patch("google.cloud.pubsub_v1.PublisherClient")
46
+ def test_google_publisher(self, _):
47
+ Publisher = factory.message_publisher(pubsub.Publisher)
48
+ publisher = Publisher()
49
+
50
+ self.assertIsInstance(publisher, MessagePublisher)
51
+ self.assertIsInstance(publisher, pubsub.Publisher)
52
+
53
+ def test_publisher_protocol_validation(self):
54
+ error = "NotMessagePublisher does not implement MessagePublisher protocol"
55
+
56
+ with self.assertRaisesRegex(AssertionError, error):
57
+ factory.message_publisher(NotMessagePublisher) # type: ignore