Skip to content

Commit e6a79b5

Browse files
authored
(fix): Remove kinesis from Category enum and refactor deploy script (#6795)
* refactor: remove Category.kinesis enum, use string categories in deploy script Decouple deploy_gen2.dart from the amplify_core Category enum by changing AmplifyBackendGroup.category to a plain String. This allows removing Category.kinesis from the enum and its dead switch case in AmplifyClassImpl, since the kinesis client is standalone and does not participate in the Amplify plugin registration system. The --category CLI flag now derives allowed values from infraConfig instead of Category.values. * fix: match original Category.api.name casing ('API' not 'Api')
1 parent dfdf7a5 commit e6a79b5

File tree

3 files changed

+28
-40
lines changed

3 files changed

+28
-40
lines changed

infra-gen2/tool/deploy_gen2.dart

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import 'dart:convert';
88
import 'dart:io';
99

10-
import 'package:amplify_core/amplify_core.dart';
10+
import 'package:amplify_core/amplify_core.dart' show UUID;
1111
import 'package:args/args.dart';
1212
import 'package:path/path.dart' as p;
1313

@@ -20,7 +20,7 @@ import 'package:path/path.dart' as p;
2020
/// 4. Run `dart tool/deploy_gen2.dart` to deploy the backend
2121
const List<AmplifyBackendGroup> infraConfig = [
2222
AmplifyBackendGroup(
23-
category: Category.api,
23+
category: 'API',
2424
defaultOutput: 'packages/api/amplify_api/example/lib',
2525
backends: [
2626
AmplifyBackend(
@@ -31,7 +31,7 @@ const List<AmplifyBackendGroup> infraConfig = [
3131
],
3232
),
3333
AmplifyBackendGroup(
34-
category: Category.auth,
34+
category: 'Auth',
3535
defaultOutput: 'packages/auth/amplify_auth_cognito/example/lib',
3636
sharedOutputs: [
3737
'packages/auth/amplify_auth_cognito_dart/example/lib',
@@ -96,7 +96,7 @@ const List<AmplifyBackendGroup> infraConfig = [
9696
],
9797
),
9898
AmplifyBackendGroup(
99-
category: Category.storage,
99+
category: 'Storage',
100100
defaultOutput: 'packages/storage/amplify_storage_s3/example/lib',
101101
backends: [
102102
AmplifyBackend(
@@ -112,7 +112,7 @@ const List<AmplifyBackendGroup> infraConfig = [
112112
],
113113
),
114114
AmplifyBackendGroup(
115-
category: Category.analytics,
115+
category: 'Analytics',
116116
defaultOutput: 'packages/analytics/amplify_analytics_pinpoint/example/lib',
117117
backends: [
118118
AmplifyBackend(
@@ -133,7 +133,7 @@ const List<AmplifyBackendGroup> infraConfig = [
133133
],
134134
),
135135
AmplifyBackendGroup(
136-
category: Category.kinesis,
136+
category: 'Kinesis',
137137
defaultOutput: 'packages/kinesis/amplify_kinesis_dart/lib',
138138
backends: [
139139
AmplifyBackend(
@@ -159,8 +159,7 @@ void main(List<String> arguments) async {
159159

160160
print('🚀 Deploying Gen 2 backends!');
161161
for (final backendGroup in infraConfig) {
162-
if (categoryToDeploy != null &&
163-
backendGroup.category.name != categoryToDeploy) {
162+
if (categoryToDeploy != null && backendGroup.category != categoryToDeploy) {
164163
continue;
165164
}
166165
// TODO(equartey): Could be removed when all backends are defined.
@@ -169,7 +168,7 @@ void main(List<String> arguments) async {
169168
}
170169
var gen2Environments = <String, String>{};
171170
var gen1Environments = <String, String>{};
172-
final categoryName = backendGroup.category.name;
171+
final categoryName = backendGroup.category;
173172
final outputPath = p.join(repoRoot.path, backendGroup.defaultOutput);
174173
final amplifyOutputs = File(p.join(outputPath, 'amplify_outputs.dart'));
175174
final amplifyConfiguration = File(
@@ -267,7 +266,7 @@ ArgResults _parseArgs(List<String> args) {
267266
'category',
268267
abbr: 'c',
269268
help: 'Specify the category to deploy.',
270-
allowed: Category.values.map((e) => e.name).toList(),
269+
allowed: infraConfig.map((e) => e.category).toList(),
271270
defaultsTo: null,
272271
);
273272

@@ -276,14 +275,12 @@ ArgResults _parseArgs(List<String> args) {
276275

277276
/// Deploy Sandbox for a given backend backend
278277
Future<String> _deployBackend(
279-
Category category,
278+
String category,
280279
AmplifyBackend backend,
281280
String outputPath,
282281
bool verbose,
283282
) async {
284-
print(
285-
'🏖️ Deploying ${category.name} ${backend.name}, this may take a while...',
286-
);
283+
print('🏖️ Deploying $category ${backend.name}, this may take a while...');
287284

288285
final outputFile = File(p.join(outputPath, 'amplify_outputs.dart'));
289286
if (outputFile.existsSync()) {
@@ -329,7 +326,6 @@ Future<String> _deployBackend(
329326
in process.stdout
330327
.transform(utf8.decoder)
331328
.transform(const LineSplitter())) {
332-
333329
if (!line.startsWith(' at ') && line.trim().isNotEmpty) {
334330
// This line does not belong to a cdk build error
335331
postingBackendBuildError = false;
@@ -369,22 +365,24 @@ Future<String> _deployBackend(
369365

370366
if (exitCode != 0) {
371367
throw Exception(
372-
'❌ Error deploying ${category.name} ${backend.identifier} sandbox',
368+
'❌ Error deploying $category ${backend.identifier} sandbox',
373369
);
374-
} else if (postedDeploymentError && postedDeploymentErrorReason && postedDeploymentUpdateFailed) {
370+
} else if (postedDeploymentError &&
371+
postedDeploymentErrorReason &&
372+
postedDeploymentUpdateFailed) {
375373
throw Exception(
376-
'❌ Error deploying ${category.name} ${backend.identifier} sandbox: Update failed',
374+
'❌ Error deploying $category ${backend.identifier} sandbox: Update failed',
377375
);
378376
} else if (postedBackendBuildError) {
379377
throw Exception(
380-
'❌ Error deploying ${category.name} ${backend.identifier} sandbox - CDK build failed',
378+
'❌ Error deploying $category ${backend.identifier} sandbox - CDK build failed',
381379
);
382380
} else if (!outputFile.existsSync()) {
383381
throw Exception(
384-
'❌ Error deploying ${category.name} ${backend.identifier} sandbox - Output file not generated',
382+
'❌ Error deploying $category ${backend.identifier} sandbox - Output file not generated',
385383
);
386384
} else {
387-
print('👍 ${category.name} ${backend.identifier} sandbox deployed');
385+
print('👍 $category ${backend.identifier} sandbox deployed');
388386
return stackID;
389387
}
390388
}
@@ -461,7 +459,7 @@ void _copyConfigFile(List<String> outputPaths, List<File> configFiles) {
461459

462460
/// Create a unique bucket name
463461
String _createBucketName(String base) {
464-
final uniqueShort = uuid().substring(0, 8);
462+
final uniqueShort = UUID.getUUID().substring(0, 8);
465463
return '${base.toLowerCase()}-gen2-integ-$uniqueShort';
466464
}
467465

@@ -560,14 +558,12 @@ void _uploadConfigFileToS3(String bucketName, List<File> configFiles) {
560558

561559
/// Generates gen 1 amplifyconfiguration.dart file
562560
void _generateGen1Config(
563-
Category category,
561+
String category,
564562
AmplifyBackend backend,
565563
String outputPath,
566564
String stack,
567565
) {
568-
print(
569-
'📁 Generating gen 1 config file for ${category.name} ${backend.name}...',
570-
);
566+
print('📁 Generating gen 1 config file for $category ${backend.name}...');
571567

572568
final outputFile = File(p.join(outputPath, 'amplifyconfiguration.dart'));
573569
if (outputFile.existsSync()) {
@@ -594,16 +590,14 @@ void _generateGen1Config(
594590

595591
if (process.exitCode != 0) {
596592
throw Exception(
597-
'❌ Error generating gen 1 config file for ${category.name} ${backend.name}:: ${process.stdout}',
593+
'❌ Error generating gen 1 config file for $category ${backend.name}:: ${process.stdout}',
598594
);
599-
} else if(!outputFile.existsSync()) {
595+
} else if (!outputFile.existsSync()) {
600596
throw Exception(
601-
'❌ Error generating gen 1 config file for ${category.name} ${backend.identifier} - Output file not generated',
597+
'❌ Error generating gen 1 config file for $category ${backend.identifier} - Output file not generated',
602598
);
603599
} else {
604-
print(
605-
'👍 Gen 1 config file for ${category.name} ${backend.name} generated',
606-
);
600+
print('👍 Gen 1 config file for $category ${backend.name} generated');
607601
}
608602
}
609603

@@ -616,7 +610,7 @@ class AmplifyBackendGroup {
616610
});
617611

618612
/// This is the category of the integration group
619-
final Category category;
613+
final String category;
620614

621615
/// This is the list of backends for the group
622616
final List<AmplifyBackend> backends;

packages/amplify_core/lib/src/amplify_class_impl.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ class AmplifyClassImpl extends AmplifyClass {
4646
plugin.cast(),
4747
authProviderRepo: authProviderRepo,
4848
);
49-
case Category.kinesis:
50-
throw UnimplementedError();
5149
}
5250
}
5351
}

packages/amplify_core/lib/src/category/amplify_categories.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@ enum Category {
5050
storage,
5151

5252
/// Push Notifications
53-
pushNotifications,
54-
55-
/// Kinesis streaming (Data Streams + Firehose)
56-
kinesis;
53+
pushNotifications;
5754

5855
String get name => switch (this) {
5956
Category.analytics => 'Analytics',
@@ -63,7 +60,6 @@ enum Category {
6360
Category.hub => 'Hub',
6461
Category.storage => 'Storage',
6562
Category.pushNotifications => 'PushNotifications',
66-
Category.kinesis => 'Kinesis',
6763
};
6864
}
6965

0 commit comments

Comments
 (0)