-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix typing error in secrets package and organize its adapters into a …
…separate subdirectory.
- Loading branch information
1 parent
8280a08
commit 89e918f
Showing
5 changed files
with
49 additions
and
50 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
2 changes: 1 addition & 1 deletion
2
packages/secrets/src/lib/in-memory.ts → ...ges/secrets/src/lib/adapters/in-memory.ts
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,43 @@ | ||
import { promises as fs } from 'fs'; | ||
|
||
import * as r from '@atj/common'; | ||
|
||
import { AWSParameterStoreSecretsVault } from './aws-param-store'; | ||
import { getSecretMapFromJsonString, type SecretsVault } from '../types'; | ||
import { InMemorySecretsVault } from './in-memory'; | ||
|
||
/** | ||
* Returns either a production vault or an in-memory vault initialized with the | ||
* contents of a JSON file. | ||
* @param jsonFilePath Optional path to a local JSON file that will stand-in | ||
* for a secrets vault. | ||
* @returns In-memory or production vault. | ||
*/ | ||
export const getSecretsVault = async (jsonFilePath?: string) => { | ||
if (jsonFilePath) { | ||
const maybeJsonString = (await fs.readFile(jsonFilePath)).toString(); | ||
const result = createInMemorySecretsVault(maybeJsonString); | ||
if (result.success) { | ||
return result.data; | ||
} else { | ||
throw new Error(result.error); | ||
} | ||
} else { | ||
return getAWSSecretsVault(); | ||
} | ||
}; | ||
|
||
export const getAWSSecretsVault = (): SecretsVault => { | ||
return new AWSParameterStoreSecretsVault(); | ||
}; | ||
|
||
export const createInMemorySecretsVault = ( | ||
jsonString?: any | ||
): r.Result<SecretsVault> => { | ||
const result = getSecretMapFromJsonString(jsonString); | ||
if (result.success) { | ||
return r.success(new InMemorySecretsVault(result.data)); | ||
} else { | ||
return r.failure(result.error); | ||
} | ||
}; |
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