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EjB,SAAU,OAIhB,CACE,KAAM,QACN,QAAS,CACP,CACE,KAAM,YACN,eAAgB,CAAC,CAAE,KAAM,GAAG,MAC5B,aAAc,CACZ,SAAU,QACV,MAAO,MACP,QAAS,IACT,SAAU,aAEZ,gBAAiB,CAAC,CAAE,KAAM,GAAG,WAC7B,cAAe,CACb,YAAa,CACX,IAAK,UAGT,SAAU,QAKlB,cAAe,CACb,KAAM,KACN,SAAU,CAAE,IAAK,kCAQzB,OAFA,EAAE,OAAO,EAAU,EAAM,EAAO,GAEzB,CACT,EAGF,OAAO,QAAU","file":"/npm/serverless-codepipeline@1.0.3/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/serverless-codepipeline@1.0.3/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\n\nconst _ = require(\"lodash\");\n\nconst baseImage = \"aws/codebuild/ubuntu-base:14.04\";\nconst nodeImage = \"aws/codebuild/nodejs:6.3.1\";\nconst pythonImage = \"aws/codebuild/python:3.5.2\";\nlet stage;\n\nclass CICDPlugin {\n  constructor(serverless, options) {\n    this.serverless = serverless;\n    this.options = options;\n    this.provider = this.serverless.getProvider(\"aws\");\n\n    /* Hooks tell Serverless when to do what */\n    this.hooks = {\n      \"before:package:initialize\": this.update.bind(this)\n    };\n  }\n\n  /**\n   * Updates CloudFormation resources with CICD\n   */\n  update() {\n    const service = this.serverless.service;\n    stage =\n      this.options.stage && this.options.stage.length > 0\n        ? this.options.stage\n        : service.provider.stage;\n    if (service.custom.cicd) {\n      if (\n        service.custom.cicd.excludestages &&\n        service.custom.cicd.excludestages.includes(\"stage\")\n      ) {\n        this.serverless.cli.log(`CICD is ignored for ${stage} stage`);\n        return;\n      }\n    }\n\n    this.serverless.cli.log(\"Updating CICD Resources...\");\n    const resource = this.create();\n    if (this.serverless.service.resources === undefined) {\n      this.serverless.service.resources = {\n        Resources: {}\n      };\n    } else if (this.serverless.service.resources.Resources === undefined) {\n      this.serverless.service.resources.Resources = {};\n    }\n    _.extend(this.serverless.service.resources.Resources, resource);\n    this.serverless.cli.log(\"CICD Resources Updated\");\n  }\n\n  /**\n   * Creates CloudFormation resources object with CICD Role, CodeBuild, CodePipeline\n   * @return {Object} resources object\n   */\n  create() {\n    const service = this.serverless.service;\n    const serviceName = service.service;\n    let image = baseImage;\n    let gitOwner = \"\";\n    let gitRepo = service.name;\n    let gitBranch = \"master\";\n    let githubOAuth = \"\";\n\n    if (service.custom[stage]) {\n      gitBranch = service.custom[stage].branch;\n    }\n\n    if (service.custom.cicd) {\n      if (service.custom.cicd.image != null) {\n        image = service.custom.cicd.image;\n      } else if (service.provider.runtime.includes(\"node\")) {\n        image = nodeImage;\n      } else if (service.provider.runtime.includes(\"python\")) {\n        image = pythonImage;\n      }\n\n      gitOwner = service.custom.cicd.owner || \"\";\n      gitRepo = service.custom.cicd.repository || gitRepo;\n      gitBranch = service.custom.cicd.branch || gitBranch;\n      githubOAuth = service.custom.cicd.githubtoken || \"\";\n    }\n\n    const resource = {};\n\n    // This role has a lot of access, but depending what you do with your buildspec\n    // it might be needed!\n    const policy = JSON.parse(service.custom.cicd.policy);\n\n    const role = {\n      CICDRole: {\n        Type: \"AWS::IAM::Role\",\n        Properties: {\n          RoleName: `${serviceName}-${stage}`,\n          AssumeRolePolicyDocument: {\n            Version: \"2012-10-17\",\n            Statement: [\n              {\n                Effect: \"Allow\",\n                Principal: {\n                  Service: [\"codepipeline.amazonaws.com\"]\n                },\n                Action: [\"sts:AssumeRole\"]\n              },\n              {\n                Effect: \"Allow\",\n                Principal: {\n                  Service: [\"codebuild.amazonaws.com\"]\n                },\n                Action: [\"sts:AssumeRole\"]\n              }\n            ]\n          },\n          Policies: [\n            {\n              PolicyName: `${serviceName}-${stage}`,\n              PolicyDocument: policy\n            }\n          ]\n        }\n      }\n    };\n\n    const build = {\n      Build: {\n        Type: \"AWS::CodeBuild::Project\",\n        Properties: {\n          Name: `${serviceName}-${stage}`,\n          ServiceRole: {\n            \"Fn::GetAtt\": [\"CICDRole\", \"Arn\"]\n          },\n          Artifacts: {\n            Type: \"CODEPIPELINE\",\n            Name: `${serviceName}-${stage}-build`,\n            Packaging: \"NONE\"\n          },\n          Environment: {\n            Type: \"LINUX_CONTAINER\",\n            ComputeType: \"BUILD_GENERAL1_SMALL\",\n            Image: `${image}`,\n            EnvironmentVariables: [\n              {\n                Name: \"STAGE\",\n                Value: `${stage}`\n              }\n            ]\n          },\n          Source: {\n            Type: \"CODEPIPELINE\"\n          },\n          TimeoutInMinutes: 60\n        }\n      }\n    };\n\n    const pipeline = {\n      Pipeline: {\n        Type: \"AWS::CodePipeline::Pipeline\",\n        Properties: {\n          Name: `${serviceName}-${stage}`,\n          RoleArn: {\n            \"Fn::GetAtt\": [\"CICDRole\", \"Arn\"]\n          },\n          Stages: [\n            {\n              Name: \"Source\",\n              Actions: [\n                {\n                  Name: \"Source\",\n                  ActionTypeId: {\n                    Category: \"Source\",\n                    Owner: \"ThirdParty\",\n                    Version: \"1\",\n                    Provider: \"GitHub\"\n                  },\n                  OutputArtifacts: [{ Name: `${serviceName}` }],\n                  Configuration: {\n                    Owner: `${gitOwner}`,\n                    Repo: `${gitRepo}`,\n                    Branch: `${gitBranch}`,\n                    OAuthToken: `${githubOAuth}`\n                  },\n                  RunOrder: \"1\"\n                }\n              ]\n            },\n            {\n              Name: \"Build\",\n              Actions: [\n                {\n                  Name: \"CodeBuild\",\n                  InputArtifacts: [{ Name: `${serviceName}` }],\n                  ActionTypeId: {\n                    Category: \"Build\",\n                    Owner: \"AWS\",\n                    Version: \"1\",\n                    Provider: \"CodeBuild\"\n                  },\n                  OutputArtifacts: [{ Name: `${serviceName}Build` }],\n                  Configuration: {\n                    ProjectName: {\n                      Ref: \"Build\"\n                    }\n                  },\n                  RunOrder: \"1\"\n                }\n              ]\n            }\n          ],\n          ArtifactStore: {\n            Type: \"S3\",\n            Location: { Ref: \"ServerlessDeploymentBucket\" }\n          }\n        }\n      }\n    };\n\n    _.extend(resource, role, build, pipeline);\n\n    return resource;\n  }\n}\n\nmodule.exports = CICDPlugin;\n\n//https://github.com/TheBlackTuxCorp/serverless-plugin-cicd\n"]}