added cognito initial config

This commit is contained in:
2020-09-12 15:04:39 +09:00
parent 41c9bdafaf
commit aa71a7a3cc
5 changed files with 125 additions and 12 deletions

View File

@@ -1,32 +1,63 @@
#!/bin/sh #!/bin/sh
# create folder to pack all
echo "Starting build process..."
mkdir build mkdir build
cd main-web/client
npm run build # build janken tool and move
cd ../../
mv main-web/client/client build
cd tools/janken cd tools/janken
echo "Starting janken tool build..."
npm run build npm run build
cd ../../ cd ../../
mv tools/janken/tool build mv tools/janken/tool build
echo "Finished janken tool build..."
# build client and move
cd main-web/client
echo "Starting client build..."
npm run build
cd ../../
mv main-web/client/client build
echo "Finished client build..."
# build admin and move
cd main-web/admin
echo "Starting admin ui build..."
npm run build
cd ../../
mv main-web/admin/build build/admin
echo "Finished admin ui build..."
# build server and move
cd main-web/server cd main-web/server
echo "Starting server build..."
npm run build npm run build
cd ../../ cd ../../
cd build/ cd build/
echo "Starting retrieval of db credentials..."
export catherine_db_endpoint=$(aws --region=ap-northeast-1 ssm get-parameter --name "db-endpoint" --with-decryption --output text --query Parameter.Value) export catherine_db_endpoint=$(aws --region=ap-northeast-1 ssm get-parameter --name "db-endpoint" --with-decryption --output text --query Parameter.Value)
export catherine_db_user=$(aws --region=ap-northeast-1 ssm get-parameter --name "db-username" --with-decryption --output text --query Parameter.Value) export catherine_db_user=$(aws --region=ap-northeast-1 ssm get-parameter --name "db-username" --with-decryption --output text --query Parameter.Value)
export catherine_db_pass=$(aws --region=ap-northeast-1 ssm get-parameter --name "db-password" --with-decryption --output text --query Parameter.Value) export catherine_db_pass=$(aws --region=ap-northeast-1 ssm get-parameter --name "db-password" --with-decryption --output text --query Parameter.Value)
echo "Saving db credentials to .env file..."
cat > .env <<EOL cat > .env <<EOL
DB_ENDPOINT=${catherine_db_endpoint} DB_ENDPOINT=${catherine_db_endpoint}
DB_USER=${catherine_db_user} DB_USER=${catherine_db_user}
DB_PASS=${catherine_db_pass} DB_PASS=${catherine_db_pass}
EOL EOL
cd ../ cd ../
cp main-web/server/.env build/
cp main-web/server/package.json build/ cp main-web/server/package.json build/
cp main-web/server/tsconfig.json build/ cp main-web/server/tsconfig.json build/
cp main-web/server/tslint.json build/ cp main-web/server/tslint.json build/
mv main-web/server/build build/server mv main-web/server/build build/server
echo "Finished server build..."
echo "Compressing all files..."
tar czf build.tar.gz build/ tar czf build.tar.gz build/
echo "Finished compressing all files..."
echo "Removing workfolder..."
rm -rf build/ rm -rf build/
aws s3 cp build.tar.gz s3://catherine-fc-infra/ echo "Removed workfolder..."
echo "Upload built files to s3..."
aws s3 cp build.tar.gz s3://catherine-fc-infra/
echo "Finished build process..."

View File

@@ -0,0 +1,23 @@
resource "aws_cognito_user_pool" "catherine_fc_admin_cognito_pool" {
name = "catherine-fc-admin"
admin_create_user_config {
allow_admin_create_user_only = true
}
}
resource "aws_cognito_user_pool_client" "catherine_fc_admin_cognito_pool_client" {
name = "catherine-fc-admin-client"
user_pool_id = aws_cognito_user_pool.catherine_fc_admin_cognito_pool.id
allowed_oauth_flows = ["code","implicit"]
allowed_oauth_scopes = ["email", "openid"]
callback_urls = ["https://www.catherine-fc.com","https://catherine-fc.com"]
allowed_oauth_flows_user_pool_client = true
generate_secret = true
explicit_auth_flows = ["USER_PASSWORD_AUTH"]
}
resource "aws_cognito_user_pool_domain" "catherine_fc_admin_cognito_pool_domain" {
domain = "catherine-fc-admin-domain"
user_pool_id = aws_cognito_user_pool.catherine_fc_admin_cognito_pool.id
}

