-
Notifications
You must be signed in to change notification settings - Fork 4k
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
"import" is a reserved word in Java #89
Comments
I think we shouldn't need to export/import anyway, see cross-stack references design |
That's one way to address this problem 😄 |
That's something we should probably do before 1.0 |
Yeah we do need to |
Also, we should standardize the naming for |
Okay, here's a proposal (following an online discussion with @RomainMuller and @rix0rrr). We'll use Bucket as an example: interface BucketAttributes {
readonly bucketArn: string;
readonly bucketName: string;
}
// mixing data types and interfaces?? would that be okay?
interface IBucket extends BucketAttributes {
export(): BucketAttributes;
}
class Bucket {
public static fromAttributes(parent: Construct, id: string, attributes: BucketAttributes): IBucket;
// if you only have a bucket ARN we can provide a convenience method which parses the
// bucket name from the ARN and vice versa
public static fromArn(parent: Construct, id: string, bucketArn: string): IBucket;
public static fromBucketName(parent: Construct, id: string, bucketName: string): IBucket;
} The only problem here is that we are mixing interfaces and data types ( |
I don't think the interface inheritance is going to be an issue. On the other hand, not convinced the combination of Also seems like the All's I'm saying is that I don't think we gain anything by tying |
I am feeling uneasy about the runtime checks we have around imports. It’s a bit of ugliness I’d love to get rid of. It also occasionally violate the rule that says that if all properties are optional then “props” should also be optional. The reason I feel this tie in makes sense is because there is a strong correlation between “import props” (for lack of a better term at the moment) and the set of attributes intrinsically available for a resource. I don’t like the fact that today we literally have to duplicate this set between BucketImportProps and IBucket, only with different levels of optionality. The “fromAttributes” method (with everything non-optional) will be useful espeically for exports and the various fromXxx methods will be more useful when you have a specific attribute value such as an ARN, etc. I like the fact that this approach gives us the ability to express the various import use cases without sacrificing type safety (contrary to the runtime checks approach). |
I agree with @eladb's point on the optionals issue. Since JSII can't allow "all type unions", the separate methods are the only way to restore type safety while allowing possibly disjoint sets of required/optional fields. |
The argument against DRY is that some things may look the same in some cases, but they're actually not the same, and now you've introduced coupling that shouldn't be there. I think S3 is a poor use case here. If you can make this design work in the ELBv2 package and/or the ECS package, then I withdraw my objections. |
@rix0rrr fair enough. Will definitely try to see how it plays out in those cases. |
Okay, @rix0rrr was right. Having For example, when you export a VPC, you export the set of public and private subnet IDs. This means that the output of vpcId: string;
availabilityZones: string[];
publicSubnetIds?: string[];
publicSubnetNames?: string[];
privateSubnetIds?: string[];
privateSubnetNames?: string[];
isolatedSubnetIds?: string[];
isolatedSubnetNames?: string[]; But in readonly vpcId: string;
readonly publicSubnets: IVpcSubnet[];
readonly privateSubnets: IVpcSubnet[];
readonly isolatedSubnets: IVpcSubnet[];
readonly availabilityZones: string[]; So, no! |
So, I think Here's a merge between @rix0rrr's original idea and the interface BucketExport {
bucketArn: string;
bucketName: string;
}
class Bucket {
public static fromExport(scope: cdk.Construct, id: string, export: BucketExport): IBucket;
public static fromBucketArn(scope: cdk.Construct, id: string, bucketArn: string): IBucket;
public static fromBucketName(scope: cdk.Construct, id: string, bucketName: string): IBucket;
}
interface IBucket {
bucketArn: string;
export(): BucketExport;
} Thoughts? |
And we can create some awslint rules that will encourage/enforce |
I think being explicit like this is right; it's intuitive/self-descriptive and has no chance of colliding with reserved words in any language. How does |
I am okay with the proposed keywords; but I think our cross-stack export mechanism needs some thinking. We have to carry over a bunch of data, and there is no convenient serialization mechanism we can use |
I tend towards a structured set of exports keyed off an identifier string |
That’s a good point Sam. I guess that we would only need “fromXxx” when cross stack references are implicit. @rix0rrr? |
@sam-goodwin brought up a good point. We need to revisit imports/exports altogether given #1436. I will submit an PR with an RFC and will take the opportunity to resolve this as well. |
Superseded by #2273 |
Implement and apply the following awslint rules: - `awslint:from-method`: resources should have at least one static "from" method - `awslint:from-signature`: enforce method signature - `awslint:from-attributes`: a `fromAttributes` static method can be used to import from more than a single attribute - `awslint:from-attributes-struct`: `fromFooAttributes` should accept a `FooAttributes` struct as input - `awslint:no-static-import`: forbids a static `import` (deprecation helper rule) - `awslint:attribute-tag`: all resource attributes should have an "@Attribute" doc tag - `awslint:attribute-readonly`: all attributes must be readonly properties Many resources now have an additional `fromFooArn` or `fromFooName` for importing from the intrinsic attribute. Misc: - Deprecate `Token.unresolved` in favor of `Token.isToken` (more idiomatic). - Added eager resolution of `Fn.select` and `Fn.split` in case they receive concrete values - Refactoring of awslint (decouple "resource" from "cfn-resource"). - Added `iam.Grant.drop` which allows "dropping" a grant on the floor for imported resources NOTE: many of the new methods do not have inline documentation. We will address this in a subsequent pass that will be focused on docs. Fixes #2450 Fixes #2428 Fixes #2424 Fixes #2429 Fixes #2425 Fixes #2422 Fixes #2423 Fixes #89 BREAKING CHANGE: all `Foo.import` static methods are now `Foo.fromFooAttributes` * All `FooImportProps` structs are now called `FooAttributes` * `stepfunctions.StateMachine.export` has been removed. * `ses.ReceiptRule.name` is now `ses.ReceiptRule.receiptRuleName` * `ses.ReceiptRuleSet.name` is now `ses.ReceiptRuleSet.receiptRuleSetName` * `secretsmanager.AttachedSecret` is now called `secretsmanager.SecretTargetAttachment` to match service semantics * `ecr.Repository.export` has been removed * `s3.Bucket.bucketUrl` is now called `s3.Bucket.bucketWebsiteUrl` * `lambda.Version.functionVersion` is now called `lambda.Version.version` * `ec2.SecurityGroup.groupName` is now `ec2.SecurityGroup.securityGroupName` * `cognito.UserPoolClient.clientId` is now `cognito.UserPoolClient.userPoolClientId` * `apigateway.IRestApiResource` is now `apigateway.IResource` * `apigateway.IResource.resourcePath` is now `apigateway.IResource.path` * `apigateway.IResource.resourceApi` is now `apigateway.IResource.restApi`
Implement and apply the following awslint rules: - `awslint:from-method`: resources should have at least one static "from" method - `awslint:from-signature`: enforce method signature - `awslint:from-attributes`: a `fromAttributes` static method can be used to import from more than a single attribute - `awslint:from-attributes-struct`: `fromFooAttributes` should accept a `FooAttributes` struct as input - `awslint:no-static-import`: forbids a static `import` (deprecation helper rule) - `awslint:attribute-tag`: all resource attributes should have an "@Attribute" doc tag - `awslint:attribute-readonly`: all attributes must be readonly properties Many resources now have an additional `fromFooArn` or `fromFooName` for importing from the intrinsic attribute. Misc: - Deprecate `Token.unresolved` in favor of `Token.isToken` (more idiomatic). - Added eager resolution of `Fn.select` and `Fn.split` in case they receive concrete values - Refactoring of awslint (decouple "resource" from "cfn-resource"). - Added `iam.Grant.drop` which allows "dropping" a grant on the floor for imported resources NOTE: many of the new methods do not have inline documentation. We will address this in a subsequent pass that will be focused on docs. Fixes aws#2450 Fixes aws#2428 Fixes aws#2424 Fixes aws#2429 Fixes aws#2425 Fixes aws#2422 Fixes aws#2423 Fixes aws#89 BREAKING CHANGE: all `Foo.import` static methods are now `Foo.fromFooAttributes` * All `FooImportProps` structs are now called `FooAttributes` * `stepfunctions.StateMachine.export` has been removed. * `ses.ReceiptRule.name` is now `ses.ReceiptRule.receiptRuleName` * `ses.ReceiptRuleSet.name` is now `ses.ReceiptRuleSet.receiptRuleSetName` * `secretsmanager.AttachedSecret` is now called `secretsmanager.SecretTargetAttachment` to match service semantics * `ecr.Repository.export` has been removed * `s3.Bucket.bucketUrl` is now called `s3.Bucket.bucketWebsiteUrl` * `lambda.Version.functionVersion` is now called `lambda.Version.version` * `ec2.SecurityGroup.groupName` is now `ec2.SecurityGroup.securityGroupName` * `cognito.UserPoolClient.clientId` is now `cognito.UserPoolClient.userPoolClientId` * `apigateway.IRestApiResource` is now `apigateway.IResource` * `apigateway.IResource.resourcePath` is now `apigateway.IResource.path` * `apigateway.IResource.resourceApi` is now `apigateway.IResource.restApi`
All AWS constructs have a static
import
method to allow bringing-in resources defined externally. However,import
is reserved in Java (and possibly in other languages).In the interim the jsii compiler will simply add an
_
at the end of the method name, but we need to find a new name for the method and rename across the codebase.The text was updated successfully, but these errors were encountered: