Merge pull request #1947 from Infisical/patch-multi-line-encoding

Patch multi line encoding when expandSecretRef is enabled
This commit is contained in:
Maidul Islam
2024-06-11 00:55:31 -04:00
committed by GitHub
4 changed files with 36 additions and 14 deletions
+6 -5
View File
@@ -309,7 +309,7 @@ export const interpolateSecrets = ({ projectId, secretEncKey, secretDAL, folderD
}; };
const expandSecrets = async ( const expandSecrets = async (
secrets: Record<string, { value: string; comment?: string; skipMultilineEncoding?: boolean }> secrets: Record<string, { value: string; comment?: string; skipMultilineEncoding?: boolean | null }>
) => { ) => {
const expandedSec: Record<string, string> = {}; const expandedSec: Record<string, string> = {};
const interpolatedSec: Record<string, string> = {}; const interpolatedSec: Record<string, string> = {};
@@ -329,8 +329,8 @@ export const interpolateSecrets = ({ projectId, secretEncKey, secretDAL, folderD
// should not do multi line encoding if user has set it to skip // should not do multi line encoding if user has set it to skip
// eslint-disable-next-line // eslint-disable-next-line
secrets[key].value = secrets[key].skipMultilineEncoding secrets[key].value = secrets[key].skipMultilineEncoding
? expandedSec[key] ? formatMultiValueEnv(expandedSec[key])
: formatMultiValueEnv(expandedSec[key]); : expandedSec[key];
// eslint-disable-next-line // eslint-disable-next-line
continue; continue;
} }
@@ -347,7 +347,7 @@ export const interpolateSecrets = ({ projectId, secretEncKey, secretDAL, folderD
); );
// eslint-disable-next-line // eslint-disable-next-line
secrets[key].value = secrets[key].skipMultilineEncoding ? expandedVal : formatMultiValueEnv(expandedVal); secrets[key].value = secrets[key].skipMultilineEncoding ? formatMultiValueEnv(expandedVal) : expandedVal;
} }
return secrets; return secrets;
@@ -395,7 +395,8 @@ export const decryptSecretRaw = (
type: secret.type, type: secret.type,
_id: secret.id, _id: secret.id,
id: secret.id, id: secret.id,
user: secret.userId user: secret.userId,
skipMultilineEncoding: secret.skipMultilineEncoding
}; };
}; };
+4 -1
View File
@@ -69,7 +69,10 @@ const MAX_SYNC_SECRET_DEPTH = 5;
export const uniqueSecretQueueKey = (environment: string, secretPath: string) => export const uniqueSecretQueueKey = (environment: string, secretPath: string) =>
`secret-queue-dedupe-${environment}-${secretPath}`; `secret-queue-dedupe-${environment}-${secretPath}`;
type TIntegrationSecret = Record<string, { value: string; comment?: string; skipMultilineEncoding?: boolean }>; type TIntegrationSecret = Record<
string,
{ value: string; comment?: string; skipMultilineEncoding?: boolean | null | undefined }
>;
export const secretQueueFactory = ({ export const secretQueueFactory = ({
queueService, queueService,
integrationDAL, integrationDAL,
+22 -4
View File
@@ -971,10 +971,24 @@ export const secretServiceFactory = ({
}); });
const batchSecretsExpand = async ( const batchSecretsExpand = async (
secretBatch: { secretKey: string; secretValue: string; secretComment?: string; secretPath: string }[] secretBatch: {
secretKey: string;
secretValue: string;
secretComment?: string;
secretPath: string;
skipMultilineEncoding: boolean | null | undefined;
}[]
) => { ) => {
// Group secrets by secretPath // Group secrets by secretPath
const secretsByPath: Record<string, { secretKey: string; secretValue: string; secretComment?: string }[]> = {}; const secretsByPath: Record<
string,
{
secretKey: string;
secretValue: string;
secretComment?: string;
skipMultilineEncoding: boolean | null | undefined;
}[]
> = {};
secretBatch.forEach((secret) => { secretBatch.forEach((secret) => {
if (!secretsByPath[secret.secretPath]) { if (!secretsByPath[secret.secretPath]) {
@@ -990,11 +1004,15 @@ export const secretServiceFactory = ({
continue; continue;
} }
const secretRecord: Record<string, { value: string; comment?: string; skipMultilineEncoding?: boolean }> = {}; const secretRecord: Record<
string,
{ value: string; comment?: string; skipMultilineEncoding: boolean | null | undefined }
> = {};
secretsByPath[secPath].forEach((decryptedSecret) => { secretsByPath[secPath].forEach((decryptedSecret) => {
secretRecord[decryptedSecret.secretKey] = { secretRecord[decryptedSecret.secretKey] = {
value: decryptedSecret.secretValue, value: decryptedSecret.secretValue,
comment: decryptedSecret.secretComment comment: decryptedSecret.secretComment,
skipMultilineEncoding: decryptedSecret.skipMultilineEncoding
}; };
}); });
@@ -393,15 +393,15 @@ export const SecretDetailSidebar = ({
{(isAllowed) => ( {(isAllowed) => (
<Switch <Switch
id="skipmultiencoding-option" id="skipmultiencoding-option"
onCheckedChange={(isChecked) => onChange(!isChecked)} onCheckedChange={(isChecked) => onChange(isChecked)}
isChecked={!value} isChecked={value}
onBlur={onBlur} onBlur={onBlur}
isDisabled={!isAllowed} isDisabled={!isAllowed}
className="items-center" className="items-center"
> >
Enable multi line encoding Multi line encoding
<Tooltip <Tooltip
content="Infisical encodes multiline secrets by escaping newlines and wrapping in quotes. To disable, enable this option" content="When enabled, multiline secrets will be handled by escaping newlines and enclosing the entire value in double quotes."
className="z-[100]" className="z-[100]"
> >
<FontAwesomeIcon icon={faCircleQuestion} className="ml-1" size="sm" /> <FontAwesomeIcon icon={faCircleQuestion} className="ml-1" size="sm" />