Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async createPipeline() {
setCredsByProfile(this.profile)
// preparations for deployment
const isTest = this.stage === 'test'
const suffix = `${isTest ? `-${this.branch}-test` : ''}-ci`
const pkgJson = require(`${this.appPath}/package.json`)
const name = `${pkgJson.name}${suffix}`.replace(/[^0-9A-Za-z-]/g, '')
const sdk = new SDK({})
const account = await sdk.defaultAccount()
const stackProps = { env: { account, region: this.region } }
const props = { projectName: name, sdk, stackProps }
const actions = this.actions
// construct the stack and the app
const pipelineApp = new SeagullApp(props)
const stack = pipelineApp.stack
const principal = 'codebuild.amazonaws.com'
const role = stack.addIAMRole('role', principal, actions)
const pipeline = stack.addPipeline('pipeline')
const token = this.githubToken
const tokenName = token ? `${name}-github` : this.ssmParam || undefined
const secretParams = { ssmHandler: this.ssm, token, tokenName }
const ssmSecret = await handleSSMSecret(secretParams)
const gitDataProps = {
async diffStack() {
const sdk = new cdk.SDK({})
const synthStack = this.synthesizeStack(this.projectName)
const cfn = await sdk.cloudFormation(synthStack.environment, 0)
const templateData = { StackName: synthStack.name }
const template = await cfn.getTemplate(templateData).promise()
const body = template.TemplateBody
const curTemplate = (body && yaml.parse(body, { schema: 'yaml-1.1' })) || {}
const logicalToPathMap = lib.createLogicalToPathMap(synthStack)
const diff = cfnDiff.diffTemplate(curTemplate, synthStack.template)
// tslint:disable-next-line:no-unused-expression
diff.isEmpty && lib.noChangesInDiff()
cfnDiff.formatDifferences(process.stdout, diff, logicalToPathMap)
}
}
async createBareApp() {
const account = this.account || (await new SDK({}).defaultAccount())
const itemsProps = {
accountId: (await aws.getAccountId(this.sts)) || '',
branch: this.branch,
projectName: this.pkgJson.name,
region: this.region,
stage: this.stage,
topic: 'items',
}
const appProps = {
addAssets: true,
appPath: this.appPath,
itemsBucket: lib.getBucketName(itemsProps),
projectName: this.getAppName(),
stackProps: { env: { account, region: this.region } },
}
return new SeagullApp(appProps)
constructor(appPath: string, opts: Options) {
this.appPath = appPath
this.opts = opts
this.projectName = `${require(`${appPath}/package.json`).name}-pipeline`
this.sdk = new cdk.SDK({})
this.logicalToPathMap = {}
this.synthStack = {} as SynthesizedStack
}
async deployStack() {
const sdk = new cdk.SDK({})
const synthStack = this.synthesizeStack(this.projectName)
const env = synthStack.environment
await cdk.bootstrapEnvironment(env, sdk, 'CDKToolkit', undefined)
const toolkitInfo = await cdk.loadToolkitInfo(env, sdk, 'CDKToolkit')
await cdk.deployStack({ sdk, stack: synthStack, toolkitInfo })
}