Skip to content

Commit

Permalink
Merge branch 'master' into epolon/graduate-docdb
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Mar 30, 2021
2 parents 623c305 + 08de262 commit cfa6057
Show file tree
Hide file tree
Showing 17 changed files with 77 additions and 32 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
"standard-version": "^9.1.1",
"typescript": "~3.9.9"
},
"resolutions-comment": "should be removed or reviewed when nodeunit dependency is dropped or adjusted",
"netmask-resolutions-comment": "transitive dep from proxy-agent@4.0.1. review when dependencies upgrade",
"tap-mocha-reporter-resolutions-comment": "should be removed or reviewed when nodeunit dependency is dropped or adjusted",
"resolutions": {
"netmask": "2.0.1",
"tap-mocha-reporter": "^5.0.1"
},
"repository": {
Expand Down
12 changes: 1 addition & 11 deletions packages/@aws-cdk/aws-chatbot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,7 @@

![cfn-resources: Stable](https://img.shields.io/badge/cfn--resources-stable-success.svg?style=for-the-badge)

> All classes with the `Cfn` prefix in this module ([CFN Resources]) are always stable and safe to use.
>
> [CFN Resources]: https://docs.aws.amazon.com/cdk/latest/guide/constructs.html#constructs_lib
![cdk-constructs: Experimental](https://img.shields.io/badge/cdk--constructs-experimental-important.svg?style=for-the-badge)

> The APIs of higher level constructs in this module are experimental and under active development.
> They are subject to non-backward compatible changes or removal in any future version. These are
> not subject to the [Semantic Versioning](https://semver.org/) model and breaking changes will be
> announced in the release notes. This means that while you may use them, you may need to update
> your source code when upgrading to a newer version of this package.
![cdk-constructs: Stable](https://img.shields.io/badge/cdk--constructs-stable-success.svg?style=for-the-badge)

---

Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-chatbot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@
"engines": {
"node": ">= 10.13.0 <13 || >=13.7.0"
},
"stability": "experimental",
"maturity": "experimental",
"stability": "stable",
"maturity": "stable",
"awscdkio": {
"announce": false
},
Expand Down
17 changes: 16 additions & 1 deletion packages/@aws-cdk/aws-iam/test/role.from-role-arn.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import '@aws-cdk/assert/jest';
import { App, CfnElement, Lazy, Stack } from '@aws-cdk/core';
import { App, Aws, CfnElement, Lazy, Stack } from '@aws-cdk/core';
import { AnyPrincipal, ArnPrincipal, IRole, Policy, PolicyStatement, Role } from '../lib';

/* eslint-disable quote-props */
Expand Down Expand Up @@ -519,6 +519,21 @@ describe('IAM Role.fromRoleArn', () => {
});
});
});

describe('for an incorrect ARN', () => {
beforeEach(() => {
roleStack = new Stack(app, 'RoleStack');
});

describe("that accidentally skipped the 'region' fragment of the ARN", () => {
test('throws an exception, indicating that error', () => {
expect(() => {
Role.fromRoleArn(roleStack, 'Role',
`arn:${Aws.PARTITION}:iam:${Aws.ACCOUNT_ID}:role/AwsCicd-${Aws.REGION}-CodeBuildRole`);
}).toThrow(/The `resource` component \(6th component\) of an ARN is required:/);
});
});
});
});

function somePolicyStatement() {
Expand Down
28 changes: 18 additions & 10 deletions packages/@aws-cdk/core/lib/arn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,36 +286,44 @@ function parseToken(arnToken: string, sep: string = '/', hasName: boolean = true
* Validate that a string is either unparseable or looks mostly like an ARN
*/
function parseArnShape(arn: string): 'token' | string[] {
const components = arn.split(':');
const looksLikeArn = arn.startsWith('arn:') && components.length >= 6;
// assume anything that starts with 'arn:' is an ARN,
// so we can report better errors
const looksLikeArn = arn.startsWith('arn:');

if (!looksLikeArn) {
if (Token.isUnresolved(arn)) { return 'token'; }
throw new Error(`ARNs must start with "arn:" and have at least 6 components: ${arn}`);
if (Token.isUnresolved(arn)) {
return 'token';
} else {
throw new Error(`ARNs must start with "arn:" and have at least 6 components: ${arn}`);
}
}

// If the ARN merely contains Tokens, but otherwise *looks* mostly like an ARN,
// it's a string of the form 'arn:${partition}:service:${region}:${account}:abc/xyz'.
// it's a string of the form 'arn:${partition}:service:${region}:${account}:resource/xyz'.
// Parse fields out to the best of our ability.
// Tokens won't contain ":", so this won't break them.
const components = arn.split(':');

const [/* arn */, partition, service, /* region */ , /* account */ , resource] = components;
// const [/* arn */, partition, service, /* region */ , /* account */ , resource] = components;

const partition = components.length > 1 ? components[1] : undefined;
if (!partition) {
throw new Error('The `partition` component (2nd component) is required: ' + arn);
throw new Error('The `partition` component (2nd component) of an ARN is required: ' + arn);
}

const service = components.length > 2 ? components[2] : undefined;
if (!service) {
throw new Error('The `service` component (3rd component) is required: ' + arn);
throw new Error('The `service` component (3rd component) of an ARN is required: ' + arn);
}

const resource = components.length > 5 ? components[5] : undefined;
if (!resource) {
throw new Error('The `resource` component (6th component) is required: ' + arn);
throw new Error('The `resource` component (6th component) of an ARN is required: ' + arn);
}

// Region can be missing in global ARNs (such as used by IAM)

// Account can be missing in some ARN types (such as used for S3 buckets)

return components;
}
}
6 changes: 3 additions & 3 deletions packages/@aws-cdk/core/test/arn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,19 @@ nodeunitShim({

'if the ARN doesnt have enough components'(test: Test) {
const stack = new Stack();
test.throws(() => stack.parseArn('arn:is:too:short'), /ARNs must.*have at least 6 components.*arn:is:too:short/);
test.throws(() => stack.parseArn('arn:is:too:short'), /The `resource` component \(6th component\) of an ARN is required/);
test.done();
},

'if "service" is not specified'(test: Test) {
const stack = new Stack();
test.throws(() => stack.parseArn('arn:aws::4:5:6'), /The `service` component \(3rd component\) is required/);
test.throws(() => stack.parseArn('arn:aws::4:5:6'), /The `service` component \(3rd component\) of an ARN is required/);
test.done();
},

'if "resource" is not specified'(test: Test) {
const stack = new Stack();
test.throws(() => stack.parseArn('arn:aws:service:::'), /The `resource` component \(6th component\) is required/);
test.throws(() => stack.parseArn('arn:aws:service:::'), /The `resource` component \(6th component\) of an ARN is required/);
test.done();
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@
},
"dependencies": {
"@aws-cdk/core": "%cdk-version%"
},
"resolutions": {
"netmask": "2.0.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@
"dependencies": {
"@aws-cdk/core": "%cdk-version%",
"source-map-support": "^0.5.16"
},
"resolutions": {
"netmask": "2.0.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@
},
"dependencies": {
"@aws-cdk/core": "%cdk-version%"
},
"resolutions": {
"netmask": "2.0.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@
"@aws-cdk/aws-sns-subscriptions": "%cdk-version%",
"@aws-cdk/aws-sqs": "%cdk-version%",
"@aws-cdk/core": "%cdk-version%"
},
"resolutions": {
"netmask": "2.0.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@
"@aws-cdk/aws-sns-subscriptions": "%cdk-version%",
"@aws-cdk/aws-sqs": "%cdk-version%",
"@aws-cdk/core": "%cdk-version%"
},
"resolutions": {
"netmask": "2.0.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@
"dependencies": {
"aws-cdk-lib": "%cdk-version%",
"constructs": "^3.0.4"
},
"resolutions": {
"netmask": "2.0.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@
"aws-cdk-lib": "%cdk-version%",
"constructs": "^3.0.4",
"source-map-support": "^0.5.16"
},
"resolutions": {
"netmask": "2.0.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@
"dependencies": {
"aws-cdk-lib": "%cdk-version%",
"constructs": "^3.0.4"
},
"resolutions": {
"netmask": "2.0.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@
"dependencies": {
"aws-cdk-lib": "%cdk-version%",
"constructs": "^3.0.4"
},
"resolutions": {
"netmask": "2.0.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@
"dependencies": {
"aws-cdk-lib": "%cdk-version%",
"constructs": "^3.0.4"
},
"resolutions": {
"netmask": "2.0.1"
}
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6909,10 +6909,10 @@ nested-error-stacks@^2.0.0:
resolved "https://registry.yarnpkg.com/nested-error-stacks/-/nested-error-stacks-2.1.0.tgz#0fbdcf3e13fe4994781280524f8b96b0cdff9c61"
integrity sha512-AO81vsIO1k1sM4Zrd6Hu7regmJN1NSiAja10gc4bX3F0wd+9rQmcuHQaHVQCYIEC8iFXnE+mavh23GOt7wBgug==

netmask@^1.0.6:
version "1.0.6"
resolved "https://registry.yarnpkg.com/netmask/-/netmask-1.0.6.tgz#20297e89d86f6f6400f250d9f4f6b4c1945fcd35"
integrity sha1-ICl+idhvb2QA8lDZ9Pa0wZRfzTU=
netmask@2.0.1, netmask@^1.0.6:
version "2.0.1"
resolved "https://registry.yarnpkg.com/netmask/-/netmask-2.0.1.tgz#5a5cbdcbb7b6de650870e15e83d3e9553a414cf4"
integrity sha512-gB8eG6ubxz67c7O2gaGiyWdRUIbH61q7anjgueDqCC9kvIs/b4CTtCMaQKeJbv1/Y7FT19I4zKwYmjnjInRQsg==

nice-try@^1.0.4:
version "1.0.5"
Expand Down

0 comments on commit cfa6057

Please sign in to comment.