diff --git a/packages/@aws-cdk/aws-iam/lib/group.ts b/packages/@aws-cdk/aws-iam/lib/group.ts index 671879b54da9d..7df4be3118611 100644 --- a/packages/@aws-cdk/aws-iam/lib/group.ts +++ b/packages/@aws-cdk/aws-iam/lib/group.ts @@ -67,7 +67,7 @@ export class Group extends Resource implements IIdentity { }); this.groupName = group.groupName; - this.groupArn = group.groupArn; + this.groupArn = group.attrArn; this.policyFragment = new ArnPrincipal(this.groupArn).policyFragment; } diff --git a/packages/@aws-cdk/aws-iam/lib/lazy-role.ts b/packages/@aws-cdk/aws-iam/lib/lazy-role.ts index 2af11a3acb1f0..5a7c4c179601e 100644 --- a/packages/@aws-cdk/aws-iam/lib/lazy-role.ts +++ b/packages/@aws-cdk/aws-iam/lib/lazy-role.ts @@ -76,12 +76,12 @@ export class LazyRole extends cdk.Construct implements IRole { /** * Returns the ARN of this role. */ - public get roleArn(): string { - return this.instantiate().roleArn; + public get attrArn(): string { + return this.instantiate().attrArn; } - public get roleId(): string { - return this.instantiate().roleId; + public get attrRoleId(): string { + return this.instantiate().attrRoleId; } public get roleName(): string { diff --git a/packages/@aws-cdk/aws-iam/lib/role.ts b/packages/@aws-cdk/aws-iam/lib/role.ts index cfbbc8f10877d..14a1213488218 100644 --- a/packages/@aws-cdk/aws-iam/lib/role.ts +++ b/packages/@aws-cdk/aws-iam/lib/role.ts @@ -113,13 +113,13 @@ export class Role extends Resource implements IRole { /** * Returns the ARN of this role. */ - public readonly roleArn: string; + public readonly attrArn: string; /** * Returns the stable and unique string identifying the role. For example, * AIDAJQABLZS4A3QDU576Q. */ - public readonly roleId: string; + public readonly attrRoleId: string; /** * Returns the name of the role. @@ -152,10 +152,10 @@ export class Role extends Resource implements IRole { maxSessionDuration: props.maxSessionDurationSec, }); - this.roleId = role.roleId; - this.roleArn = role.roleArn; + this.attrRoleId = role.attrRoleId; + this.attrArn = role.attrArn; this.roleName = role.roleName; - this.policyFragment = new ArnPrincipal(this.roleArn).policyFragment; + this.policyFragment = new ArnPrincipal(this.attrArn).policyFragment; function _flatten(policies?: { [name: string]: PolicyDocument }) { if (policies == null || Object.keys(policies).length === 0) { @@ -172,8 +172,8 @@ export class Role extends Resource implements IRole { public export(): RoleImportProps { return { - roleArn: new CfnOutput(this, 'RoleArn', { value: this.roleArn }).makeImportValue(), - roleId: new CfnOutput(this, 'RoleId', { value: this.roleId }).makeImportValue() + roleArn: new CfnOutput(this, 'RoleArn', { value: this.attrArn }).makeImportValue(), + roleId: new CfnOutput(this, 'RoleId', { value: this.attrRoleId }).makeImportValue() }; } @@ -215,7 +215,7 @@ export class Role extends Resource implements IRole { return Grant.addToPrincipal({ grantee, actions, - resourceArns: [this.roleArn], + resourceArns: [this.attrArn], scope: this }); } @@ -235,13 +235,13 @@ export interface IRole extends IIdentity { /** * Returns the ARN of this role. */ - readonly roleArn: string; + readonly attrArn: string; /** * Returns the stable and unique string identifying the role. For example, * AIDAJQABLZS4A3QDU576Q. */ - readonly roleId: string; + readonly attrRoleId: string; /** * Returns the name of this role. @@ -313,18 +313,18 @@ class ImportedRole extends Construct implements IRole { public readonly grantPrincipal: IPrincipal = this; public readonly assumeRoleAction: string = 'sts:AssumeRole'; public readonly policyFragment: PrincipalPolicyFragment; - public readonly roleArn: string; + public readonly attrArn: string; private readonly _roleId?: string; constructor(scope: Construct, id: string, private readonly props: RoleImportProps) { super(scope, id); - this.roleArn = props.roleArn; + this.attrArn = props.roleArn; this._roleId = props.roleId; - this.policyFragment = new ArnPrincipal(this.roleArn).policyFragment; + this.policyFragment = new ArnPrincipal(this.attrArn).policyFragment; } - public get roleId() { + public get attrRoleId() { if (!this._roleId) { throw new Error(`No roleId specified for imported role`); } @@ -332,7 +332,7 @@ class ImportedRole extends Construct implements IRole { } public get roleName() { - return this.node.stack.parseArn(this.roleArn).resourceName!; + return this.node.stack.parseArn(this.attrArn).resourceName!; } public export() { @@ -359,7 +359,7 @@ class ImportedRole extends Construct implements IRole { return Grant.addToPrincipal({ grantee, actions, - resourceArns: [this.roleArn], + resourceArns: [this.attrArn], scope: this }); } diff --git a/packages/@aws-cdk/aws-iam/lib/user.ts b/packages/@aws-cdk/aws-iam/lib/user.ts index 10e8d4a8629b9..a3201c0b4cfee 100644 --- a/packages/@aws-cdk/aws-iam/lib/user.ts +++ b/packages/@aws-cdk/aws-iam/lib/user.ts @@ -101,7 +101,7 @@ export class User extends Resource implements IIdentity { }); this.userName = user.userName; - this.userArn = user.userArn; + this.userArn = user.attrArn; this.policyFragment = new ArnPrincipal(this.userArn).policyFragment; if (props.groups) { diff --git a/packages/@aws-cdk/aws-iam/test/test.lazy-role.ts b/packages/@aws-cdk/aws-iam/test/test.lazy-role.ts index dd3ab5ec63f2b..0d498c80fd13a 100644 --- a/packages/@aws-cdk/aws-iam/test/test.lazy-role.ts +++ b/packages/@aws-cdk/aws-iam/test/test.lazy-role.ts @@ -25,7 +25,7 @@ export = nodeunit.testCase({ // WHEN const roleArn = new iam.LazyRole(stack, 'Lazy', { assumedBy: new iam.ServicePrincipal('test.service') - }).roleArn; + }).attrArn; // THEN test.notEqual(roleArn, null); diff --git a/packages/@aws-cdk/aws-iam/test/test.role.ts b/packages/@aws-cdk/aws-iam/test/test.role.ts index c8a7a7d266976..fa655b0f99103 100644 --- a/packages/@aws-cdk/aws-iam/test/test.role.ts +++ b/packages/@aws-cdk/aws-iam/test/test.role.ts @@ -269,8 +269,8 @@ export = { roleId: { 'Fn::ImportValue': 'Stack:MyRoleRoleIdF7B258D8' } }); - test.deepEqual(stack.node.resolve(importedRole.roleArn), { 'Fn::ImportValue': 'Stack:MyRoleRoleArn3388B7E2' }); - test.deepEqual(stack.node.resolve(importedRole.roleId), { 'Fn::ImportValue': 'Stack:MyRoleRoleIdF7B258D8' }); + test.deepEqual(stack.node.resolve(importedRole.attrArn), { 'Fn::ImportValue': 'Stack:MyRoleRoleArn3388B7E2' }); + test.deepEqual(stack.node.resolve(importedRole.attrRoleId), { 'Fn::ImportValue': 'Stack:MyRoleRoleIdF7B258D8' }); test.deepEqual(stack.node.resolve(importedRole.roleName), { 'Fn::Select': [ 1, { 'Fn::Split': [ '/', { diff --git a/tools/awslint/lib/rules/resource.ts b/tools/awslint/lib/rules/resource.ts index 32ffeeccc0ca5..c0fd804448dcc 100644 --- a/tools/awslint/lib/rules/resource.ts +++ b/tools/awslint/lib/rules/resource.ts @@ -112,7 +112,11 @@ resourceLinter.add({ const resourceAttributes = new Array(); for (const attr of e.ctx.resource.attributes) { const attribute: reflect.Property | undefined = e.ctx.resourceInterface.ownProperties.find(p => p.name === attr); + // tslint:disable-next-line:no-console + e.ctx.resourceInterface.ownProperties.map(p => console.log(`name: ${p.name}, attr: ${attr}`)); const scope: string = e.ctx.resourceInterface.fqn + '.' + attr; + // tslint:disable-next-line:no-console + console.log(`${scope} :: ${attribute}`); if (e.assert(attribute, scope)) { resourceAttributes.push(attribute); } @@ -192,4 +196,4 @@ resourceLinter.add({ }); } } -}); \ No newline at end of file +}); diff --git a/tools/cfn2ts/lib/codegen.ts b/tools/cfn2ts/lib/codegen.ts index e922c4613aeca..e8a9e8f3cc049 100644 --- a/tools/cfn2ts/lib/codegen.ts +++ b/tools/cfn2ts/lib/codegen.ts @@ -249,21 +249,7 @@ export default class CodeGenerator { attributes.push(refAttr); } - // // - // // Ref attribute - // // - // if (spec.RefKind !== schema.SpecialRefKind.None) { - // const refAttribute = genspec.refAttributeDefinition(resourceName, spec.RefKind!); - // - // // If there's already an attribute with the same name, ref is not needed - // if (!attributes.some(a => a.propertyName === refAttribute.propertyName)) { - // this.code.line(`public readonly ${refAttribute.propertyName}Attr: ${refAttribute.attributeType};`); - // attributes.push(refAttribute); - // } - // } - // set class properties to match CloudFormation Properties spec - if (propsType) { this.emitPropsTypeProperties(resourceName, spec.Properties!, Container.Class); } diff --git a/tools/cfn2ts/lib/genspec.ts b/tools/cfn2ts/lib/genspec.ts index 2f64322bfca98..bddd7d9289fea 100644 --- a/tools/cfn2ts/lib/genspec.ts +++ b/tools/cfn2ts/lib/genspec.ts @@ -169,7 +169,8 @@ export function validatorName(typeName: CodeName): CodeName { */ export function attributeDefinition(attributeName: string, spec: schema.Attribute): Attribute { const descriptiveName = attributeName.replace(/\./g, ''); - const propertyName = `${cloudFormationToScriptName(descriptiveName)}Attr`; // "bucketArn" + const suffixName = codemaker.toPascalCase(cloudFormationToScriptName(descriptiveName)); + const propertyName = `attr${suffixName}`; // "attrArn" let attrType: string; if ('PrimitiveType' in spec && spec.PrimitiveType === 'String') { @@ -193,7 +194,7 @@ export function refAttributeDefinition(): Attribute { const constructorArguments = 'this.ref'; - return new Attribute('refAttr', 'string', constructorArguments); + return new Attribute('attrRef', 'string', constructorArguments); } /**