diff --git a/.github/workflows/aws-ec2-deploy-staging.yml b/.github/workflows/aws-deploy.yml similarity index 93% rename from .github/workflows/aws-ec2-deploy-staging.yml rename to .github/workflows/aws-deploy.yml index 2ec68c3..e96fd08 100644 --- a/.github/workflows/aws-ec2-deploy-staging.yml +++ b/.github/workflows/aws-deploy.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}} \ @@ -66,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_SECONDS=${{vars.TOKEN_VALIDITY_IN_SECONDS}} \ + -e USER_MAX_URL_COUNT=${{vars.USER_MAX_URL_COUNT}} \ ${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }} 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..d545b2b --- /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 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 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