@@ -14,11 +14,22 @@ export function getInputSchemaSecretFieldKeys(inputSchema: any): string[] {
14
14
. filter ( ( key ) => ! ! inputSchema . properties [ key ] . isSecret ) ;
15
15
}
16
16
17
+ /**
18
+ * Encrypts input secret value
19
+ */
20
+ export function encryptInputSecretValue ( { value, publicKey } : { value : string , publicKey : KeyObject } ) : string {
21
+ ow ( value , ow . string ) ;
22
+ ow ( publicKey , ow . object . instanceOf ( KeyObject ) ) ;
23
+
24
+ const { encryptedValue, encryptedPassword } = publicEncrypt ( { value, publicKey } ) ;
25
+ return `${ ENCRYPTED_INPUT_VALUE_PREFIX } :${ encryptedPassword } :${ encryptedValue } ` ;
26
+ }
27
+
17
28
/**
18
29
* Encrypts actor input secrets
19
30
*/
20
31
export function encryptInputSecrets < T > (
21
- { input, inputSchema, publicKey } : { input : T , inputSchema : object , publicKey : KeyObject } ,
32
+ { input, inputSchema, publicKey } : { input : T , inputSchema : object , publicKey : KeyObject } ,
22
33
) : T {
23
34
ow ( input , ow . object ) ;
24
35
ow ( inputSchema , ow . object ) ;
@@ -33,8 +44,7 @@ export function encryptInputSecrets<T>(
33
44
// NOTE: Skips already encrypted values. It can happens in case client already encrypted values, before
34
45
// sending them using API. Or input was takes from task, run console or scheduler, where input is stored encrypted.
35
46
if ( value && ow . isValid ( value , ow . string ) && ! ENCRYPTED_INPUT_VALUE_REGEXP . test ( value ) ) {
36
- const { encryptedValue, encryptedPassword } = publicEncrypt ( { value : input [ key ] , publicKey } ) ;
37
- encryptedInput [ key ] = `${ ENCRYPTED_INPUT_VALUE_PREFIX } :${ encryptedPassword } :${ encryptedValue } ` ;
47
+ encryptedInput [ key ] = encryptInputSecretValue ( { value : input [ key ] , publicKey } ) ;
38
48
}
39
49
}
40
50
0 commit comments