Skip to content

Commit 0dd6699

Browse files
author
Bob Strahan
committed
fix lint errors
1 parent e439883 commit 0dd6699

File tree

4 files changed

+110
-84
lines changed

4 files changed

+110
-84
lines changed

lib/idp_common_pkg/idp_common/docs_service.py

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
AppSync and DynamoDB implementations while maintaining the same interface.
1010
"""
1111

12-
import os
1312
import logging
13+
import os
1414
from typing import Optional, Union
1515

1616
from idp_common.appsync import DocumentAppSyncService
@@ -30,37 +30,36 @@
3030
class DocumentServiceFactory:
3131
"""
3232
Factory class for creating document services based on configuration.
33-
33+
3434
This factory allows switching between AppSync and DynamoDB implementations
3535
while maintaining the same interface for document operations.
3636
"""
37-
37+
3838
@staticmethod
3939
def create_service(
40-
mode: Optional[str] = None,
41-
**kwargs
40+
mode: Optional[str] = None, **kwargs
4241
) -> Union[DocumentAppSyncService, DocumentDynamoDBService]:
4342
"""
4443
Create a document service based on the specified mode.
45-
44+
4645
Args:
4746
mode: Optional mode override. If not provided, uses DOCUMENT_TRACKING_MODE
4847
environment variable, defaulting to 'appsync'
4948
**kwargs: Additional arguments passed to the service constructor
50-
49+
5150
Returns:
5251
DocumentAppSyncService or DocumentDynamoDBService instance
53-
52+
5453
Raises:
5554
ValueError: If an unsupported mode is specified
56-
55+
5756
Examples:
5857
# Use environment variable (default behavior)
5958
service = DocumentServiceFactory.create_service()
60-
59+
6160
# Override mode explicitly
6261
service = DocumentServiceFactory.create_service(mode='dynamodb')
63-
62+
6463
# Pass additional arguments
6564
service = DocumentServiceFactory.create_service(
6665
mode='appsync',
@@ -72,16 +71,16 @@ def create_service(
7271
mode = os.environ.get("DOCUMENT_TRACKING_MODE", DEFAULT_MODE).lower()
7372
else:
7473
mode = mode.lower()
75-
74+
7675
# Validate mode
7776
if mode not in SUPPORTED_MODES:
7877
raise ValueError(
7978
f"Unsupported document tracking mode: '{mode}'. "
8079
f"Supported modes are: {', '.join(SUPPORTED_MODES)}"
8180
)
82-
81+
8382
logger.info(f"Creating document service with mode: {mode}")
84-
83+
8584
# Create the appropriate service
8685
if mode == APPSYNC_MODE:
8786
return DocumentAppSyncService(**kwargs)
@@ -90,32 +89,32 @@ def create_service(
9089
else:
9190
# This should never happen due to validation above, but included for completeness
9291
raise ValueError(f"Unsupported mode: {mode}")
93-
92+
9493
@staticmethod
9594
def get_current_mode() -> str:
9695
"""
9796
Get the current document tracking mode from environment variable.
98-
97+
9998
Returns:
10099
Current mode string ('appsync' or 'dynamodb')
101100
"""
102101
return os.environ.get("DOCUMENT_TRACKING_MODE", DEFAULT_MODE).lower()
103-
102+
104103
@staticmethod
105104
def is_appsync_mode() -> bool:
106105
"""
107106
Check if current mode is AppSync.
108-
107+
109108
Returns:
110109
True if current mode is AppSync, False otherwise
111110
"""
112111
return DocumentServiceFactory.get_current_mode() == APPSYNC_MODE
113-
112+
114113
@staticmethod
115114
def is_dynamodb_mode() -> bool:
116115
"""
117116
Check if current mode is DynamoDB.
118-
117+
119118
Returns:
120119
True if current mode is DynamoDB, False otherwise
121120
"""
@@ -124,29 +123,28 @@ def is_dynamodb_mode() -> bool:
124123

125124
# Convenience function for creating services
126125
def create_document_service(
127-
mode: Optional[str] = None,
128-
**kwargs
126+
mode: Optional[str] = None, **kwargs
129127
) -> Union[DocumentAppSyncService, DocumentDynamoDBService]:
130128
"""
131129
Convenience function to create a document service.
132-
130+
133131
This is a shorthand for DocumentServiceFactory.create_service().
134-
132+
135133
Args:
136134
mode: Optional mode override. If not provided, uses DOCUMENT_TRACKING_MODE
137135
environment variable, defaulting to 'appsync'
138136
**kwargs: Additional arguments passed to the service constructor
139-
137+
140138
Returns:
141139
DocumentAppSyncService or DocumentDynamoDBService instance
142-
140+
143141
Examples:
144142
# Simple usage
145143
service = create_document_service()
146-
144+
147145
# With mode override
148146
service = create_document_service(mode='dynamodb')
149-
147+
150148
# With additional parameters
151149
service = create_document_service(
152150
mode='appsync',

lib/idp_common_pkg/idp_common/dynamodb/client.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from typing import Any, Dict, List, Optional
1111

1212
import boto3
13-
from botocore.exceptions import ClientError, BotoCoreError
13+
from botocore.exceptions import BotoCoreError, ClientError
1414

1515
logger = logging.getLogger(__name__)
1616

@@ -164,7 +164,9 @@ def get_item(self, key: Dict[str, Any]) -> Optional[Dict[str, Any]]:
164164
logger.error(f"BotoCore error during get_item: {str(e)}")
165165
raise DynamoDBError(f"BotoCore error: {str(e)}")
166166

167-
def transact_write_items(self, transact_items: List[Dict[str, Any]]) -> Dict[str, Any]:
167+
def transact_write_items(
168+
self, transact_items: List[Dict[str, Any]]
169+
) -> Dict[str, Any]:
168170
"""
169171
Execute a transaction with multiple write operations.
170172
@@ -193,12 +195,16 @@ def transact_write_items(self, transact_items: List[Dict[str, Any]]) -> Dict[str
193195
response = self.dynamodb.meta.client.transact_write_items(
194196
TransactItems=processed_items
195197
)
196-
logger.debug(f"Successfully executed transaction with {len(transact_items)} items")
198+
logger.debug(
199+
f"Successfully executed transaction with {len(transact_items)} items"
200+
)
197201
return response
198202
except ClientError as e:
199203
error_code = e.response["Error"]["Code"]
200204
error_message = e.response["Error"]["Message"]
201-
logger.error(f"DynamoDB transact_write_items failed: {error_code} - {error_message}")
205+
logger.error(
206+
f"DynamoDB transact_write_items failed: {error_code} - {error_message}"
207+
)
202208
raise DynamoDBError(f"Transaction failed: {error_message}", error_code)
203209
except BotoCoreError as e:
204210
logger.error(f"BotoCore error during transact_write_items: {str(e)}")
@@ -247,7 +253,9 @@ def scan(
247253
scan_params["ExclusiveStartKey"] = exclusive_start_key
248254

249255
response = self.table.scan(**scan_params)
250-
logger.debug(f"Successfully scanned table, returned {len(response.get('Items', []))} items")
256+
logger.debug(
257+
f"Successfully scanned table, returned {len(response.get('Items', []))} items"
258+
)
251259
return response
252260
except ClientError as e:
253261
error_code = e.response["Error"]["Code"]
@@ -300,7 +308,9 @@ def query(
300308
query_params["ExclusiveStartKey"] = exclusive_start_key
301309

302310
response = self.table.query(**query_params)
303-
logger.debug(f"Successfully queried table, returned {len(response.get('Items', []))} items")
311+
logger.debug(
312+
f"Successfully queried table, returned {len(response.get('Items', []))} items"
313+
)
304314
return response
305315
except ClientError as e:
306316
error_code = e.response["Error"]["Code"]

0 commit comments

Comments
 (0)