View File

@@ -20,4 +20,58 @@ resource "aws_lb_listener" "catherine_fc_load_balancer_listener" {
type = "forward" type = "forward"
target_group_arn = aws_lb_target_group.target_group_web.arn target_group_arn = aws_lb_target_group.target_group_web.arn
} }
} }
resource "aws_lb_listener_rule" "catherine_fc_alb_listener_admin" {
listener_arn = aws_lb_listener.catherine_fc_load_balancer_listener.arn
priority = 1
action {
type = "authenticate-cognito"
authenticate_cognito {
user_pool_arn = aws_cognito_user_pool.catherine_fc_admin_cognito_pool.arn
user_pool_client_id = aws_cognito_user_pool_client.catherine_fc_admin_cognito_pool_client.id
user_pool_domain = aws_cognito_user_pool_domain.catherine_fc_admin_cognito_pool_domain.domain
on_unauthenticated_request = "authenticate"
session_cookie_name = "CatherineFCAdmin"
session_timeout = 86400
}
}
action {
type = "forward"
target_group_arn = aws_lb_target_group.target_group_web.arn
}
condition {
path_pattern {
values = ["/admin*"]
}
}
}
resource "aws_lb_listener_rule" "catherine_fc_alb_listener_admin_api" {
listener_arn = aws_lb_listener.catherine_fc_load_balancer_listener.arn
priority = 2
action {
type = "authenticate-cognito"
authenticate_cognito {
user_pool_arn = aws_cognito_user_pool.catherine_fc_admin_cognito_pool.arn
user_pool_client_id = aws_cognito_user_pool_client.catherine_fc_admin_cognito_pool_client.id
user_pool_domain = aws_cognito_user_pool_domain.catherine_fc_admin_cognito_pool_domain.domain
on_unauthenticated_request = "deny"
session_cookie_name = "CatherineFCAdmin"
session_timeout = 86400
}
}
action {
type = "forward"
target_group_arn = aws_lb_target_group.target_group_web.arn
}
condition {
path_pattern {
values = ["/api/admin*"]
}
}
}

View File

@@ -1,11 +1,16 @@
import React, { FunctionComponent } from 'react'; import React, { FunctionComponent } from 'react';
import style from '../web.module.scss'; import style from '../web.module.scss';
import YouTube from 'react-youtube';
type ComponentProps = { type ComponentProps = {
}; };
export const Home: FunctionComponent<ComponentProps> = (props): JSX.Element => { export const Home: FunctionComponent<ComponentProps> = (props): JSX.Element => {
const opts = {
height: '696',
width: '1024'
};
return ( return (
<div className={style.mainBody}> <div className={style.mainBody}>
<div className={style.chalice} /> <div className={style.chalice} />
@@ -16,11 +21,10 @@ export const Home: FunctionComponent<ComponentProps> = (props): JSX.Element => {
<div className={style.twitchHome}> <div className={style.twitchHome}>
<a href='https://www.twitch.tv/catherine_faito_crab' rel='noopener noreferrer' target='_blank'>&nbsp;</a> <a href='https://www.twitch.tv/catherine_faito_crab' rel='noopener noreferrer' target='_blank'>&nbsp;</a>
</div> </div>
<div className={style.players0801} /> <YouTube
<div className={style.players0802} /> videoId={'oetCaugzOew'}
<div className={style.players0808} /> opts={opts}
<div className={style.players0809} /> />
<div className={style.players0815} />
</div> </div>
); );
}; };

View File

@@ -141,6 +141,7 @@ app.get('/api/contact', (req: any, res: any) => {
); );
}); });
app.use('/admin', express.static('admin'));
app.use('/players', express.static('client')); app.use('/players', express.static('client'));
app.use('/tournaments*', express.static('client')); app.use('/tournaments*', express.static('client'));
app.use('/about', express.static('client')); app.use('/about', express.static('client'));