-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- allow CTA to load metadata from multiple files in addition to the env var - add driver metadata - add creation date and version metadata
- Loading branch information
Roy Razon
committed
Aug 9, 2023
1 parent
b0a62e2
commit 84a61c4
Showing
17 changed files
with
176 additions
and
48 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import fs from 'fs' | ||
import path from 'path' | ||
|
||
const isNotFoundError = (e: unknown) => (e as { code?: unknown })?.code === 'ENOENT' | ||
|
||
export const readOrUndefined = ( | ||
...args: Parameters<typeof fs.promises.readFile> | ||
) => fs.promises.readFile(...args).catch(err => { | ||
if (isNotFoundError(err)) { | ||
return undefined | ||
} | ||
throw err | ||
}) | ||
|
||
const readDir = async (dir: string) => { | ||
try { | ||
return ((await fs.promises.readdir(dir, { withFileTypes: true })) ?? []) | ||
.filter(d => d.isFile()).map(f => f.name) | ||
} catch (e) { | ||
if ((e as { code: string }).code === 'ENOENT') { | ||
return [] | ||
} | ||
throw e | ||
} | ||
} | ||
|
||
export const readAllFiles = async (dir: string) => { | ||
const files = await readDir(dir) | ||
return await Promise.all( | ||
files.map(file => fs.promises.readFile(path.join(dir, file), { encoding: 'utf8' })) | ||
) | ||
} |
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,34 @@ | ||
import fs from 'fs' | ||
import { Logger } from '@preevy/common' | ||
import { merge } from 'lodash' | ||
import { inspect } from 'util' | ||
|
||
export const envMetadata = async ({ env, log }: { env: NodeJS.ProcessEnv; log: Logger }) => { | ||
const jsons = [ | ||
...await Promise.all( | ||
(env.ENV_METADATA_FILES || '') | ||
.split(' ') | ||
.map(async f => { | ||
try { | ||
return await fs.promises.readFile(f, { encoding: 'utf8' }) | ||
} catch (err) { | ||
log.warn('error reading env metadata from file "%s": %j', f, inspect(err)) | ||
return undefined | ||
} | ||
}) | ||
), | ||
env.ENV_METADATA, | ||
] | ||
|
||
const objects = jsons.map((s, i) => { | ||
try { | ||
if (s === undefined) return undefined | ||
return JSON.parse(s) as Record<string, unknown> | ||
} catch (err) { | ||
log.warn('error reading env metadta from JSON %d %s: %j', i, s, inspect(err)) | ||
return undefined | ||
} | ||
}) | ||
|
||
return merge({}, ...objects.filter(Boolean)) | ||
} |
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
Oops, something went wrong.