SecretString
Class: SecretString
Defined in: packages/core/src/services/cryptoservice.service.ts:54
A secret value decrypted from a crypt:<encrypter>:<data> configuration string
The plain value is only available through SecretString.getValue: string
conversion, JSON.stringify and util.inspect all return a mask, so the secret
does not leak into logs, configuration dumps or serialized services.
In a service parameters class, type a secret field as string | SecretString
and read it with SecretString.from.
@secret marks every property typed with this class as a secret in the generated
schema (x-webda-secret), so webda config encrypt encrypts it and --check reports it when it is not encrypted.
Secret
Constructors
Constructor
new SecretString(
str,encrypter):SecretString
Defined in: packages/core/src/services/cryptoservice.service.ts:68
Create a new SecretString
Parameters
str
string
the secret value
encrypter
string
the encrypter name
Returns
SecretString
Properties
encrypter
readonlyencrypter:string
Defined in: packages/core/src/services/cryptoservice.service.ts:62
Name of the encrypter that decrypted the value
Methods
[custom]()
[custom](
depth,options,inspect):string
Defined in: packages/core/src/services/cryptoservice.service.ts:146
Custom inspect handler to mask the secret in Node.js util.inspect
Parameters
depth
any
the depth level
options
any
the options
inspect
any
the inspect function
Returns
string
the result
getValue()
getValue():
string
Defined in: packages/core/src/services/cryptoservice.service.ts:122
Get the underlying secret value
Returns
string
the result string
toJSON()
toJSON():
string
Defined in: packages/core/src/services/cryptoservice.service.ts:136
Return a masked representation to prevent secret leakage through JSON
Returns
string
the result string
toString()
toString():
string
Defined in: packages/core/src/services/cryptoservice.service.ts:129
Return a masked representation to prevent secret leakage
Returns
string
the result string
from()
staticfrom(value,path?):string
Defined in: packages/core/src/services/cryptoservice.service.ts:82
Extract the plain string value, warning if the string is not encrypted
The warning never contains the value itself, only the optional path.
Parameters
value
string | SecretString
the secret, or a plain string
path?
string
the configuration path of the value, used in the warning
Returns
string
the plain value
unwrap()
staticunwrap<T>(value):T
Defined in: packages/core/src/services/cryptoservice.service.ts:101
Replace every SecretString in a structure by its plain value
Use it to pass a configuration object holding secrets to a third-party client that expects plain strings. The structure is copied, not modified.
Type Parameters
T
T = any
Parameters
value
T
the structure to unwrap
Returns
T
a copy with plain values