11from __future__ import annotations
22
3- from .parser_utils import (
4- MigrationParseError ,
5- is_blank ,
6- parse_directive_line ,
7- parse_quoted_value ,
8- read_directive_block ,
9- split_lines ,
10- )
3+ from .parser_utils import MigrationParseError , is_blank , parse_directive_line , parse_quoted_value , read_directive_block , split_lines
114from .types import (
125 ConnectionModel ,
6+ DynamoDBConnectionModel ,
137 GCSConnectionModel ,
148 KafkaConnectionModel ,
159 ResourceFile ,
3024 "S3_ACCESS_KEY" ,
3125 "S3_SECRET" ,
3226 "GCS_SERVICE_ACCOUNT_CREDENTIALS_JSON" ,
27+ "DYNAMODB_ARN" ,
28+ "DYNAMODB_REGION" ,
3329}
3430
3531
@@ -58,6 +54,9 @@ def parse_connection_file(resource: ResourceFile) -> ConnectionModel:
5854 access_secret : str | None = None
5955 service_account_credentials_json : str | None = None
6056
57+ dynamodb_arn : str | None = None
58+ dynamodb_region : str | None = None
59+
6160 i = 0
6261 while i < len (lines ):
6362 raw_line = lines [i ]
@@ -119,6 +118,10 @@ def parse_connection_file(resource: ResourceFile) -> ConnectionModel:
119118 access_secret = parse_quoted_value (value )
120119 elif name == "GCS_SERVICE_ACCOUNT_CREDENTIALS_JSON" :
121120 service_account_credentials_json = parse_quoted_value (value )
121+ elif name == "DYNAMODB_ARN" :
122+ dynamodb_arn = parse_quoted_value (value )
123+ elif name == "DYNAMODB_REGION" :
124+ dynamodb_region = parse_quoted_value (value )
122125 else :
123126 raise MigrationParseError (
124127 resource .file_path ,
@@ -135,12 +138,20 @@ def parse_connection_file(resource: ResourceFile) -> ConnectionModel:
135138 )
136139
137140 if connection_type == "kafka" :
138- if region or arn or access_key or access_secret or service_account_credentials_json :
141+ if (
142+ region
143+ or arn
144+ or access_key
145+ or access_secret
146+ or service_account_credentials_json
147+ or dynamodb_arn
148+ or dynamodb_region
149+ ):
139150 raise MigrationParseError (
140151 resource .file_path ,
141152 "connection" ,
142153 resource .name ,
143- "S3/GCS directives are not valid for kafka connections." ,
154+ "S3/GCS/DynamoDB directives are not valid for kafka connections." ,
144155 )
145156
146157 if not bootstrap_servers :
@@ -175,12 +186,14 @@ def parse_connection_file(resource: ResourceFile) -> ConnectionModel:
175186 or schema_registry_url
176187 or ssl_ca_pem
177188 or service_account_credentials_json
189+ or dynamodb_arn
190+ or dynamodb_region
178191 ):
179192 raise MigrationParseError (
180193 resource .file_path ,
181194 "connection" ,
182195 resource .name ,
183- "Kafka/GCS directives are not valid for s3 connections." ,
196+ "Kafka/GCS/DynamoDB directives are not valid for s3 connections." ,
184197 )
185198
186199 if not region :
@@ -231,12 +244,14 @@ def parse_connection_file(resource: ResourceFile) -> ConnectionModel:
231244 or arn
232245 or access_key
233246 or access_secret
247+ or dynamodb_arn
248+ or dynamodb_region
234249 ):
235250 raise MigrationParseError (
236251 resource .file_path ,
237252 "connection" ,
238253 resource .name ,
239- "Kafka/S3 directives are not valid for gcs connections." ,
254+ "Kafka/S3/DynamoDB directives are not valid for gcs connections." ,
240255 )
241256
242257 if not service_account_credentials_json :
@@ -255,6 +270,53 @@ def parse_connection_file(resource: ResourceFile) -> ConnectionModel:
255270 service_account_credentials_json = service_account_credentials_json ,
256271 )
257272
273+ if connection_type == "dynamodb" :
274+ if (
275+ bootstrap_servers
276+ or security_protocol
277+ or sasl_mechanism
278+ or key
279+ or secret
280+ or schema_registry_url
281+ or ssl_ca_pem
282+ or region
283+ or arn
284+ or access_key
285+ or access_secret
286+ or service_account_credentials_json
287+ ):
288+ raise MigrationParseError (
289+ resource .file_path ,
290+ "connection" ,
291+ resource .name ,
292+ "Kafka/S3/GCS directives are not valid for dynamodb connections." ,
293+ )
294+
295+ if not dynamodb_arn :
296+ raise MigrationParseError (
297+ resource .file_path ,
298+ "connection" ,
299+ resource .name ,
300+ "DYNAMODB_ARN is required for dynamodb connections." ,
301+ )
302+
303+ if not dynamodb_region :
304+ raise MigrationParseError (
305+ resource .file_path ,
306+ "connection" ,
307+ resource .name ,
308+ "DYNAMODB_REGION is required for dynamodb connections." ,
309+ )
310+
311+ return DynamoDBConnectionModel (
312+ kind = "connection" ,
313+ name = resource .name ,
314+ file_path = resource .file_path ,
315+ connection_type = "dynamodb" ,
316+ region = dynamodb_region ,
317+ arn = dynamodb_arn ,
318+ )
319+
258320 raise MigrationParseError (
259321 resource .file_path ,
260322 "connection" ,
0 commit comments