<commit_before>import * as cdk from '@aws-cdk/core'
import { CfnOutput } from '@aws-cdk/core'
import { Bucket } from '@aws-cdk/aws-s3'
import { CloudFrontWebDistribution, OriginAccessIdentity, ViewerCertificate } from '@aws-cdk/aws-cloudfront'
import { User } from '@aws-cdk/aws-iam'
import { domainNames } from './domain-names'
import { Certificate } from '@aws-cdk/aws-certificatemanager'

interface WebsiteProps {
  certificateArn: string
}

export class Website extends cdk.Stack {
  constructor(scope: cdk.Construct, props: WebsiteProps) {
    super(scope, 'BrightInventionsPl')

    const originAccessIdentity = new OriginAccessIdentity(this, 'cloudfront access')
    const user = new User(this, 'GithubPagesDeploymentUser', {
      userName: 'brightinventions-pl-deployer'
    })

    const bucket = new Bucket(this, 'bucket', {
      bucketName: 'brightinventions-pl-website-content'
    })

    bucket.grantRead(originAccessIdentity)

    bucket.grantReadWrite(user)

    const certificate = Certificate.fromCertificateArn(this, 'certificate', props.certificateArn)

    const webDistribution = new CloudFrontWebDistribution(this, 'distribution', {
      originConfigs: [{
        s3OriginSource: {
          s3BucketSource: bucket,
          originAccessIdentity: originAccessIdentity
        },
        behaviors: [{
          isDefaultBehavior: true
        }]
      }],
      viewerCertificate: ViewerCertificate.fromAcmCertificate(certificate, {
        aliases: domainNames
      })
    })

    new CfnOutput(this, 'DistributionId', {
      value: webDistribution.distributionId
    })
  }
}<commit_msg>[CICD] Grant deploy user pub website access<commit_after>import * as cdk from '@aws-cdk/core'
import { CfnOutput } from '@aws-cdk/core'
import { Bucket } from '@aws-cdk/aws-s3'
import { CloudFrontWebDistribution, OriginAccessIdentity, ViewerCertificate } from '@aws-cdk/aws-cloudfront'
import { Effect, PolicyStatement, User } from '@aws-cdk/aws-iam'
import { domainNames } from './domain-names'
import { Certificate } from '@aws-cdk/aws-certificatemanager'

interface WebsiteProps {
  certificateArn: string
}

export class Website extends cdk.Stack {
  constructor(scope: cdk.Construct, props: WebsiteProps) {
    super(scope, 'BrightInventionsPl')

    const originAccessIdentity = new OriginAccessIdentity(this, 'cloudfront access')
    const user = new User(this, 'GithubPagesDeploymentUser', {
      userName: 'brightinventions-pl-deployer'
    })

    const bucket = new Bucket(this, 'bucket', {
      bucketName: 'brightinventions-pl-website-content'
    })

    bucket.grantRead(originAccessIdentity)

    bucket.grantReadWrite(user)

    user.addToPolicy(new PolicyStatement({
      actions: ['s3:PutBucketWebsite'],
      resources: [bucket.bucketArn],
      effect: Effect.ALLOW
    }))

    const certificate = Certificate.fromCertificateArn(this, 'certificate', props.certificateArn)

    const webDistribution = new CloudFrontWebDistribution(this, 'distribution', {
      originConfigs: [{
        s3OriginSource: {
          s3BucketSource: bucket,
          originAccessIdentity: originAccessIdentity
        },
        behaviors: [{
          isDefaultBehavior: true
        }]
      }],
      viewerCertificate: ViewerCertificate.fromAcmCertificate(certificate, {
        aliases: domainNames
      })
    })

    new CfnOutput(this, 'DistributionId', {
      value: webDistribution.distributionId
    })
  }
}
{'fraction_non_alphanumeric': 0.10704960835509138, 'fraction_numerical': 0.0020307513780098638, 'mean_word_length': 3.6594594594594594, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7460708', 'n_tokens_mistral': 1031, 'n_tokens_neox': 977, 'n_words': 208}