Skip to content

Commit

Permalink
Merge pull request #3 from capralifecycle/cals-800/update-example-pro…
Browse files Browse the repository at this point in the history
…ject

Update and test example project
  • Loading branch information
joakimen authored Jun 7, 2024
2 parents 28d77cb + 810e55e commit 78129b2
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 148 deletions.
28 changes: 14 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@ jobs:
- name: prepare
run: npm run test

# - name: example project - npm pack
# run: npm pack
#
# - name: example project - npm ci
# working-directory: example
# run: npm ci
#
# - name: example project - npm install
# working-directory: example
# run: npm install --no-save ../liflig-cdk-cloudfront-auth-0.0.0-development.tgz
#
# - name: example project - npm test
# run: npm run test
# working-directory: example
- name: example project - npm pack
run: npm pack

- name: example project - npm ci
working-directory: example
run: npm ci

- name: example project - npm install
working-directory: example
run: npm install --no-save ../liflig-cdk-cloudfront-auth-0.0.0-development.tgz

- name: example project - npm test
run: npm run test
working-directory: example

- name: conditionally semantic release
if: ${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
Expand Down
30 changes: 15 additions & 15 deletions example/lib/auth-lambdas-stack.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// import { AuthLambdas } from "@liflig/cdk-cloudfront-auth"
// import * as cdk from "aws-cdk-lib"
// import { Construct } from "constructs"
//
// export class AuthLambdasStack extends cdk.Stack {
// readonly authLambdas: AuthLambdas
//
// constructor(scope: Construct, id: string, props?: cdk.StackProps) {
// super(scope, id, props)
//
// this.authLambdas = new AuthLambdas(this, "AuthLambdas", {
// regions: ["eu-west-1"],
// })
// }
// }
import { AuthLambdas } from "@liflig/cdk-cloudfront-auth"
import * as cdk from "aws-cdk-lib"
import { Construct } from "constructs"

export class AuthLambdasStack extends cdk.Stack {
readonly authLambdas: AuthLambdas

constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props)

this.authLambdas = new AuthLambdas(this, "AuthLambdas", {
regions: ["eu-west-1"],
})
}
}
162 changes: 81 additions & 81 deletions example/lib/main-stack.ts
Original file line number Diff line number Diff line change
@@ -1,81 +1,81 @@
// import { AuthLambdas, CloudFrontAuth } from "@liflig/cdk-cloudfront-auth"
// import * as cdk from "aws-cdk-lib"
// import * as cloudfront from "aws-cdk-lib/aws-cloudfront"
// import * as origins from "aws-cdk-lib/aws-cloudfront-origins"
// import * as cognito from "aws-cdk-lib/aws-cognito"
// import * as s3 from "aws-cdk-lib/aws-s3"
// import * as s3Deployment from "aws-cdk-lib/aws-s3-deployment"
// import * as constructs from "constructs"
// import { CognitoUser } from "./cognito-user"
//
// interface Props extends cdk.StackProps {
// authLambdas: AuthLambdas
// }
//
// export class MainStack extends cdk.Stack {
// constructor(scope: constructs.Construct, id: string, props: Props) {
// super(scope, id, props)
//
// const bucket = new s3.Bucket(this, "Bucket")
//
// const userPool = new cognito.UserPool(this, "UserPool", {
// signInAliases: {
// email: true,
// },
// passwordPolicy: {
// minLength: 6,
// requireSymbols: false,
// requireUppercase: false,
// },
// signInCaseSensitive: false,
// })
//
// const domainPrefix = `${this.account}-${this.stackName}`
//
// userPool.addDomain("UserPoolDomain", {
// cognitoDomain: {
// domainPrefix,
// },
// })
//
// const auth = new CloudFrontAuth(this, "Auth", {
// cognitoAuthDomain: `${domainPrefix}.auth.${this.region}.amazoncognito.com`,
// authLambdas: props.authLambdas,
// userPool,
// requireGroupAnyOf: ["test"],
// })
//
// const origin = new origins.S3Origin(bucket)
//
// const distribution = new cloudfront.Distribution(this, "Distribution", {
// defaultBehavior: auth.createProtectedBehavior(origin),
// additionalBehaviors: auth.createAuthPagesBehaviors(origin),
// defaultRootObject: "index.html",
// })
//
// auth.updateClient("ClientUpdate", {
// signOutUrl: `https://${distribution.distributionDomainName}${auth.signOutRedirectTo}`,
// callbackUrl: `https://${distribution.distributionDomainName}${auth.callbackPath}`,
// })
//
// new s3Deployment.BucketDeployment(this, "BucketDeployment", {
// sources: [s3Deployment.Source.asset("./website")],
// destinationBucket: bucket,
// distribution,
// })
//
// new CognitoUser(this, "User", {
// userPool,
// email: "[email protected]",
// password: "example",
// })
//
// new cdk.CfnOutput(this, "UrlOutput", {
// value: `https://${distribution.domainName}`,
// })
//
// new cdk.CfnOutput(this, "BucketNameOutput", {
// value: bucket.bucketName,
// })
// }
// }
import { AuthLambdas, CloudFrontAuth } from "@liflig/cdk-cloudfront-auth"
import * as cdk from "aws-cdk-lib"
import * as cloudfront from "aws-cdk-lib/aws-cloudfront"
import * as origins from "aws-cdk-lib/aws-cloudfront-origins"
import * as cognito from "aws-cdk-lib/aws-cognito"
import * as s3 from "aws-cdk-lib/aws-s3"
import * as s3Deployment from "aws-cdk-lib/aws-s3-deployment"
import * as constructs from "constructs"
import { CognitoUser } from "./cognito-user"

interface Props extends cdk.StackProps {
authLambdas: AuthLambdas
}

export class MainStack extends cdk.Stack {
constructor(scope: constructs.Construct, id: string, props: Props) {
super(scope, id, props)

const bucket = new s3.Bucket(this, "Bucket")

const userPool = new cognito.UserPool(this, "UserPool", {
signInAliases: {
email: true,
},
passwordPolicy: {
minLength: 6,
requireSymbols: false,
requireUppercase: false,
},
signInCaseSensitive: false,
})

const domainPrefix = `${this.account}-${this.stackName}`

userPool.addDomain("UserPoolDomain", {
cognitoDomain: {
domainPrefix,
},
})

const auth = new CloudFrontAuth(this, "Auth", {
cognitoAuthDomain: `${domainPrefix}.auth.${this.region}.amazoncognito.com`,
authLambdas: props.authLambdas,
userPool,
requireGroupAnyOf: ["test"],
})

const origin = new origins.S3Origin(bucket)

const distribution = new cloudfront.Distribution(this, "Distribution", {
defaultBehavior: auth.createProtectedBehavior(origin),
additionalBehaviors: auth.createAuthPagesBehaviors(origin),
defaultRootObject: "index.html",
})

auth.updateClient("ClientUpdate", {
signOutUrl: `https://${distribution.distributionDomainName}${auth.signOutRedirectTo}`,
callbackUrl: `https://${distribution.distributionDomainName}${auth.callbackPath}`,
})

new s3Deployment.BucketDeployment(this, "BucketDeployment", {
sources: [s3Deployment.Source.asset("./website")],
destinationBucket: bucket,
distribution,
})

new CognitoUser(this, "User", {
userPool,
email: "[email protected]",
password: "example",
})

new cdk.CfnOutput(this, "UrlOutput", {
value: `https://${distribution.domainName}`,
})

new cdk.CfnOutput(this, "BucketNameOutput", {
value: bucket.bucketName,
})
}
}
74 changes: 37 additions & 37 deletions example/package-lock.json

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

2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"typescript": "4.9.5"
},
"dependencies": {
"@liflig/cdk-cloudfront-auth": "^2",
"@liflig/cdk-cloudfront-auth": "1.0.0",
"aws-cdk-lib": "^2",
"source-map-support": "^0.5"
}
Expand Down

0 comments on commit 78129b2

Please sign in to comment.