Last active
April 3, 2021 05:57
-
-
Save nwstephens/255be56b99f1700acfd7a7f8b69da103 to your computer and use it in GitHub Desktop.
Storing secrets with R. Using the keyring package you can stole encrypted secrets on disk or store them as environment variables in memory.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(keyring) | |
options("keyring_backend" = "file") # set this in .Rprofile for convenience | |
### Store secrets encrypted at rest | |
keyring_create("kr") | |
key_set("foobar", keyring = "kr") | |
key_get("foobar", keyring = "kr") | |
### Store multiple secrets | |
keyring_create("DBs") | |
key_set("db1", "user", keyring = "DBs") | |
key_set_with_value("db2", "user", "password", keyring = "DBs") | |
keyring_lock("DBs") | |
keyring_unlock("DBs") | |
key_get("db1", "user", keyring = "DBs") | |
key_get("db2", "user", keyring = "DBs") | |
### Retrieve with RStudio | |
options("keyring_backend" = "file") | |
keyring::keyring_create("system") | |
rstudioapi::askForSecret("psql") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment