Skip to content
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

fix(env): convert all env vars to SCREAMING_CASE from camelCase #335

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/api/env/.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AKASHLYTICS_CORS_WEBSITE_URLS=https://cloudmos.io,https://www.cloudmos.io,http://debug.cloudmos.io,https://deploy.cloudmos.io,https://beta.cloudmos.io,https://stats.akash.network,https://console.akash.network,https://akash.network,https://akash.hooman.digital,http://localhost:3000,http://localhost:3001,https://beta2.cloudmos.io,https://beta3.cloudmos.io,https://akashconsole.vercel.app,https://console-beta.akash.network
WebsiteUrl=https://console-beta.akash.network
WEBSITE_URL=https://console-beta.akash.network
TRIAL_DEPLOYMENT_ALLOWANCE_AMOUNT=10000000
DEPLOYMENT_ALLOWANCE_REFILL_AMOUNT=10000000
DEPLOYMENT_ALLOWANCE_REFILL_THRESHOLD=1000000
Expand Down
4 changes: 2 additions & 2 deletions apps/api/env/.env.functional.test
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AkashSandboxDatabaseCS=postgres://postgres:password@localhost:5432/console-akash-sandbox
UserDatabaseCS=postgres://postgres:password@localhost:5432/console-users
AKASH_SANDBOX_DATABASE_CS=postgres://postgres:password@localhost:5432/console-akash-sandbox
USER_DATABASE_CS=postgres://postgres:password@localhost:5432/console-users
POSTGRES_DB_URI=postgres://postgres:password@localhost:5432/console-users
MASTER_WALLET_MNEMONIC="motion isolate mother convince snack twenty tumble boost elbow bundle modify balcony"
NETWORK=sandbox
Expand Down
8 changes: 4 additions & 4 deletions apps/api/env/.env.production
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Auth0JWKSUri=https://cloudmos-prod.us.auth0.com/.well-known/jwks.json
Auth0Audience=https://api.cloudmos.io
Auth0Issuer=https://auth.cloudmos.io/
AUTH0_JWKS_URI=https://cloudmos-prod.us.auth0.com/.well-known/jwks.json
AUTH0_AUDIENCE=https://api.cloudmos.io
AUTH0_ISSUER=https://auth.cloudmos.io/
PORT=80
ServerOrigin=https://api.cloudmos.io
SERVER_ORIGIN=https://api.cloudmos.io
DRIZZLE_MIGRATIONS_FOLDER=./dist/drizzle
SENTRY_ENABLED=true
BILLING_ENABLED=false
Expand Down
21 changes: 10 additions & 11 deletions apps/api/env/.env.sample
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
# Secrets
AkashDatabaseCS=
AkashlyticsGithubPAT=
AKASH_DATABASE_CS=
AKASHLYTICS_GITHUB_PAT=
ANONYMOUS_USER_TOKEN_SECRET=
HealthChecks_SyncAKTMarketData=
MASTER_WALLET_MNEMONIC=
POSTGRES_DB_URI=
SecretToken=
SentryDSN=
SECRET_TOKEN=
SENTRY_DSN=
UserDatabaseCS=
STRIPE_SECRET_KEY=
STRIPE_PRICE_ID=
USER_DATABASE_CS=

