Skip to content

Commit f50c00c

Browse files
committed
Clean references to boto2
1 parent 9abd620 commit f50c00c

File tree

12 files changed

+7
-125
lines changed

12 files changed

+7
-125
lines changed

simpleflow/swf/mapper/actors/core.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
from simpleflow.swf.mapper.core import ConnectedSWFObject
66
from simpleflow.swf.mapper.models.domain import Domain
77

8-
if TYPE_CHECKING:
9-
from boto.exception import SWFResponseError
10-
118

129
class Actor(ConnectedSWFObject):
1310
"""SWF Actor base class.
@@ -50,11 +47,3 @@ def stop(self):
5047
shutting down.
5148
"""
5249
raise NotImplementedError
53-
54-
def get_error_message(self, e: SWFResponseError) -> str:
55-
message = e.error_message
56-
if not message:
57-
if e.body:
58-
# Expected 'message', got 'Message' ¯\_(ツ)_/¯
59-
message = e.body.get("Message")
60-
return message

simpleflow/swf/mapper/actors/decider.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from typing import TYPE_CHECKING, Any
44

5-
import boto.exception
65
from botocore.exceptions import ClientError
76

87
from simpleflow import format, logging_context

simpleflow/swf/mapper/actors/worker.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from typing import TYPE_CHECKING, Any
44

5-
import boto.exception
65
from botocore.exceptions import ClientError
76

87
from simpleflow import format, logging_context

simpleflow/swf/mapper/core.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
import os
99
from typing import Any
1010

11-
import boto.swf # noqa
1211
import boto3
13-
from boto.exception import NoAuthHandlerFound
12+
from botocore.exceptions import NoCredentialsError
1413

1514
# NB: import logger directly from simpleflow so we benefit from the logging
1615
# config hosted in simpleflow. This wouldn't be the case with a standard
@@ -23,6 +22,7 @@
2322

2423
SETTINGS = settings.get()
2524
RETRIES = int(os.environ.get("SWF_CONNECTION_RETRIES", "5"))
25+
DEFAULT_AWS_REGION = "us-east-1"
2626

2727

2828
class ConnectedSWFObject:
@@ -31,26 +31,21 @@ class ConnectedSWFObject:
3131
__slots__ = ["region", "connection", "boto3_client"]
3232

3333
region: str
34-
connection: boto.swf.layer1.Layer1
3534
boto3_client: boto3.client
3635

3736
@retry.with_delay(
3837
nb_times=RETRIES,
3938
delay=retry.exponential,
40-
on_exceptions=(TypeError, NoAuthHandlerFound),
39+
on_exceptions=(TypeError, NoCredentialsError),
4140
)
4241
def __init__(self, *args, **kwargs):
43-
self.region = SETTINGS.get("region") or kwargs.get("region") or boto.swf.layer1.Layer1.DefaultRegionName
42+
self.region = SETTINGS.get("region") or kwargs.get("region") or DEFAULT_AWS_REGION
4443
# Use settings-provided keys if available, otherwise pass empty
4544
# dictionary to boto SWF client, which will use its default credentials
4645
# chain provider.
4746
cred_keys = ["aws_access_key_id", "aws_secret_access_key"]
4847
creds_ = {k: SETTINGS[k] for k in cred_keys if SETTINGS.get(k, None)}
4948

50-
self.connection = kwargs.pop("connection", None) or boto.swf.connect_to_region(self.region, **creds_)
51-
if self.connection is None:
52-
raise ValueError(f"invalid region: {self.region}")
53-
5449
self.boto3_client = kwargs.pop("boto3_client", None)
5550
if not self.boto3_client:
5651
session = boto3.session.Session(region_name=self.region)

simpleflow/swf/mapper/exceptions.py

Lines changed: 1 addition & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from functools import partial, wraps
66
from typing import Any, Callable
77

8-
import boto.exception
98
from botocore.exceptions import ClientError
109

1110

@@ -140,17 +139,6 @@ def match_equals(regex, string, values):
140139
return matched[0] in values
141140

142141

143-
def is_swf_response_error(error):
144-
"""
145-
Return true if *error* is a :class:`SWFResponseError` exception.
146-
147-
:param error: is the exception to check.
148-
:type error: Exception.
149-
150-
"""
151-
return isinstance(error, boto.exception.SWFResponseError)
152-
153-
154142
def is_unknown_resource_raised(error, *args, **kwargs):
155143
"""
156144
Handler that checks if *error* is an unknown resource fault.
@@ -159,7 +147,7 @@ def is_unknown_resource_raised(error, *args, **kwargs):
159147
:type error: Exception
160148
161149
"""
162-
if not isinstance(error, (boto.exception.SWFResponseError, ClientError)):
150+
if not isinstance(error, ClientError):
163151
return False
164152

