From e735a6c68f0b7836258be5e78f0fe7e0e6bcf42a Mon Sep 17 00:00:00 2001 From: Vinit khandal <111434418+vinit717@users.noreply.github.com> Date: Mon, 1 Jul 2024 00:14:38 +0530 Subject: [PATCH 1/6] FIX url count migration (#106) * fix: url count migration * made capital the users tbale name --- cmd/bun/migrations/20240215113820_initial-setup.up.sql | 1 - cmd/bun/migrations/20240630181359_add_url_count.up.sql | 9 +++++++++ .../migrations/20240630181359_remove_url_count.down.sql | 7 +++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 cmd/bun/migrations/20240630181359_add_url_count.up.sql create mode 100644 cmd/bun/migrations/20240630181359_remove_url_count.down.sql diff --git a/cmd/bun/migrations/20240215113820_initial-setup.up.sql b/cmd/bun/migrations/20240215113820_initial-setup.up.sql index af192e6..ce37feb 100644 --- a/cmd/bun/migrations/20240215113820_initial-setup.up.sql +++ b/cmd/bun/migrations/20240215113820_initial-setup.up.sql @@ -12,7 +12,6 @@ CREATE TABLE users ( updated_at timestamp DEFAULT (NOW() AT TIME ZONE 'UTC'), is_deleted boolean DEFAULT false, is_onboarding BOOLEAN NOT NULL DEFAULT TRUE - url_count int NOT NULL DEFAULT 0 ); --bun:split diff --git a/cmd/bun/migrations/20240630181359_add_url_count.up.sql b/cmd/bun/migrations/20240630181359_add_url_count.up.sql new file mode 100644 index 0000000..6890393 --- /dev/null +++ b/cmd/bun/migrations/20240630181359_add_url_count.up.sql @@ -0,0 +1,9 @@ +BEGIN; + +--bun:split + +ALTER TABLE USERS ADD url_count bool int NOT NULL DEFAULT 0; + +--bun:split + +COMMIT; \ No newline at end of file diff --git a/cmd/bun/migrations/20240630181359_remove_url_count.down.sql b/cmd/bun/migrations/20240630181359_remove_url_count.down.sql new file mode 100644 index 0000000..1eff067 --- /dev/null +++ b/cmd/bun/migrations/20240630181359_remove_url_count.down.sql @@ -0,0 +1,7 @@ +BEGIN; +--bun:split + +ALTER TABLE USERS DROP COLUMN url_count; +--bun:split + +COMMIT; \ No newline at end of file From 918e7c9f994d054a232328a15252cc72c565aa25 Mon Sep 17 00:00:00 2001 From: Vinit khandal <111434418+vinit717@users.noreply.github.com> Date: Mon, 1 Jul 2024 13:08:11 +0530 Subject: [PATCH 2/6] Bug url count migration (#109) * fix: url count migration * made capital the users tbale name * remove bool from url_count migration script --- cmd/bun/migrations/20240630181359_add_url_count.up.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/bun/migrations/20240630181359_add_url_count.up.sql b/cmd/bun/migrations/20240630181359_add_url_count.up.sql index 6890393..d545b2b 100644 --- a/cmd/bun/migrations/20240630181359_add_url_count.up.sql +++ b/cmd/bun/migrations/20240630181359_add_url_count.up.sql @@ -2,7 +2,7 @@ BEGIN; --bun:split -ALTER TABLE USERS ADD url_count bool int NOT NULL DEFAULT 0; +ALTER TABLE USERS ADD url_count int NOT NULL DEFAULT 0; --bun:split From 43026617e49e48e10880cb611d0433e2355ffc74 Mon Sep 17 00:00:00 2001 From: Prakash Choudhary <34452139+prakashchoudhary07@users.noreply.github.com> Date: Mon, 1 Jul 2024 21:16:37 +0530 Subject: [PATCH 3/6] feat: pass env as param (#111) --- .github/workflows/aws-ec2-deploy-staging.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/aws-ec2-deploy-staging.yml b/.github/workflows/aws-ec2-deploy-staging.yml index 2ec68c3..2c8e0a2 100644 --- a/.github/workflows/aws-ec2-deploy-staging.yml +++ b/.github/workflows/aws-ec2-deploy-staging.yml @@ -51,6 +51,7 @@ jobs: docker run -d -p ${{vars.PORT}}:${{vars.PORT}} \ --name ${{ github.event.repository.name }}-${{vars.ENV}} \ --network=${{vars.DOCKER_NETWORK}} \ + -e ENV=${{vars.ENV}} \ -e GIN_MODE=${{vars.GIN_MODE}} \ -e JWT_SECRET=${{secrets.JWT_SECRET}} \ -e JWT_VALIDITY_IN_HOURS=${{vars.JWT_VALIDITY_IN_HOURS}} \ From aec9d9a0bb3f209a45113acf797b01df9ae4ebf8 Mon Sep 17 00:00:00 2001 From: Vinit khandal <111434418+vinit717@users.noreply.github.com> Date: Sat, 13 Jul 2024 00:32:37 +0530 Subject: [PATCH 4/6] Fix env naming convention (#112) * fix env naming * fix variable naming * fix test env for failing test * fix test and dev env * chore: change dev env --- config/core-config.go | 8 ++++---- controllers/auth.go | 2 +- controllers/url.go | 4 ++-- environments/test.env | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/config/core-config.go b/config/core-config.go index e3df1f2..9b9f039 100644 --- a/config/core-config.go +++ b/config/core-config.go @@ -12,7 +12,7 @@ import ( var ( Env string - MaxUrlCount int + UserMaxUrlCount int Domain string AuthRedirectUrl string DbUrl string @@ -20,7 +20,7 @@ var ( GoogleClientId string GoogleClientSecret string GoogleRedirectUrl string - TokenExpiration int + TokenValidity int JwtSecret string JwtValidity int JwtIssuer string @@ -96,8 +96,8 @@ func loadConfig() { GoogleClientSecret = getEnvVar("GOOGLE_CLIENT_SECRET") GoogleRedirectUrl = getEnvVar("GOOGLE_REDIRECT_URL") - MaxUrlCount = getEnvInt("Max_Url_Count") - TokenExpiration = getEnvInt("TokenExpiration") + UserMaxUrlCount = getEnvInt("USER_MAX_URL_COUNT") + TokenValidity = getEnvInt("TOKEN_VALIDITY_IN_SECONDS") AllowedOrigin = getEnvVar("ALLOWED_ORIGINS") diff --git a/controllers/auth.go b/controllers/auth.go index 441b013..fb24210 100644 --- a/controllers/auth.go +++ b/controllers/auth.go @@ -121,7 +121,7 @@ func GoogleCallback(ctx *gin.Context, db *bun.DB) { ctx.JSON(http.StatusInternalServerError, gin.H{"message": "error"}) return } - ctx.SetCookie("token", token, config.TokenExpiration, "/", domain, true, true) + ctx.SetCookie("token", token, config.TokenValidity, "/", domain, true, true) ctx.Redirect(http.StatusFound, authRedirectUrl) } diff --git a/controllers/url.go b/controllers/url.go index ceea4b7..0dd0962 100644 --- a/controllers/url.go +++ b/controllers/url.go @@ -87,9 +87,9 @@ func CreateTinyURL(ctx *gin.Context, db *bun.DB) { return } - if count >= config.MaxUrlCount { + if count >= config.UserMaxUrlCount { ctx.JSON(http.StatusForbidden, dtos.URLCreationResponse{ - Message: "You've reached the limit of " + strconv.Itoa(config.MaxUrlCount) + " for URLs. Delete one to add a new one !!", + Message: "You've reached the limit of " + strconv.Itoa(config.UserMaxUrlCount) + " for URLs. Delete one to add a new one !!", }) return } diff --git a/environments/test.env b/environments/test.env index d8ec492..53ac240 100644 --- a/environments/test.env +++ b/environments/test.env @@ -14,7 +14,7 @@ GOOGLE_CLIENT_ID="google-client-id" GOOGLE_CLIENT_SECRET="google-client-secret" GOOGLE_REDIRECT_URL="http://localhost:8000/v1/auth/google/callback" -Max_Url_Count=10 -TokenExpiration=3600 +USER_MAX_URL_COUNT=10 +TOKEN_VALIDITY_IN_SECONDS=3600 ALLOWED_ORIGINS=* PORT=8000 \ No newline at end of file From 052d12d756e5f712a7251462fa71f1a74b40ab97 Mon Sep 17 00:00:00 2001 From: Prakash Choudhary <34452139+prakashchoudhary07@users.noreply.github.com> Date: Sat, 13 Jul 2024 00:37:51 +0530 Subject: [PATCH 5/6] ci: add env (#115) --- .../workflows/{aws-ec2-deploy-staging.yml => aws-deploy.yml} | 2 ++ 1 file changed, 2 insertions(+) rename .github/workflows/{aws-ec2-deploy-staging.yml => aws-deploy.yml} (95%) diff --git a/.github/workflows/aws-ec2-deploy-staging.yml b/.github/workflows/aws-deploy.yml similarity index 95% rename from .github/workflows/aws-ec2-deploy-staging.yml rename to .github/workflows/aws-deploy.yml index 2c8e0a2..e6c87d4 100644 --- a/.github/workflows/aws-ec2-deploy-staging.yml +++ b/.github/workflows/aws-deploy.yml @@ -67,4 +67,6 @@ jobs: -e GOOGLE_CLIENT_SECRET=${{secrets.GOOGLE_CLIENT_SECRET}} \ -e GOOGLE_REDIRECT_URL=${{vars.GOOGLE_REDIRECT_URL}} \ -e ALLOWED_ORIGINS=${{vars.ALLOWED_ORIGINS}} \ + -e TOKEN_VALIDITY_IN_SECOND=${{vars.TOKEN_VALIDITY_IN_SECOND}} \ + -e USER_MAX_URL_COUNT=${{vars.USER_MAX_URL_COUNT}} \ ${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }} From b5c89e5a5808359dfb53b8540240ee474ad10ec2 Mon Sep 17 00:00:00 2001 From: Prakash Choudhary <34452139+prakashchoudhary07@users.noreply.github.com> Date: Wed, 17 Jul 2024 16:01:39 +0530 Subject: [PATCH 6/6] chore: fix spelling (#118) --- .github/workflows/aws-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/aws-deploy.yml b/.github/workflows/aws-deploy.yml index e6c87d4..e96fd08 100644 --- a/.github/workflows/aws-deploy.yml +++ b/.github/workflows/aws-deploy.yml @@ -67,6 +67,6 @@ jobs: -e GOOGLE_CLIENT_SECRET=${{secrets.GOOGLE_CLIENT_SECRET}} \ -e GOOGLE_REDIRECT_URL=${{vars.GOOGLE_REDIRECT_URL}} \ -e ALLOWED_ORIGINS=${{vars.ALLOWED_ORIGINS}} \ - -e TOKEN_VALIDITY_IN_SECOND=${{vars.TOKEN_VALIDITY_IN_SECOND}} \ + -e TOKEN_VALIDITY_IN_SECONDS=${{vars.TOKEN_VALIDITY_IN_SECONDS}} \ -e USER_MAX_URL_COUNT=${{vars.USER_MAX_URL_COUNT}} \ ${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}