-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(server/multi region config): mount file and read config from file (
#3407) * feat(multi region config): mount file and read config from file * feat(helm): allow multi region config to be mounted from a secret * Allow the file name to be amended
- Loading branch information
1 parent
55d0d10
commit 8ea43d7
Showing
10 changed files
with
127 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
import { RegionServerConfig } from '@/modules/multiregion/domain/types' | ||
import { MultiRegionConfig } from '@/modules/multiregion/domain/types' | ||
|
||
export type GetAvailableRegionConfigs = () => Promise<{ | ||
[key: string]: RegionServerConfig | ||
}> | ||
export type GetAvailableRegionConfigs = () => Promise<MultiRegionConfig> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,4 @@ | ||
export type RegionServerConfig = { | ||
postgres: { | ||
/** | ||
* Full Postgres connection URI (e.g. "postgres://user:password@host:port/dbname") | ||
*/ | ||
connectionUri: string | ||
/** | ||
* SSL cert, if any | ||
*/ | ||
publicTlsCertificate?: string | ||
} | ||
} | ||
import { z } from 'zod' | ||
import { multiRegionConfigSchema } from '@/modules/multiregion/helpers/validation' | ||
|
||
export type MultiRegionConfig = z.infer<typeof multiRegionConfigSchema> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { z } from 'zod' | ||
|
||
export const regionServerConfigSchema = z.object({ | ||
postgres: z.object({ | ||
connectionUri: z | ||
.string() | ||
.url() | ||
.describe( | ||
'Full Postgres connection URI (e.g. "postgres://user:password@host:port/dbname")' | ||
), | ||
publicTlsCertificate: z | ||
.string() | ||
.describe('Public TLS ("CA") certificate for the Postgres server') | ||
}) | ||
//TODO - add the rest of the config when blob storage is implemented | ||
// blobStorage: z | ||
// .object({ | ||
// endpoint: z.string().url(), | ||
// accessKey: z.string(), | ||
// secretKey: z.string(), | ||
// bucket: z.string() | ||
// }) | ||
}) | ||
|
||
export const multiRegionConfigSchema = z.record(z.string(), regionServerConfigSchema) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,26 @@ | ||
import { GetAvailableRegionConfigs } from '@/modules/multiregion/domain/operations' | ||
import { packageRoot } from '@/bootstrap' | ||
import path from 'node:path' | ||
import fs from 'node:fs/promises' | ||
import { getMultiRegionConfigPath } from '@/modules/shared/helpers/envHelper' | ||
import type { Optional } from '@speckle/shared' | ||
import type { GetAvailableRegionConfigs } from '@/modules/multiregion/domain/operations' | ||
import { type MultiRegionConfig } from '@/modules/multiregion/domain/types' | ||
import { multiRegionConfigSchema } from '@/modules/multiregion/helpers/validation' | ||
|
||
let multiRegionConfig: Optional<MultiRegionConfig> = undefined | ||
|
||
export const getAvailableRegionConfigsFactory = | ||
(): GetAvailableRegionConfigs => async () => { | ||
// TODO: Hardcoded for now, should be fetched from a config file | ||
return { | ||
eu: { | ||
postgres: { | ||
connectionUri: 'postgresql://speckle:speckle@localhost/speckle_eu', | ||
publicTlsCertificate: undefined | ||
} | ||
} | ||
} | ||
if (multiRegionConfig) return multiRegionConfig | ||
|
||
const relativePath = getMultiRegionConfigPath() // This will throw if the path is not set | ||
const fullPath = path.resolve(packageRoot, relativePath) | ||
const file = await fs.readFile(fullPath, 'utf-8') | ||
|
||
const parsedJson = JSON.parse(file) // This will throw if the file is not valid JSON | ||
|
||
const multiRegionConfigFileContents = multiRegionConfigSchema.parse(parsedJson) // This will throw if the config is invalid | ||
|
||
multiRegionConfig = multiRegionConfigFileContents | ||
return multiRegionConfig | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters