-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprepare.ts
More file actions
35 lines (30 loc) · 1.21 KB
/
prepare.ts
File metadata and controls
35 lines (30 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import type { PrepareFunction } from '@data-fair/lib-common-types/processings.js'
import type { ProcessingConfig } from '#types/processingConfig/index.ts'
/**
* When the configuration is saved, we hide the secret values and store them in the secrets store.
* - password and sshKey are extracted from connectionKey, stored in secrets, and replaced by '********'.
* - If the field is emptied, the corresponding secret is removed.
*/
const prepare: PrepareFunction<ProcessingConfig> = async ({ processingConfig, secrets }) => {
const connectionKey = processingConfig.connectionKey
if (connectionKey.key === 'password') {
const password = connectionKey.password
if (password && password !== '********') {
secrets.password = password
connectionKey.password = '********'
} else if (secrets.password && password === '') {
delete secrets.password
}
}
if (connectionKey.key === 'sshKey') {
const sshKey = connectionKey.sshKey
if (sshKey && sshKey !== '********') {
secrets.sshKey = sshKey
connectionKey.sshKey = '********'
} else if (secrets.sshKey && sshKey === '') {
delete secrets.sshKey
}
}
return { processingConfig, secrets }
}
export default prepare