awsimple 4.2.0__py3-none-any.whl → 5.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.

Potentially problematic release.


This version of awsimple might be problematic. Click here for more details.

awsimple/__version__.py CHANGED
@@ -1,7 +1,7 @@
1
1
  __application_name__ = "awsimple"
2
2
  __title__ = __application_name__
3
3
  __author__ = "abel"
4
- __version__ = "4.2.0"
4
+ __version__ = "5.0.0"
5
5
  __author_email__ = "j@abel.co"
6
6
  __url__ = "https://github.com/jamesabel/awsimple"
7
7
  __download_url__ = "https://github.com/jamesabel/awsimple"
awsimple/pubsub.py CHANGED
@@ -14,6 +14,7 @@ import json
14
14
 
15
15
  from typeguard import typechecked
16
16
  from botocore.exceptions import ClientError
17
+ import strif
17
18
 
18
19
  from .sns import SNSAccess
19
20
  from .sqs import SQSPollAccess, get_all_sqs_queues
@@ -121,17 +122,17 @@ class _SubscriptionThread(Thread):
121
122
 
122
123
 
123
124
  @lru_cache
124
- def make_name_aws_safe(name: str) -> str:
125
+ def make_name_aws_safe(*args: str) -> str:
125
126
  """
126
- Make a name safe for an SQS queue to subscribe to an SNS topic.
127
+ Make a name safe for an SQS queue to subscribe to an SNS topic. AWS has a bunch of undocumented restrictions on names, so we just hash the name to a base36 string.
127
128
 
128
- :param name: input name
129
+ :params: input name(s)
129
130
  :return: AWS safe name
130
131
  """
131
- safe_name = "".join([c for c in name.strip().lower() if c.isalnum()]) # only allow alphanumeric characters
132
- if len(safe_name) < 1:
133
- raise ValueError(f'"{name}" is not valid after making AWS safe - result must contain at least one alphanumeric character.')
134
- return safe_name
132
+
133
+ base36 = strif.hash_string("".join(args)).base36
134
+ assert len(base36) == 31
135
+ return base36
135
136
 
136
137
 
137
138
  class PubSub(Process):
@@ -155,9 +156,10 @@ class PubSub(Process):
155
156
  :param node_name: Node name (SQS queue name suffix). Defaults to a combination of computer name and username, but can be passed in for customization and/or testing.
156
157
  :param sub_callback: Optional thread and process safe callback function to be called when a new message is received. The function should accept a single argument, which will be the message as a dictionary.
