MCPcopy Create free account
hub / github.com/Kilo-Org/cloud / mergeEnvVarsWithSecrets

Function mergeEnvVarsWithSecrets

packages/encryption/src/encryption.ts:262–284  ·  view source on GitHub ↗
(
  envVars: Record<string, string> | undefined,
  encryptedSecrets: Record<string, EncryptedEnvelope> | undefined,
  privateKeyPem: string | Buffer | undefined
)

Source from the content-addressed store, hash-verified

260 * Decrypted secrets override plaintext env vars if there are conflicts.
261 */
262export function mergeEnvVarsWithSecrets(
263 envVars: Record<string, string> | undefined,
264 encryptedSecrets: Record<string, EncryptedEnvelope> | undefined,
265 privateKeyPem: string | Buffer | undefined
266): Record<string, string> {
267 const result: Record<string, string> = { ...(envVars ?? {}) };
268
269 if (encryptedSecrets && Object.keys(encryptedSecrets).length > 0) {
270 if (!privateKeyPem) {
271 throw new EncryptionConfigurationError(
272 'Private key is required to decrypt encrypted secrets'
273 );
274 }
275
276 const decrypted = decryptSecrets(encryptedSecrets, privateKeyPem);
277
278 for (const [key, value] of Object.entries(decrypted)) {
279 result[key] = value;
280 }
281 }
282
283 return result;
284}

Callers 1

encryption.test.tsFile · 0.90

Calls 1

decryptSecretsFunction · 0.70

Tested by

no test coverage detected