-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Readme file updated along with other validations #42
Changes from all commits
9ac225e
43ad83d
79ce5f0
44803b2
452a65c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
SECRET_KEY=your_secret_key | ||
# Database Configuration | ||
DB_NAME= | ||
DB_HOSTNAME=localhost | ||
DB_PORT=3306 | ||
DB_USERNAME= | ||
DB_PASSWORD= | ||
DB_HOSTNAME= | ||
DB_PORT= | ||
DB_NAME= | ||
SECRET_KEY= | ||
REDIS_URL= | ||
DB_ROOT_PASSWORD= | ||
# Additional Configuration | ||
REDIS_URL=redis://localhost:6379/ | ||
SENTRY_DSN= | ||
SLACK_WEBHOOK_URL= | ||
ENVIRONMENT_NAME= | ||
DB_ROOT_PASSWORD= //this is applicable for .env.local file only | ||
// you will get these data from signoz portal | ||
# Advance Usage - Signoz Configuration | ||
OTEL_RESOURCE_ATTRIBUTES= | ||
OTEL_EXPORTER_OTLP_ENDPOINT= | ||
OTEL_EXPORTER_OTLP_HEADERS= | ||
OTEL_EXPORTER_OTLP_PROTOCOL= | ||
CACHE_ENABLED= | ||
SENTRY_ENABLED= | ||
SLACK_ENABLED= | ||
# Docker Configuration | ||
ENVIRONMENT_NAME= |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,28 +11,29 @@ class DBSettings(BaseSettings): | |
DB_PASSWORD: str | ||
|
||
class Config: | ||
env_file = ".env" | ||
env_file = ".env.local" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dont harcode. .env.local keep it .env.${environment_name} i mean to say this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey, for it take the environment name it has to go to .env file and for it to go to environment file it has to know the .env file. It's not gonna work as it's a circular thing. We can have some sort of hack here tho but that's not gonna remain a standard base file Also please go through the hierarchy pattern I've mentioned. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reference link please There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
|
||
class FlagFeatureSettings(BaseSettings): | ||
CACHE_ENABLED: bool | ||
SENTRY_ENABLED: bool = False | ||
SLACK_ENABLED: bool = False | ||
|
||
class Config: | ||
env_file = ".env" | ||
|
||
|
||
class Settings(FlagFeatureSettings, DBSettings): | ||
class Settings(DBSettings): | ||
SECRET_KEY: str | ||
REDIS_URL: str | ||
SENTRY_DSN: str | None | ||
SLACK_WEBHOOK_URL: str | ||
SLACK_WEBHOOK_URL: str | None | ||
ALLOWED_HOSTS: list = ["*"] | ||
CACHE_MAX_AGE: int = 60 | ||
|
||
class Config: | ||
env_file = ".env" | ||
env_file = ".env.local" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
|
||
def check_environment_variables(self): | ||
if not self.DB_HOSTNAME or not self.DB_PORT or not self.DB_NAME or not self.DB_USERNAME or not self.DB_PASSWORD: | ||
raise ValueError("Database environment variables are not set") | ||
|
||
if not self.SECRET_KEY: | ||
raise ValueError("SECRET_KEY is not set") | ||
|
||
if not self.REDIS_URL: | ||
raise ValueError("REDIS_URL is not set") | ||
|
||
|
||
class CachedEndpoints(BaseSettings): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,24 @@ | ||
from __future__ import annotations | ||
|
||
from app.config.base import settings | ||
from app.config.redis_config import get_redis_pool | ||
|
||
|
||
class CacheUtils: | ||
CACHE_ENABLED = settings.CACHE_ENABLED | ||
|
||
@classmethod | ||
async def create_cache(cls, resp, key: str, ex: int = 60): | ||
if cls.CACHE_ENABLED: | ||
redis = await get_redis_pool() | ||
await redis.set(key, resp, ex=ex) | ||
redis = await get_redis_pool() | ||
await redis.set(key, resp, ex=ex) | ||
|
||
@classmethod | ||
async def retrieve_cache(cls, key: str): | ||
if cls.CACHE_ENABLED: | ||
redis = await get_redis_pool() | ||
data = await redis.get(key) | ||
if not data: | ||
return None, None | ||
expire = await redis.ttl(key) | ||
return data, expire | ||
return None, None | ||
redis = await get_redis_pool() | ||
data = await redis.get(key) | ||
if not data: | ||
return None, None | ||
expire = await redis.ttl(key) | ||
return data, expire | ||
|
||
@classmethod | ||
async def invalidate_cache(cls, key: str): | ||
if cls.CACHE_ENABLED: | ||
redis = await get_redis_pool() | ||
await redis.delete(key) | ||
return None | ||
redis = await get_redis_pool() | ||
await redis.delete(key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how will it behave with .env.docker file Add a comment here please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, I researched a bit and found out that each env file is unique.
And so by the previous '.env', your docker wouldn't work cause if you'll check your compose file it is .env.${environment_name} now in any case it will never be .env and docker won't work and so I've standardized it and fixed your docker error too.
Here's you can repro the uniqueness,
change your .env file to .env.local in your current code and run it.
Also there is a hierarchy of it:
Here's the priority of the files for the development build and the production build:
Dev.: (npm start): .env.development.local, .env.local, .env.development, .env
Prod.: (npm run build): .env.production.local, .env.local, .env.production, .env
And so by this .env.local is pretty standard and solves your compose problem too