157
158
  """
158
-
159
- self.channel = "ps" + make_name_aws_safe(channel) # prefix with ps (pubsub) to avoid collisions with other uses of SNS topics and SQS queues
160
- self.node_name = make_name_aws_safe(node_name)
159
+ self.aws_resource_prefix = "ps" # for pubsub
160
+ self.channel = self.aws_resource_prefix + make_name_aws_safe(channel) # prefix with ps (pubsub) to avoid collisions with other uses of SNS topics and SQS queues
161
+ self.node_name = node_name
162
+ self.sqs_queue_name = self.aws_resource_prefix + make_name_aws_safe(self.channel, self.node_name)
161
163
  self.sub_callback = sub_callback
162
164
 
163
165
  self.profile_name = profile_name
@@ -174,8 +176,6 @@ class PubSub(Process):
174
176
 
175
177
  def run(self):
176
178
 
177
- sqs_queue_name = f"{self.channel}{self.node_name}"
178
-
179
179
  sns = SNSAccess(
180
180
  self.channel,
181
181
  auto_create=True,
@@ -185,11 +185,16 @@ class PubSub(Process):
185
185
  region_name=self.region_name,
186
186
  )
187
187
  sqs_metadata = _DynamoDBMetadataTable(
188
- sqs_name, sqs_queue_name, profile_name=self.profile_name, aws_access_key_id=self.aws_access_key_id, aws_secret_access_key=self.aws_secret_access_key, region_name=self.region_name
188
+ sqs_name,
189
+ self.sqs_queue_name,
190
+ profile_name=self.profile_name,
191
+ aws_access_key_id=self.aws_access_key_id,
192
+ aws_secret_access_key=self.aws_secret_access_key,
193
+ region_name=self.region_name,
189
194
  )
190
195
 
191
196
  sqs = SQSPollAccess(
192
- sqs_queue_name, profile_name=self.profile_name, aws_access_key_id=self.aws_access_key_id, aws_secret_access_key=self.aws_secret_access_key, region_name=self.region_name
197
+ self.sqs_queue_name, profile_name=self.profile_name, aws_access_key_id=self.aws_access_key_id, aws_secret_access_key=self.aws_secret_access_key, region_name=self.region_name
193
198
  )
194
199
  if not sqs.exists():
195
200
  sqs.create_queue()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: awsimple
3
- Version: 4.2.0
3
+ Version: 5.0.0
4
4
  Summary: Simple AWS API for S3, DynamoDB, SNS, and SQS
5
5
  Home-page: https://github.com/jamesabel/awsimple
6
6
  Download-URL: https://github.com/jamesabel/awsimple
@@ -22,6 +22,7 @@ Requires-Dist: tobool
22
22
  Requires-Dist: urllib3
23
23
  Requires-Dist: python-dateutil
24
24
  Requires-Dist: yasf
25
+ Requires-Dist: strif
25
26
  Dynamic: author
26
27
  Dynamic: author-email
27
28
  Dynamic: description
@@ -1,5 +1,5 @@
1
1
  awsimple/__init__.py,sha256=RT9hATlcKnnvJYnSh7tCWEeeT2LyleL_vT1Zdz0nSkM,1051
2
- awsimple/__version__.py,sha256=fij2OF6RPCHAUREavC9bv6YK4lD3nxXPz58k91OHyT4,323
2
+ awsimple/__version__.py,sha256=xCHPAAnvsCqjRKpsIAQOEFC8V53loQAyz0sN0R7SAo0,323
3
3
  awsimple/aws.py,sha256=NbRu1v_J5j2-pcefNZ5Xggii3mM9nHpeHMz9L9K9r-U,7653
4
4
  awsimple/cache.py,sha256=_LvPx76215t8KhAJOin6Pe2b4lWpB6kbKpdzgR4FeA4,7206
5
5
  awsimple/dynamodb.py,sha256=7MNxAutOCMTS4JSX-DLOwzaImJ2TzIc7kfQzQPAy5y8,41193
@@ -8,14 +8,14 @@ awsimple/exceptions.py,sha256=Ew-S8YkHVWrZFI_Yik5n0cJ7Ss4Kig5JsEPQ-9z18SU,922
8
8
  awsimple/logs.py,sha256=s9FhdDFWjfxGCVDx-FNTPgJ-YN1AOAgz4HNxTVfRARE,4108
9
9
  awsimple/mock.py,sha256=eScbnxFF9xAosOAsL-NZgp_P-fezB6StQMkb85Y3TNo,574
10
10
  awsimple/platform.py,sha256=TObvLIVgRGh-Mh4ZCxFfxAmrn8KNMHktr6XkDZX8JYE,376
11
- awsimple/pubsub.py,sha256=Pw5foOHtpd-tAWMRlnSYuRpa4c-fi1tMZfesizn9UDc,10143
11
+ awsimple/pubsub.py,sha256=Fxo3i4zo3GfBVhmGMGI4CQsRQ18x4Pp_bjpxSL-9xJY,10240
12
12
  awsimple/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
13
  awsimple/s3.py,sha256=OhWF1uv4oLmBF5jAhKIi918iUQxx4CX8bTEvQ5wLYr8,24050
14
14
  awsimple/sns.py,sha256=T_FyN8eSmBPo213HOfB3UBlMrvtBK768IaRo_ks-7do,3526
15
15
  awsimple/sqs.py,sha256=9ZY7161CpmYpcxlCFIfW8bvMn9SGl4cgGR79I4MFLDk,17281
16
- awsimple-4.2.0.dist-info/licenses/LICENSE,sha256=d956YAgtDaxgxQmccyUk__EfhORZyBjvmJ8pq6zYTxk,1093
17
- awsimple-4.2.0.dist-info/licenses/LICENSE.txt,sha256=d956YAgtDaxgxQmccyUk__EfhORZyBjvmJ8pq6zYTxk,1093
18
- awsimple-4.2.0.dist-info/METADATA,sha256=TRNowXIo5ZYVRxy37xcGZ4o4UyIikkS1_JcjrqHGnBg,6638
19
- awsimple-4.2.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
20
- awsimple-4.2.0.dist-info/top_level.txt,sha256=mwqCoH_8vAaK6iYioiRbasXmVCQM7AK3grNWOKp2VHE,9
21
- awsimple-4.2.0.dist-info/RECORD,,
16
+ awsimple-5.0.0.dist-info/licenses/LICENSE,sha256=d956YAgtDaxgxQmccyUk__EfhORZyBjvmJ8pq6zYTxk,1093
17
+ awsimple-5.0.0.dist-info/licenses/LICENSE.txt,sha256=d956YAgtDaxgxQmccyUk__EfhORZyBjvmJ8pq6zYTxk,1093
18
+ awsimple-5.0.0.dist-info/METADATA,sha256=98gj_2M_A4xwO4-y5c8LLsRML1pfnoKeqE2-LCyEvMU,6660
19
+ awsimple-5.0.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
20
+ awsimple-5.0.0.dist-info/top_level.txt,sha256=mwqCoH_8vAaK6iYioiRbasXmVCQM7AK3grNWOKp2VHE,9
21
+ awsimple-5.0.0.dist-info/RECORD,,