Skip to content

Commit

Permalink
AB#157 feat: read s3 configuration from env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
giovannibaratta committed Mar 17, 2024
1 parent 8f4e277 commit 2fd1e2c
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
7 changes: 6 additions & 1 deletion service/.env.local
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
DATABASE_URL=postgresql://developer:Safe1!@localhost:5432/terraapprove?schema=public
KAFKA_BROKERS=localhost:9092
KAFKA_TOPIC_RUN_STATUS_CHANGED="run-status-changed"
KAFKA_TOPIC_RUN_STATUS_CHANGED="run-status-changed"
S3_ENDPOINT=http://localhost:9000
S3_ACCESS_KEY_ID=developer
S3_SECRET_ACCESS_KEY=SafePassword1!
S3_BUCKET_SOURCE_CODE=source-code
S3_BUCKET_PLANS=plans
7 changes: 6 additions & 1 deletion service/.env.test
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
DATABASE_URL=postgresql://developer:Safe1!@localhost:5433/terraapprove?schema=public
KAFKA_BROKERS=localhost:9092
KAFKA_BROKERS=localhost:9092
S3_ENDPOINT=http://localhost:9000
S3_ACCESS_KEY_ID=test-access-key
S3_SECRET_ACCESS_KEY=test-secret-key
S3_BUCKET_SOURCE_CODE=source-code
S3_BUCKET_PLANS=plans
47 changes: 47 additions & 0 deletions service/libs/external/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {Injectable} from "@nestjs/common"
export class Config {
private dbConnectionUrl: string
readonly kafkaConfig: KafkaConfig
readonly s3Config: S3Config

constructor() {
const connectionUrl = process.env.DATABASE_URL
Expand Down Expand Up @@ -34,11 +35,46 @@ export class Config {
}

this.kafkaConfig = kafkaConfig
this.s3Config = this.readS3Config()
}

getDbConnectionUrl(): string {
return this.dbConnectionUrl
}

private readS3Config(): S3Config {
const rawS3Endpoint = process.env.S3_ENDPOINT
const rawS3AccessKeyId = process.env.S3_ACCESS_KEY_ID
const rawS3SecretAccessKey = process.env.S3_SECRET_ACCESS_KEY

const rawS3BucketSourceCode = process.env.S3_BUCKET_SOURCE_CODE
const rawS3BucketPlans = process.env.S3_BUCKET_PLANS

if (rawS3Endpoint === undefined)
throw new Error("S3_ENDPOINT is not defined")

if (rawS3AccessKeyId === undefined)
throw new Error("S3_ACCESS_KEY_ID is not defined")

if (rawS3SecretAccessKey === undefined)
throw new Error("S3_SECRET_ACCESS_KEY is not defined")

if (rawS3BucketSourceCode === undefined)
throw new Error("S3_BUCKET_SOURCE_CODE is not defined")

if (rawS3BucketPlans === undefined)
throw new Error("S3_BUCKET_PLANS is not defined")

return {
entpoint: rawS3Endpoint,
accessKeyId: rawS3AccessKeyId,
secretAccessKey: rawS3SecretAccessKey,
buckets: {
sourceCode: rawS3BucketSourceCode,
plans: rawS3BucketPlans
}
}
}
}

export interface KafkaConfig {
Expand All @@ -47,3 +83,14 @@ export interface KafkaConfig {
readonly runStatusChanged: string
}
}

export interface S3Config {
readonly entpoint: string
readonly accessKeyId: string
readonly secretAccessKey: string

readonly buckets: {
readonly sourceCode: string
readonly plans: string
}
}

0 comments on commit 2fd1e2c

Please sign in to comment.