-
Notifications
You must be signed in to change notification settings - Fork 249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(aft): Use public models #3727
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,6 @@ import 'package:async/async.dart'; | |
import 'package:aws_common/aws_common.dart'; | ||
import 'package:checked_yaml/checked_yaml.dart'; | ||
import 'package:code_builder/code_builder.dart'; | ||
import 'package:collection/collection.dart'; | ||
import 'package:git/git.dart'; | ||
import 'package:path/path.dart' as p; | ||
import 'package:pubspec_parse/pubspec_parse.dart'; | ||
|
@@ -26,7 +25,7 @@ class GenerateSdkCommand extends AmplifyCommand with GlobOptions { | |
..addOption( | ||
'models', | ||
abbr: 'm', | ||
help: 'The path to the AWS SDK models', | ||
help: 'The path to the AWS JS V3 repo', | ||
) | ||
..addOption( | ||
'output', | ||
|
@@ -75,7 +74,9 @@ class GenerateSdkCommand extends AmplifyCommand with GlobOptions { | |
await runGit( | ||
[ | ||
'clone', | ||
'https://github.com/aws/aws-models.git', | ||
// https://github.blog/2020-12-21-get-up-to-speed-with-partial-clone-and-shallow-clone/ | ||
'--filter=tree:0', | ||
'https://github.com/aws/aws-sdk-js-v3.git', | ||
cloneDir.path, | ||
], | ||
echoOutput: verbose, | ||
|
@@ -102,30 +103,6 @@ class GenerateSdkCommand extends AmplifyCommand with GlobOptions { | |
return worktreeDir; | ||
} | ||
|
||
/// Organizes model files from [baseDir] into a new temporary directory. | ||
/// | ||
/// Returns the new directory. | ||
Future<Directory> _organizeModels(Directory baseDir) async { | ||
final modelsDir = await Directory.systemTemp.createTemp('models'); | ||
logger.debug('Organizing models in ${modelsDir.path}'); | ||
final services = baseDir.list(followLinks: false).whereType<Directory>(); | ||
await for (final serviceDir in services) { | ||
final serviceName = p.basename(serviceDir.path); | ||
final artifacts = await serviceDir.list().whereType<Directory>().toList(); | ||
final smithyDir = artifacts.firstWhereOrNull( | ||
(dir) => p.basename(dir.path) == 'smithy', | ||
); | ||
if (smithyDir == null) { | ||
continue; | ||
} | ||
final smithyModel = File(p.join(smithyDir.path, 'model.json')); | ||
final copyToPath = p.join(modelsDir.path, '$serviceName.json'); | ||
logger.verbose('Copying $serviceName.json to $copyToPath'); | ||
await smithyModel.copy(copyToPath); | ||
} | ||
return modelsDir; | ||
} | ||
|
||
Future<Directory> _modelsDirForRef(String ref) async { | ||
if (_modelsCache[ref] case final cachedDir?) { | ||
return cachedDir; | ||
|
@@ -137,19 +114,20 @@ class GenerateSdkCommand extends AmplifyCommand with GlobOptions { | |
exitError('Model directory ($modelsDir) does not exist'); | ||
} | ||
// Checkout models if modelsPath is a git repository. | ||
if (File(p.join(modelsPath, '.git')).existsSync()) { | ||
if (Directory(p.join(modelsPath, '.git')).existsSync()) { | ||
modelsDir = await _checkoutModelsRef(modelsDir, ref); | ||
} else { | ||
logger.warn( | ||
'Unable to check out $ref since $modelsDir is not a git repo', | ||
); | ||
} | ||
modelsDir = await _organizeModels(modelsDir); | ||
} else { | ||
modelsDir = await _downloadModels(); | ||
modelsDir = await _checkoutModelsRef(modelsDir, ref); | ||
modelsDir = await _organizeModels(modelsDir); | ||
} | ||
modelsDir = Directory.fromUri( | ||
modelsDir.uri.resolve('codegen/sdk-codegen/aws-models'), | ||
); | ||
return _modelsCache[ref] = modelsDir; | ||
} | ||
|
||
|
@@ -180,13 +158,13 @@ class GenerateSdkCommand extends AmplifyCommand with GlobOptions { | |
final modelsDir = await _modelsDirForRef(config.ref); | ||
final models = modelsDir.list().whereType<File>(); | ||
await for (final model in models) { | ||
final serviceName = p.basenameWithoutExtension(model.path); | ||
if (!config.apis.keys.contains(serviceName)) { | ||
continue; | ||
} | ||
final astJson = await model.readAsString(); | ||
final ast = parseAstJson(astJson); | ||
|
||
final serviceNamespace = | ||
ast.shapes.values.whereType<ServiceShape>().single.shapeId.namespace; | ||
if (!config.apis.containsKey(serviceNamespace)) { | ||
continue; | ||
} | ||
smithyModel.shapes!.addAll(ast.shapes); | ||
} | ||
|
||
|
@@ -201,21 +179,26 @@ class GenerateSdkCommand extends AmplifyCommand with GlobOptions { | |
} | ||
|
||
final includeShapes = <ShapeId>[]; | ||
for (final shapeIdEntries in config.apis.entries) { | ||
final shapeIds = shapeIdEntries.value; | ||
if (shapeIds != null && shapeIds.isNotEmpty) { | ||
includeShapes.addAll(shapeIds); | ||
continue; | ||
} | ||
|
||
final apiName = shapeIdEntries.key; | ||
for (final MapEntry(key: namespace, value: operations) | ||
in config.apis.entries) { | ||
final serviceShape = smithyModel.shapes!.values | ||
.whereType<ServiceShape>() | ||
.singleWhere( | ||
(service) => | ||
service.expectTrait<ServiceTrait>().endpointPrefix == apiName, | ||
.singleWhere((service) => service.shapeId.namespace == namespace); | ||
final allOperations = serviceShape.operations.map((op) => op.target); | ||
final includeOperations = switch (operations) { | ||
List<String> _ when operations.isNotEmpty => operations.map( | ||
(op) => ShapeId(namespace: namespace, shape: op), | ||
), | ||
_ => allOperations, | ||
}; | ||
for (final operation in includeOperations) { | ||
if (!allOperations.contains(operation)) { | ||
throw Exception( | ||
'Invalid operation specified for $namespace: $operation', | ||
); | ||
includeShapes.addAll(serviceShape.operations.map((op) => op.target)); | ||
} | ||
} | ||
includeShapes.addAll(includeOperations); | ||
Comment on lines
+194
to
+201
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could flatten this logic a little bit. final isMissingOp = includeOperations.every((e) => !allOperations.contains(operation));
if (isMissingOp) {
throw Exception(
'Invalid operation specified for $namespace: $operation',
);
}
includeShapes.addAll(includeOperations); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, started with something like that. This turned out to be cleaner - the problem is getting the element which didn't pass the condition, i.e. |
||
} | ||
|
||
// Generate SDK for combined operations | ||
|
@@ -326,7 +309,7 @@ class GenerateSdkCommand extends AmplifyCommand with GlobOptions { | |
), | ||
]); | ||
|
||
final modelsDir = await _modelsDirForRef('master'); | ||
final modelsDir = await _modelsDirForRef('main'); | ||
final models = modelsDir.list().whereType<File>(); | ||
final services = <Field>[]; | ||
await for (final model in models) { | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,7 @@ | ||
apis: | ||
pinpoint: | ||
- com.amazonaws.pinpoint#GetEndpoint | ||
- com.amazonaws.pinpoint#GetInAppMessages | ||
- com.amazonaws.pinpoint#PutEvents | ||
- com.amazonaws.pinpoint#UpdateEndpoint | ||
- com.amazonaws.pinpoint#UpdateEndpointsBatch | ||
- com.amazonaws.pinpoint#GetUserProfile | ||
- com.amazonaws.pinpoint#UpdateUserProfile | ||
- com.amazonaws.pinpoint#DeleteUserProfile | ||
- com.amazonaws.pinpoint#GetUserProfilesBatch | ||
- com.amazonaws.pinpoint#UpdateUserProfilesBatch | ||
- com.amazonaws.pinpoint#PutUserEvents | ||
# patches: | ||
# - tool/patch/user-models.patch | ||
com.amazonaws.pinpoint: | ||
- GetEndpoint | ||
- GetInAppMessages | ||
- PutEvents | ||
- UpdateEndpoint | ||
- UpdateEndpointsBatch |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
apis: | ||
cognito-idp: | ||
- com.amazonaws.cognitoidentityprovider#AssociateSoftwareToken | ||
- com.amazonaws.cognitoidentityprovider#ChangePassword | ||
- com.amazonaws.cognitoidentityprovider#ConfirmDevice | ||
- com.amazonaws.cognitoidentityprovider#ConfirmForgotPassword | ||
- com.amazonaws.cognitoidentityprovider#ConfirmSignUp | ||
- com.amazonaws.cognitoidentityprovider#DeleteUser | ||
- com.amazonaws.cognitoidentityprovider#ForgetDevice | ||
- com.amazonaws.cognitoidentityprovider#ForgotPassword | ||
- com.amazonaws.cognitoidentityprovider#GetDevice | ||
- com.amazonaws.cognitoidentityprovider#GetUser | ||
- com.amazonaws.cognitoidentityprovider#GetUserAttributeVerificationCode | ||
- com.amazonaws.cognitoidentityprovider#GlobalSignOut | ||
- com.amazonaws.cognitoidentityprovider#InitiateAuth | ||
- com.amazonaws.cognitoidentityprovider#ListDevices | ||
- com.amazonaws.cognitoidentityprovider#ResendConfirmationCode | ||
- com.amazonaws.cognitoidentityprovider#RespondToAuthChallenge | ||
- com.amazonaws.cognitoidentityprovider#RevokeToken | ||
- com.amazonaws.cognitoidentityprovider#SetUserMFAPreference | ||
- com.amazonaws.cognitoidentityprovider#SignUp | ||
- com.amazonaws.cognitoidentityprovider#UpdateDeviceStatus | ||
- com.amazonaws.cognitoidentityprovider#UpdateUserAttributes | ||
- com.amazonaws.cognitoidentityprovider#VerifySoftwareToken | ||
- com.amazonaws.cognitoidentityprovider#VerifyUserAttribute | ||
cognito-identity: | ||
- com.amazonaws.cognitoidentity#GetCredentialsForIdentity | ||
- com.amazonaws.cognitoidentity#GetId | ||
com.amazonaws.cognitoidentityprovider: | ||
- AssociateSoftwareToken | ||
- ChangePassword | ||
- ConfirmDevice | ||
- ConfirmForgotPassword | ||
- ConfirmSignUp | ||
- DeleteUser | ||
- ForgetDevice | ||
- ForgotPassword | ||
- GetDevice | ||
- GetUser | ||
- GetUserAttributeVerificationCode | ||
- GlobalSignOut | ||
- InitiateAuth | ||
- ListDevices | ||
- ResendConfirmationCode | ||
- RespondToAuthChallenge | ||
- RevokeToken | ||
- SetUserMFAPreference | ||
- SignUp | ||
- UpdateDeviceStatus | ||
- UpdateUserAttributes | ||
- VerifySoftwareToken | ||
- VerifyUserAttribute | ||
com.amazonaws.cognitoidentity: | ||
- GetCredentialsForIdentity | ||
- GetId | ||
|
||
plugins: | ||
- tool/generate_sdk_exceptions.dart |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
apis: | ||
s3: | ||
- com.amazonaws.s3#CopyObject | ||
- com.amazonaws.s3#DeleteObject | ||
- com.amazonaws.s3#DeleteObjects | ||
- com.amazonaws.s3#GetObject | ||
- com.amazonaws.s3#HeadObject | ||
- com.amazonaws.s3#ListObjectsV2 | ||
- com.amazonaws.s3#PutObject | ||
- com.amazonaws.s3#AbortMultipartUpload | ||
- com.amazonaws.s3#CompleteMultipartUpload | ||
- com.amazonaws.s3#CreateMultipartUpload | ||
- com.amazonaws.s3#ListParts | ||
- com.amazonaws.s3#UploadPart | ||
- com.amazonaws.s3#ListMultipartUploads | ||
- com.amazonaws.s3#UploadPartCopy | ||
- com.amazonaws.s3#SelectObjectContent | ||
com.amazonaws.s3: | ||
- CopyObject | ||
- DeleteObject | ||
- DeleteObjects | ||
- GetObject | ||
- HeadObject | ||
- ListObjectsV2 | ||
- PutObject | ||
- AbortMultipartUpload | ||
- CompleteMultipartUpload | ||
- CreateMultipartUpload | ||
- ListParts | ||
- UploadPart | ||
- ListMultipartUploads | ||
- UploadPartCopy | ||
- SelectObjectContent |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
apis: | ||
cognito-idp: | ||
- com.amazonaws.cognitoidentityprovider#AdminListUserAuthEvents | ||
com.amazonaws.cognitoidentityprovider: | ||
- AdminListUserAuthEvents |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool function, didn't know this existed.