Skip to content

Instantly share code, notes, and snippets.

View cal0610's full-sized avatar

Calvin Pang cal0610

View GitHub Profile
@cal0610
cal0610 / starship.toml
Created December 6, 2022 14:37 — forked from 3ayazaya/starship.toml
My Starship terminal configuration file
#format = """
#[╭─user───❯](bold blue) $username
#[┣─system─❯](bold yellow) $hostname
#[┣─project❯](bold red) $directory$rust$git_branch$git_status$package$golang$terraform$docker_context$python$docker_context$nodejs
#[╰─cmd────❯](bold green)
#"""
[username]
style_user = "green bold"
style_root = "red bold"
format = "[$user]($style) "
@cal0610
cal0610 / find_duplicate_objects.py
Created December 4, 2022 23:01 — forked from dlinsley/find_duplicate_objects.py
Find duplicate objects in an aws s3 bucket by comparing ETag
#!/usr/bin/env python3
import boto3
import argparse
import string
parser = argparse.ArgumentParser('Find duplicate objects in an aws s3 bucket')
parser.add_argument('--bucket', dest='myBucket', default='yourBucketName', help='S3 Bucket to search')
cliArgs = parser.parse_args()
@cal0610
cal0610 / creating a store using an id token
Created November 3, 2022 03:10
cognito user pools id token
➜ ~ curl --header "Authorization: eyJraWQiOiJCS0hEUDFENlZjNlU3Sk9ad0h4dDJ5K3ptcDBkb1psaCsxSGl4MEpueWE4PSIsImFsZyI6IlJTMjU2In0.eyJhdF9oYXNoIjoiSDJTdzlJaW12ZVJ0bXUwd2lCcnhjdyIsInN1YiI6IjhiNjU1Y2M1LWVmZDQtNDBkOS1iZjIwLThkNTI4M2UyNTc4ZiIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJpc3MiOiJodHRwczpcL1wvY29nbml0by1pZHAuYXAtc291dGhlYXN0LTIuYW1hem9uYXdzLmNvbVwvYXAtc291dGhlYXN0LTJfMUVFdHp3VWEwIiwiY29nbml0bzp1c2VybmFtZSI6Im1lZGl1bS1hZG1pbi11c2VyIiwiYXVkIjoiNzVvaG9nam8xczlkZmZnbjVxczQwOGpscGMiLCJldmVudF9pZCI6IjQzNmE3MDIxLTVjMmYtNGQ4Yi05YTUzLWUzNGRhZmFlOTA0MyIsInRva2VuX3VzZSI6ImlkIiwiYXV0aF90aW1lIjoxNjY3NDQ0MDU5LCJleHAiOjE2Njc0NDc2NTksImlhdCI6MTY2NzQ0NDA1OSwianRpIjoiZjdkYmFmNzAtMWU5YS00NWQxLWFjZDMtZDBlY2M3MGUzNjkyIiwiZW1haWwiOiJtZWRpdW1AZXhhbXBsZS5jb20ifQ.SxitwSkKs7T42-gUq7JNaw-oKdlYoct8O1OrwNQx_2PoSRYbAHWoZTe2ws3x_BC_oG3PB8lpzZQxiUrC1soHBmO5yriIM34xOBqCL9rTNKCE1eUHqtPoW2DUwAzLCrJncecYl6t10K_yYQMadearS3L8_RA3cHN4-V43QNlhCQyqWBYD3GQJsxBjFuL_NJ71ca1sGahMe9sprNqk-7tEk3z_gb9_Z7IaAeZfDwlf9SHUgaVg88DEAnjFHMNgjhtm_78sPTw8MmIlyAQati55_VD_qJ
@cal0610
cal0610 / myStack.ts
Created November 2, 2022 08:34
updating the lambda to use cognito authorizer
store.addMethod('POST', createOneIntegration, { ...authorizer });
store.addMethod('GET', getAllIntegration, { ...authorizer });
const singleStore = store.addResource('{id}');
singleStore.addMethod('GET', getOneIntegration, { ...authorizer });
singleStore.addMethod('PATCH', updateOneIntegration, { ...authorizer });
singleStore.addMethod('DELETE', deleteOneIntegration, { ...authorizer });
@cal0610
cal0610 / myStack.ts
Last active November 2, 2022 15:13
creating cognito user pool, app client, and user
const userPool = new cognito.UserPool(this, 'medium-userpool', {
userPoolName: 'medium-userpool',
});
userPool.addClient('medium-client-1', {
oAuth: {
flows: {
authorizationCodeGrant: true,
},
callbackUrls: ['https://www.google.com.au/'],
@cal0610
cal0610 / myStack.ts
Created November 2, 2022 03:31
attaching an authoriser to the endpoint
store.addMethod('POST', createOneIntegration, { authorizer });
store.addMethod('GET', getAllIntegration, { authorizer });
const singleStore = store.addResource('{id}');
singleStore.addMethod('GET', getOneIntegration, { authorizer });
singleStore.addMethod('PATCH', updateOneIntegration, { authorizer });
singleStore.addMethod('DELETE', deleteOneIntegration, { authorizer });
@cal0610
cal0610 / myStack.ts
Last active November 2, 2022 03:34
lambda authoriser
const medium_username = ssm.StringParameter.fromStringParameterName(this, 'medium_username', 'medium_username');
const medium_password = ssm.StringParameter.fromStringParameterName(this, 'medium_password', 'medium_password');
const authorizerFn = new NodejsFunction(this, 'BasicAuthAuthorizer', {
entry: join(__dirname, '..', 'lambda', '/authorizer.ts'),
handler: 'authorizer',
environment: {
medium_username: medium_username.stringValue,
medium_password: medium_password.stringValue,
},
@cal0610
cal0610 / authorizer.ts
Last active November 2, 2022 03:21
token authorizer
import { APIGatewayTokenAuthorizerHandler } from 'aws-lambda';
export const authorizer: APIGatewayTokenAuthorizerHandler = async (
event: any
) => {
const token = event.authorizationToken;
let effect = 'Deny';
if (
compareTokenWithCredentials(
curl -X POST https://fp5l1e7iwl.execute-api.ap-southeast-2.amazonaws.com/dev/store -H "Content-Type: application/json" -d '{"store_name":"yellow store","store_description":"my awesome store"}'
new cdk.CfnOutput(this, 'apiUrl', {value: api.url});