public class RuntimeSecrets extends Object
This class makes use of cloud KMS for encryption/decryption operations.
It will also make use of GCS if a GCS URL is provided when calling interpretSecret.
Constructor and Description |
---|
RuntimeSecrets(String project,
String ring,
String keyName)
Create new
RuntimeSecrets object referencing a KMS key based on the supplied
parameters. |
Modifier and Type | Method and Description |
---|---|
String |
decrypt(String input)
Decrypt the supplied input
|
void |
done()
Indicate
RuntimeSecrets object will no longer be used, must be called to shutdown
background threads |
String |
encrypt(String input)
Encrypt the supplied input
|
static String |
interpretSecret(String input,
String project)
Interpret a runtime secret as specified in pipeline options.
|
static void |
main(String[] args)
main routine can be used to encrypt or decrypt data on the command line
|
public RuntimeSecrets(String project, String ring, String keyName) throws IOException
RuntimeSecrets
object referencing a KMS key based on the supplied
parameters.project
- Project namering
- Keyring namekeyName
- Key nameIOException
- IOExceptionpublic String encrypt(String input)
input
- Input stringpublic String decrypt(String input)
input
- Input stringpublic void done() throws InterruptedException
RuntimeSecrets
object will no longer be used, must be called to shutdown
background threadsInterruptedException
- InterruptedExceptionpublic static String interpretSecret(String input, String project) throws IOException
This function currently handles three formats. A string prefixed with cloudkms:// is interpreted as an encrypted string which will be decrypted via CloudKMS. The project should be set to the correct GCP project name. The key ring and key name will always be looked for as "dataflow".
With no prefix, the input is simply returned as is and treated as an unencrypted string.
If a GCS URL is provided (e.g., gs://bucket/path) - the content of the object at the specified path will be fetched and handled as if it was passed directly as a string into the function.
input
- Input stringproject
- GCP project name, can be null if unapplicableIOException
- IOExceptionCopyright © 2022. All rights reserved.