# Configuration
AKASHLYTICS_CORS_WEBSITE_URLS=
Auth0Audience=
Auth0Issuer=
Auth0JWKSUri=
AUTH0_AUDIENCE=
AUTH0_ISSUER=
AUTH0_JWKS_URI=
BILLING_ENABLED=
DEPLOYMENT_ALLOWANCE_REFILL_AMOUNT=
DEPLOYMENT_ALLOWANCE_REFILL_THRESHOLD=
Expand All @@ -25,7 +24,7 @@ DEPLOYMENT_GRANT_DENOM=
DRIZZLE_MIGRATIONS_FOLDER=
FEE_ALLOWANCE_REFILL_AMOUNT=
FEE_ALLOWANCE_REFILL_THRESHOLD=
HealthchecksEnabled=
HEALTHCHECKS_ENABLED=
LOG_LEVEL=
NETWORK=
PORT=
Expand All @@ -34,7 +33,7 @@ SENTRY_ENABLED=
SENTRY_SERVER_NAME=
SentryServerName=
SENTRY_TRACES_RATE=
ServerOrigin=
SERVER_ORIGIN=
TRIAL_DEPLOYMENT_ALLOWANCE_AMOUNT=
TRIAL_FEES_ALLOWANCE_AMOUNT=
WebsiteUrl=
WEBSITE_URL=
8 changes: 4 additions & 4 deletions apps/api/env/.env.staging
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
ServerOrigin=https://api-sandbox.cloudmos.io
SERVER_ORIGIN=https://api-sandbox.cloudmos.io
DRIZZLE_MIGRATIONS_FOLDER=./dist/drizzle
Auth0JWKSUri=https://dev-5aprb0lr.us.auth0.com/.well-known/jwks.json
Auth0Audience=https://api.cloudmos.io
Auth0Issuer=https://dev-5aprb0lr.us.auth0.com/
AUTH0_JWKS_URI=https://dev-5aprb0lr.us.auth0.com/.well-known/jwks.json
AUTH0_AUDIENCE=https://api.cloudmos.io
AUTH0_ISSUER=https://dev-5aprb0lr.us.auth0.com/
SENTRY_TRACES_RATE=1.0
SENTRY_ENABLED=true
BILLING_ENABLED=true
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ appHono.use(
const { PORT = 3080, BILLING_ENABLED } = process.env;

const scheduler = new Scheduler({
healthchecksEnabled: env.HealthchecksEnabled === "true",
healthchecksEnabled: env.HEALTHCHECKS_ENABLED === "true",
errorHandler: (task, error) => {
console.error(`Task "${task.name}" failed: ${error}`);
getSentry().captureException(error);
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/auth/services/auth.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class AuthInterceptor implements HonoInterceptor {

private async getValidUserId(bearer: string, c: Context) {
const token = bearer.replace(/^Bearer\s+/i, "");
const jwks = await getJwks(env.Auth0JWKSUri || c.env?.JWKS_URI, useKVStore(kvStore || c.env?.VERIFY_RSA_JWT), c.env?.VERIFY_RSA_JWT_JWKS_CACHE_KEY);
const jwks = await getJwks(env.AUTH0_JWKS_URI || c.env?.JWKS_URI, useKVStore(kvStore || c.env?.VERIFY_RSA_JWT), c.env?.VERIFY_RSA_JWT_JWKS_CACHE_KEY);
const result = await verify(token, jwks);

return (result.payload as { sub: string }).sub;
Expand Down
8 changes: 4 additions & 4 deletions apps/api/src/db/dbConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ function isValidNetwork(network: string): network is keyof typeof csMap {
}

const csMap = {
mainnet: env.AkashDatabaseCS,
testnet: env.AkashTestnetDatabaseCS,
sandbox: env.AkashSandboxDatabaseCS
mainnet: env.AKASH_DATABASE_CS,
testnet: env.AKASH_TESTNET_DATABASE_CS,
sandbox: env.AKASH_SANDBOX_DATABASE_CS
};

if (!isValidNetwork(env.NETWORK)) {
Expand Down Expand Up @@ -63,7 +63,7 @@ export const chainDbs: { [key: string]: Sequelize } = Object.keys(chainDefinitio
{}
);

export const userDb = new Sequelize(env.UserDatabaseCS, {
export const userDb = new Sequelize(env.USER_DATABASE_CS, {
dialectModule: pg,
logging,
logQueryParameters: true,
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/middlewares/privateMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { Context, Next } from "hono";
import { env } from "@src/utils/env";

export async function privateMiddleware(c: Context, next: Next) {
if (!env.SecretToken) {
if (!env.SECRET_TOKEN) {
await next();
} else if (c.req.query("token") === env.SecretToken) {
} else if (c.req.query("token") === env.SECRET_TOKEN) {
await next();
} else {
return c.text("Unauthorized", 401);
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/middlewares/userMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ export const kvStore = {
};

export const requiredUserMiddleware = verifyRsaJwt({
jwksUri: env.Auth0JWKSUri,
jwksUri: env.AUTH0_JWKS_URI,
kvStore: kvStore
});

export const optionalUserMiddleware = verifyRsaJwt({
jwksUri: env.Auth0JWKSUri,
jwksUri: env.AUTH0_JWKS_URI,
kvStore: kvStore,
optional: true
});
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/routers/apiRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function registerApiVersion(version: string, baseRouter: OpenAPIHono, versionRou

versionRouter.doc(`/doc`, {
openapi: "3.0.0",
servers: [{ url: `${env.ServerOrigin}/${version}` }],
servers: [{ url: `${env.SERVER_ORIGIN}/${version}` }],
info: {
title: "Console API",
description: "Access Akash data from our indexer",
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/routers/internalRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const internalRouter = new OpenAPIHono();

internalRouter.doc(`/doc`, {
openapi: "3.0.0",
servers: [{ url: `${env.ServerOrigin}/internal` }],
servers: [{ url: `${env.SERVER_ORIGIN}/internal` }],
info: {
title: "Console Internal API",
description: "APIs for internal use that are not part of the public API. There is no garantees of stability or backward compatibility.",
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/routes/internal/gpu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export default new OpenAPIHono().openapi(route, async c => {
memory_size: memory_size ?? null,
provider_address: provider_address ?? null,
provider_hosturi: provider_hosturi ?? null,
grace_date: toUTC(sub(new Date(), { minutes: env.ProviderUptimeGracePeriodMinutes }))
grace_date: toUTC(sub(new Date(), { minutes: env.PROVIDER_UPTIME_GRACE_PERIOD_MINUTES }))
}
}
);
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/routes/internal/gpuPrices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ async function getGpus() {
{
type: QueryTypes.SELECT,
replacements: {
grace_date: toUTC(sub(new Date(), { minutes: env.ProviderUptimeGracePeriodMinutes }))
grace_date: toUTC(sub(new Date(), { minutes: env.PROVIDER_UPTIME_GRACE_PERIOD_MINUTES }))
}
}
);
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/routes/internal/providerVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default new OpenAPIHono().openapi(route, async c => {
{
type: QueryTypes.SELECT,
replacements: {
grace_date: toUTC(sub(new Date(), { minutes: env.ProviderUptimeGracePeriodMinutes }))
grace_date: toUTC(sub(new Date(), { minutes: env.PROVIDER_UPTIME_GRACE_PERIOD_MINUTES }))
}
}
);
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/services/db/providerStatusService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function getNetworkCapacity() {
required: true,
model: ProviderSnapshot,
as: "lastSuccessfulSnapshot",
where: { checkDate: { [Op.gte]: toUTC(sub(new Date(), { minutes: env.ProviderUptimeGracePeriodMinutes })) } }
where: { checkDate: { [Op.gte]: toUTC(sub(new Date(), { minutes: env.PROVIDER_UPTIME_GRACE_PERIOD_MINUTES })) } }
}
]
});
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/services/db/statsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export const getProviderGraphData = async (dataName: ProviderStatsKey) => {
{
type: QueryTypes.SELECT,
replacements: {
grace_duration: env.ProviderUptimeGracePeriodMinutes
grace_duration: env.PROVIDER_UPTIME_GRACE_PERIOD_MINUTES
}
}
);
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/services/external/githubService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { Auditor, ProviderAttributesSchema } from "@src/types/provider";
import { env } from "@src/utils/env";

export function getOctokit() {
const githubPAT = env.AkashlyticsGithubPAT;
const githubPAT = env.AKASHLYTICS_GITHUB_PAT;

if (!githubPAT) {
throw new Error("AkashlyticsGithubPAT is missing");
throw new Error("AKASHLYTICS_GITHUB_PAT is missing");
}

return new Octokit({
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ export const defaultNodeUrlMapping: { [key: string]: string } = {
testnet: "https://api.testnet-02.aksh.pw"
};

export const apiNodeUrl = env.RestApiNodeUrl ?? defaultNodeUrlMapping[env.NETWORK] ?? defaultNodeUrlMapping.mainnet;
export const apiNodeUrl = env.REST_API_NODE_URL ?? defaultNodeUrlMapping[env.NETWORK] ?? defaultNodeUrlMapping.mainnet;
export const betaTypeVersion = "v1beta3";
export const betaTypeVersionMarket = "v1beta4";
28 changes: 14 additions & 14 deletions apps/api/src/utils/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ export const env = z
.object({
AKASHLYTICS_CORS_WEBSITE_URLS: z.string().optional(),
NODE_ENV: z.string().optional(),
HealthchecksEnabled: z.string().optional(),
AkashDatabaseCS: z.string().optional(),
AkashTestnetDatabaseCS: z.string().optional(),
AkashSandboxDatabaseCS: z.string().optional(),
UserDatabaseCS: z.string().optional(),
HEALTHCHECKS_ENABLED: z.string().optional(),
AKASH_DATABASE_CS: z.string().optional(),
AKASH_TESTNET_DATABASE_CS: z.string().optional(),
AKASH_SANDBOX_DATABASE_CS: z.string().optional(),
USER_DATABASE_CS: z.string().optional(),
NETWORK: z.string().default("mainnet"),
RestApiNodeUrl: z.string().optional(),
ServerOrigin: z.string().optional().default("http://localhost:3080"),
AkashlyticsGithubPAT: z.string().optional(),
Auth0JWKSUri: z.string().optional(),
Auth0Audience: z.string().optional(),
Auth0Issuer: z.string().optional(),
WebsiteUrl: z.string().optional(),
SecretToken: z.string().optional(),
ProviderUptimeGracePeriodMinutes: z
REST_API_NODE_URL: z.string().optional(),
SERVER_ORIGIN: z.string().optional().default("http://localhost:3080"),
AKASHLYTICS_GITHUB_PAT: z.string().optional(),
AUTH0_JWKS_URI: z.string().optional(),
AUTH0_AUDIENCE: z.string().optional(),
AUTH0_ISSUER: z.string().optional(),
WEBSITE_URL: z.string().optional(),
SECRET_TOKEN: z.string().optional(),
PROVIDER_UPTIME_GRACE_PERIOD_MINUTES: z
.number()
.optional()
.default(3 * 60),
Expand Down
22 changes: 11 additions & 11 deletions apps/indexer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ You can make sure the api is working by accessing the status endpoint: `http://l

|Name|Value|Note|
|-|-|-
HealthchecksEnabled|`true` or `false`|Specify if the [Scheduler](./src/index.ts#L42) should send health check pings.
SentryDSN|ex: `"https://[email protected]/1234"`|[Sentry DSN](https://docs.sentry.io/product/sentry-basics/dsn-explainer/) used when [initializing](./src/index.ts#L25) Sentry
HealthChecks_SyncBlocks|ex: `041b2561-be28-4a36-bb3f-36a68f86224e`|[HealthChecks.io](https://healthchecks.io) check ID for the `SyncBlocks` task.
HealthChecks_SyncAKTPriceHistory|ex: `041b2561-be28-4a36-bb3f-36a68f86224e`|[HealthChecks.io](https://healthchecks.io) check ID for the `SyncAKTPriceHistory` task.
HealthChecks_SyncProviderInfo|ex: `041b2561-be28-4a36-bb3f-36a68f86224e`|[HealthChecks.io](https://healthchecks.io) check ID for the `SyncProviderInfo` task.
HealthChecks_SyncKeybaseInfo|ex: `041b2561-be28-4a36-bb3f-36a68f86224e`|[HealthChecks.io](https://healthchecks.io) check ID for the `SyncKeybaseInfo` task.
AkashDatabaseCS|ex: `postgres://user:password@localhost:5432/cloudmos-akash`|Akash Database Connection String
ActiveChain|ex: `akash`|Chain code from [chainDefinitions.ts](../shared/chainDefinitions.ts)
KeepCache|`true` or `false`|Specify if the [block & block response cache](#block-cache-structure) should be kept on drive. Takes a lot of space, but allow rebuilding the database without redownloading every blocks.
Standby|`true` or `false`|If `true`, indexer will not start. Useful for stopping an indexer deployed on akash without needing to close the lease.
DataFolder|ex: `./data/`|Directory where block cache and node statuses should be saved. Defaults to `./data/`.
HEALTH_CHECKS_ENABLED|`true` or `false`|Specify if the [Scheduler](./src/index.ts#L42) should send health check pings.
SENTRY_DSN|ex: `"https://[email protected]/1234"`|[Sentry DSN](https://docs.sentry.io/product/sentry-basics/dsn-explainer/) used when [initializing](./src/index.ts#L25) Sentry
HEALTHCHECKS_SYNC_BLOCKS|ex: `041b2561-be28-4a36-bb3f-36a68f86224e`|[HealthChecks.io](https://healthchecks.io) check ID for the `SyncBlocks` task.
HEALTHCHECKS_SYNC_AKT_PRICE_HISTORY|ex: `041b2561-be28-4a36-bb3f-36a68f86224e`|[HealthChecks.io](https://healthchecks.io) check ID for the `SyncAKTPriceHistory` task.
HEALTHCHECKS_SYNC_PROVIDER_INFO|ex: `041b2561-be28-4a36-bb3f-36a68f86224e`|[HealthChecks.io](https://healthchecks.io) check ID for the `SyncProviderInfo` task.
HEALTHCHECKS_SYNC_KEYBASE_INFO|ex: `041b2561-be28-4a36-bb3f-36a68f86224e`|[HealthChecks.io](https://healthchecks.io) check ID for the `SyncKeybaseInfo` task.
AKASH_DATABASE_CS|ex: `postgres://user:password@localhost:5432/cloudmos-akash`|Akash Database Connection String
ACTIVE_CHAIN|ex: `akash`|Chain code from [chainDefinitions.ts](../shared/chainDefinitions.ts)
KEEP_CACHE|`true` or `false`|Specify if the [block & block response cache](#block-cache-structure) should be kept on drive. Takes a lot of space, but allow rebuilding the database without redownloading every blocks.
STANDBY|`true` or `false`|If `true`, indexer will not start. Useful for stopping an indexer deployed on akash without needing to close the lease.
DATA_FOLDER|ex: `./data/`|Directory where block cache and node statuses should be saved. Defaults to `./data/`.

## Scheduled Tasks

Expand Down
16 changes: 8 additions & 8 deletions apps/indexer/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ services:
syncer:
image: redm4x/console-syncer:1.0.0
env:
- HealthchecksEnabled=true
- SentryDSN=<SENTRY_DSN>
- SentryServerName=<SENTRY_SERVER_NAME>
- HealthChecks_SyncBlocks=<HEALTH_CHECKS_ID>
- HealthChecks_SyncAKTPriceHistory=<HEALTH_CHECKS_ID>
- HealthChecks_SyncProviderInfo=<HEALTH_CHECKS_ID>
- HealthChecks_SyncKeybaseInfo=<HEALTH_CHECKS_ID>
- HEALTH_CHECKS_ENABLED=true
- SENTRY_DSN=<SENTRY_DSN>
- SENTRY_SERVER_NAME=<SENTRY_SERVER_NAME>
- HEALTHCHECKS_SYNC_BLOCKS=<HEALTH_CHECKS_ID>
- HEALTHCHECKS_SYNC_AKT_PRICE_HISTORY=<HEALTH_CHECKS_ID>
- HEALTHCHECKS_SYNC_PROVIDER_INFO=<HEALTH_CHECKS_ID>
- HEALTHCHECKS_SYNC_KEYBASE_INFO=<HEALTH_CHECKS_ID>
- ChainDatabaseCS=<DATABASE_CONNECTION_STRING>
- ActiveChain=<CHAIN>
- ACTIVE_CHAIN=<CHAIN>
expose:
- port: 3079
as: 80
Expand Down
6 changes: 3 additions & 3 deletions apps/indexer/src/chain/chainSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export async function syncBlocks() {
if (latestHeightInCache >= latestBlockToDownload) {
console.log("No blocks to download");
} else {
let startHeight = !env.KeepCache ? latestInsertedHeight + 1 : Math.max(latestHeightInCache, 1);
let startHeight = !env.KEEP_CACHE ? latestInsertedHeight + 1 : Math.max(latestHeightInCache, 1);

// If database is empty
if (latestInsertedHeight === 0) {
Expand Down Expand Up @@ -118,7 +118,7 @@ export async function syncBlocks() {
if (executionMode === ExecutionMode.RebuildAll) {
await sequelize.query("DROP INDEX message_height");

if (env.ActiveChain === "akash") {
if (env.ACTIVE_CHAIN === "akash") {
await sequelize.query("DROP INDEX message_related_deployment_id");
}

Expand All @@ -144,7 +144,7 @@ export async function syncBlocks() {

benchmark.displayTimes();

if (!env.KeepCache) {
if (!env.KEEP_CACHE) {
await deleteCache();
}
}
Expand Down
Loading
Loading