"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const codepipeline = require("@aws-cdk/aws-codepipeline");
const cdk = require("@aws-cdk/cdk");
/**
 * CodePipeline Source that is provided by an AWS CodeCommit repository.
 */
class PipelineSource extends codepipeline.Source {
    constructor(parent, name, props) {
        super(parent, name, {
            provider: 'CodeCommit',
            configuration: {
                RepositoryName: props.repository.repositoryName,
                BranchName: props.branch || 'master',
                PollForSourceChanges: props.pollForSourceChanges || true
            },
            artifactName: props.artifactName
        });
        // https://docs.aws.amazon.com/codecommit/latest/userguide/auth-and-access-control-permissions-reference.html#aa-acp
        const actions = [
            'codecommit:GetBranch',
            'codecommit:GetCommit',
            'codecommit:UploadArchive',
            'codecommit:GetUploadArchiveStatus',
            'codecommit:CancelUploadArchive',
        ];
        parent.pipeline.addToRolePolicy(new cdk.PolicyStatement()
            .addResource(props.repository.repositoryArn)
            .addActions(...actions));
    }
}
exports.PipelineSource = PipelineSource;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicGlwZWxpbmUtYWN0aW9uLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsicGlwZWxpbmUtYWN0aW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQ0EsMERBQTJEO0FBQzNELG9DQUFxQztBQThCckM7O0dBRUc7QUFDSCxNQUFhLGNBQWUsU0FBUSxZQUFZLENBQUMsTUFBTTtJQUNuRCxZQUFZLE1BQTBCLEVBQUUsSUFBWSxFQUFFLEtBQTBCO1FBQzVFLEtBQUssQ0FBQyxNQUFNLEVBQUUsSUFBSSxFQUFFO1lBQ2hCLFFBQVEsRUFBRSxZQUFZO1lBQ3RCLGFBQWEsRUFBRTtnQkFDWCxjQUFjLEVBQUUsS0FBSyxDQUFDLFVBQVUsQ0FBQyxjQUFjO2dCQUMvQyxVQUFVLEVBQUUsS0FBSyxDQUFDLE1BQU0sSUFBSSxRQUFRO2dCQUNwQyxvQkFBb0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