-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some adjustments for Storage Driver and SourceManager to run on a nodejs
server We want to use some methods from these 2 packages in our Latitude cloud and we have to make it work
- Loading branch information
1 parent
1b25797
commit 4c129f2
Showing
18 changed files
with
189 additions
and
55 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@latitude-data/source-manager": patch | ||
"@latitude-data/storage-driver": patch | ||
--- | ||
|
||
Dry resolve secrets helper function |
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
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,54 @@ | ||
import { describe, expect, it } from 'vitest' | ||
import { resolveSecrets } from './index' | ||
|
||
describe('resolveSecrets', () => { | ||
it('should resolve secrets', () => { | ||
const config = { | ||
secret1: 'LATITUDE__SECRET1', | ||
secret2: 'LATITUDE__SECRET2', | ||
} | ||
|
||
// eslint-disable-next-line turbo/no-undeclared-env-vars | ||
process.env['LATITUDE__SECRET1'] = 'supersecret1' | ||
// eslint-disable-next-line turbo/no-undeclared-env-vars | ||
process.env['LATITUDE__SECRET2'] = 'supersecret2' | ||
|
||
const resolvedSecrets = resolveSecrets({ unresolvedSecrets: config }) | ||
|
||
expect(resolvedSecrets.secret1).toBe('supersecret1') | ||
expect(resolvedSecrets.secret2).toBe('supersecret2') | ||
}) | ||
|
||
it('should resolve nested secrets', () => { | ||
const config = { | ||
secret: { | ||
secret: 'LATITUDE__SECRET1', | ||
notASecret: 33, | ||
}, | ||
} | ||
// eslint-disable-next-line turbo/no-undeclared-env-vars | ||
process.env['LATITUDE__SECRET1'] = 'supersecret1' | ||
const resolvedSecrets = resolveSecrets({ unresolvedSecrets: config }) | ||
const firstLevel = resolvedSecrets.secret as { | ||
secret: string | ||
notASecret: number | ||
} | ||
|
||
expect(firstLevel.secret).toBe('supersecret1') | ||
expect(firstLevel.notASecret).toBe(33) | ||
}) | ||
|
||
it('should throw error when environment variable is not found', () => { | ||
const config = { | ||
secret3: 'LATITUDE__SECRET3', | ||
} | ||
|
||
expect(() => { | ||
resolveSecrets({ unresolvedSecrets: config }) | ||
}).toThrowError( | ||
new Error( | ||
`Invalid configuration. Environment variable LATITUDE__SECRET3 was not found in the environment.`, | ||
), | ||
) | ||
}) | ||
}) |
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,31 @@ | ||
export function resolveSecrets({ | ||
unresolvedSecrets, | ||
}: { | ||
unresolvedSecrets: Record<string, unknown> | ||
}) { | ||
return Object.entries(unresolvedSecrets).reduce( | ||
(acc, [key, value]) => { | ||
if (typeof value === 'object') { | ||
acc[key] = resolveSecrets({ | ||
unresolvedSecrets: value as Record<string, unknown>, | ||
}) | ||
return acc | ||
} | ||
|
||
if (typeof value === 'string' && value.startsWith('LATITUDE__')) { | ||
if (process.env[value]) { | ||
acc[key] = process.env[value] | ||
return acc | ||
} | ||
|
||
throw new Error( | ||
`Invalid configuration. Environment variable ${value} was not found in the environment.`, | ||
) | ||
} | ||
|
||
acc[key] = value | ||
return acc | ||
}, | ||
{} as Record<string, unknown>, | ||
) | ||
} |
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 |
---|---|---|
|
@@ -15,6 +15,9 @@ export default { | |
], | ||
external: [ | ||
'fs', | ||
'@aws-sdk/client-s3', | ||
'@aws-sdk/lib-storage', | ||
'stream', | ||
'path', | ||
], | ||
} |
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.