Skip to content

Commit 6c38dd6

Browse files
feat(codestarconnection): add fromCodestartConnectionArn static method (#10)
* feat(codestarconnection): add fromCodestartConnectionArn static method with this method, we can create a codestar connection class from an exising arn * docs(codestarconnection): fix js-doc documentation the name of the imported resource arn was wrong. This comes from a comment in code review ISSUES CLOSED: 7
1 parent 584a092 commit 6c38dd6

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed

API.md

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/code-star-connection.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,28 @@ export interface CodeStarConnectionProps {
426426
* }
427427
*/
428428
export class CodeStarConnection extends CodeStarConnectionBase {
429+
/**
430+
* Import an externally defined Code Star Connection using its ARN.
431+
*
432+
* @param scope the construct that will "own" the imported key.
433+
* @param id the id of the imported code star conection in the construct tree.
434+
* @param codestarConnectionArn the ARN of an existing Code Star Connection.
435+
*/
436+
public static fromCodeStarConnectionArn(
437+
scope: Construct,
438+
id: string,
439+
codestarConnectionArn: string
440+
): ICodeStarConnection {
441+
class Import extends CodeStarConnectionBase {
442+
public connectionName = '';
443+
public connectionArn = codestarConnectionArn;
444+
}
445+
446+
return new Import(scope, id, {
447+
environmentFromArn: codestarConnectionArn,
448+
});
449+
}
450+
429451
public readonly connectionName: string;
430452
public readonly connectionArn: string;
431453

test/code-star-connection.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,3 +225,36 @@ describe('Grants permisions', () => {
225225
});
226226
});
227227
});
228+
229+
describe('Static methods', () => {
230+
it('should return a instance of code star connection and use the grantUse method', () => {
231+
// GIVEN
232+
const app = new App();
233+
const stack = new Stack(app, 'TestStack');
234+
235+
// WHEN
236+
const codestarConnection = CodeStarConnection.fromCodeStarConnectionArn(
237+
stack,
238+
'CodeStarConnectionFromArn',
239+
'arn:aws:codestar-connections:eu-west-1:123456789012:connection/8c86942e-a7ca-4a4a-8b63-e2f7f5efaeee'
240+
);
241+
242+
const role = new Role(stack, 'Role', {
243+
assumedBy: new AnyPrincipal(),
244+
});
245+
246+
codestarConnection.grantUse(role);
247+
248+
Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', {
249+
PolicyDocument: {
250+
Statement: [
251+
{
252+
Action: CodeStarConnectionPolicyActions.USE_CONNECTION,
253+
Effect: 'Allow',
254+
Resource: codestarConnection.connectionArn,
255+
},
256+
],
257+
},
258+
});
259+
});
260+
});

0 commit comments

Comments
 (0)