Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions API.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions src/code-star-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,28 @@ export interface CodeStarConnectionProps {
* }
*/
export class CodeStarConnection extends CodeStarConnectionBase {
/**
* Import an externally defined Code Star Connection using its ARN.
*
* @param scope the construct that will "own" the imported key.
* @param id the id of the imported code star conection in the construct tree.
* @param codestarConnectionArn the ARN of an existing Code Star Connection.
*/
public static fromCodeStarConnectionArn(
scope: Construct,
id: string,
codestarConnectionArn: string
): ICodeStarConnection {
class Import extends CodeStarConnectionBase {
public connectionName = '';
public connectionArn = codestarConnectionArn;
}

return new Import(scope, id, {
environmentFromArn: codestarConnectionArn,
});
}

public readonly connectionName: string;
public readonly connectionArn: string;

Expand Down
33 changes: 33 additions & 0 deletions test/code-star-connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,36 @@ describe('Grants permisions', () => {
});
});
});

describe('Static methods', () => {
it('should return a instance of code star connection and use the grantUse method', () => {
// GIVEN
const app = new App();
const stack = new Stack(app, 'TestStack');

// WHEN
const codestarConnection = CodeStarConnection.fromCodeStarConnectionArn(
stack,
'CodeStarConnectionFromArn',
'arn:aws:codestar-connections:eu-west-1:123456789012:connection/8c86942e-a7ca-4a4a-8b63-e2f7f5efaeee'
);

const role = new Role(stack, 'Role', {
assumedBy: new AnyPrincipal(),
});

codestarConnection.grantUse(role);

Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', {
PolicyDocument: {
Statement: [
{
Action: CodeStarConnectionPolicyActions.USE_CONNECTION,
Effect: 'Allow',
Resource: codestarConnection.connectionArn,
},
],
},
});
});
});