165153
return extract_error_code(error) == "UnknownResourceFault"
@@ -241,77 +229,6 @@ def raises(exception, when, extract: Callable[[Any], str] = str):
241229
242230
:param when: predicate to apply.
243231
:type when: (error, *args, **kwargs) -> bool
244-
245-
Examples
246-
--------
247-
248-
Let's build a :class:`boto.swf.exceptions.SWFResponseError` for an unknown
249-
execution:
250-
251-
FIXME commented-out these doctests for now as they fail on python3
252-
(returning simpleflow.swf.mapper.exceptions.DoesNotExistError and such, not just DoesNotExistError)
253-
# >>> status = 400
254-
# >>> reason = 'Bad Request'
255-
# >>> body_type = 'com.amazonaws.swf.base.model#UnknownResourceFault'
256-
# >>> body_message = 'Unknown execution: blah'
257-
# >>> body = {'__type': body_type, 'message': body_message}
258-
# >>> error_code = 'UnknownResourceFault'
259-
# >>> from boto.swf.exceptions import SWFResponseError
260-
# >>> err = SWFResponseError(status, reason, body, error_code)
261-
# >>> raises(DoesNotExistError,
262-
# ... when=is_unknown_resource_raised,
263-
# ... extract=extract_resource)(err)
264-
# Traceback (most recent call last):
265-
# ...
266-
# DoesNotExistError: Resource execution does not exist
267-
#
268-
# >>> body = {'__type': body_type}
269-
# >>> err = SWFResponseError(status, reason, body, error_code)
270-
# >>> raises(DoesNotExistError,
271-
# ... when=is_unknown_resource_raised,
272-
# ... extract=extract_resource)(err)
273-
# Traceback (most recent call last):
274-
# ...
275-
# DoesNotExistError: Resource unknown does not exist
276-
#
277-
# Now, we do the same for an unknown domain:
278-
#
279-
# >>> body_message = 'Unknown domain'
280-
# >>> body = {'__type': body_type, 'message': body_message}
281-
# >>> err = SWFResponseError(status, reason, body, error_code)
282-
# >>> raises(DoesNotExistError,
283-
# ... when=is_unknown_resource_raised,
284-
# ... extract=extract_resource)(err)
285-
# Traceback (most recent call last):
286-
# ...
287-
# DoesNotExistError: Resource domain does not exist
288-
#
289-
# If it does not detect an error related to an unknown resource,
290-
# it raises a :class:`ResponseError`:
291-
#
292-
# >>> body_message = 'Other Fault'
293-
# >>> body = {'__type': body_type, 'message': body_message}
294-
# >>> err = SWFResponseError(status, reason, body, error_code)
295-
# >>> err.error_code = 'OtherFault'
296-
# >>> raises(DoesNotExistError,
297-
# ... when=is_unknown_resource_raised,
298-
# ... extract=extract_resource)(err)
299-
# ... # doctest: +IGNORE_EXCEPTION_DETAIL
300-
# Traceback (most recent call last):
301-
# ...
302-
# SWFResponseError: SWFResponseError: 400 Bad Request
303-
# {'message': 'Other Fault', '__type': 'com.amazonaws.swf.base.model#UnknownResourceFault'}
304-
#
305-
# If it's not a :class:`boto.swf.exceptions.SWFResponseError`, it
306-
# raises the exception as-is:
307-
#
308-
# >>> raises(DoesNotExistError,
309-
# ... when=is_unknown_resource_raised,
310-
# ... extract=extract_resource)(Exception('boom!'))
311-
# Traceback (most recent call last):
312-
# ...
313-
# Exception: boom!
314-
315232
"""
316233

317234
@wraps(raises)

simpleflow/swf/mapper/models/activity.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
from typing import TYPE_CHECKING, Any, List
99

10-
from boto.swf.exceptions import SWFResponseError, SWFTypeAlreadyExistsError # noqa
1110
from botocore.exceptions import ClientError
1211

1312
from simpleflow.swf.mapper import exceptions

simpleflow/swf/mapper/querysets/domain.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ def get(self, name: str, *args, **kwargs) -> Domain:
5555
domain_info["name"],
5656
status=domain_info["status"],
5757
retention_period=domain_config["workflowExecutionRetentionPeriodInDays"],
58-
connection=self.connection,
5958
)
6059

6160
def get_or_create(

simpleflow/swf/mapper/querysets/workflow.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
from typing import Any
99

10-
from boto.swf.exceptions import SWFResponseError # noqa
1110
from botocore.exceptions import ClientError
1211

1312
from simpleflow.swf.mapper.constants import MAX_WORKFLOW_AGE, REGISTERED

tests/data/constants.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
from __future__ import annotations
22

3-
from unittest.mock import patch
3+
from simpleflow.swf.mapper.models import Domain
44

5-
import simpleflow.swf.mapper.models
6-
7-
with patch("boto.swf.connect_to_region"):
8-
DOMAIN = simpleflow.swf.mapper.models.Domain("TestDomain")
5+
DOMAIN = Domain("TestDomain")
96
DEFAULT_VERSION = "test"

tests/integration/__init__.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import os
55
from typing import TYPE_CHECKING
66

7-
import boto.swf # noqa
87
import boto3
98
from click.testing import CliRunner
109
from sure import expect
@@ -62,12 +61,6 @@ def domain(self):
6261
def workflow_id(self):
6362
return WORKFLOW_ID
6463

65-
@property
66-
def conn(self):
67-
if not hasattr(self, "_conn"):
68-
self._conn = boto.swf.connect_to_region(self.region)
69-
return self._conn
70-
7164
@property
7265
def boto3_client(self):
7366
if not hasattr(self, "_boto3_client"):

0 commit comments

Comments
 (0)