Skip to content

Instantly share code, notes, and snippets.

@andrie
Created July 29, 2017 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrie/ae65ae5472b6c1849f5d0cd327668594 to your computer and use it in GitHub Desktop.
Save andrie/ae65ae5472b6c1849f5d0cd327668594 to your computer and use it in GitHub Desktop.
Demo of `secret` package at UseR!2017
# load the package ----------------------------------------------------
# install.packages("secret")
library(secret)
library(magrittr)
# set up local user ---------------------------------------------------
# Andrie wants to share a secret with Bob
# Andrie is the local user
# He saved his private key at ~/.ssh
dir("~/.ssh")
local_key()
# Bob has shared his public key
key_dir <- system.file("user_keys", package = "secret")
bob_public <- file.path(key_dir, "bob.pub")
bob_public %>% readLines() %>% cat()
# Create a vault ------------------------------------------------------
original_wd <- getwd()
vault <- "vault"
create_vault(vault)
dir(vault)
setwd(vault)
# Add users to vault --------------------------------------------------
# Add andrie as a user
add_user("andrie", local_key())
dir(recursive = TRUE)
# Add Bob as a user
add_user("bob", bob_public)
dir(recursive = TRUE)
# Share a secret ------------------------------------------------------
# Add a secret and share with Bob
add_secret("azure_key",
value = list(
`resource group` = "azure super user",
`storage key` = "adgfjh345=="
),
users = c("andrie", "bob")
)
dir(recursive = TRUE)
# Test: decrypt using my own key
get_secret("azure_key")
# Decrypt the secret using Bob's key
get_secret("azure_key", file.path(key_dir, "bob.pem"))
# But Alice doesn't have access
get_secret("azure_key", file.path(key_dir, "alice.pem"))
# Share the same secret with alice ------------------------------------
add_user("alice", public_key = file.path(key_dir, "alice.pub"))
share_secret("azure_key", users = "alice")
get_secret("azure_key", file.path(key_dir, "alice.pem"))
# list secrets
list_secrets(".")
list_owners("azure_key")
list_users()
# Some more things you can do -----------------------------------------
# add github user
add_github_user("statsmaths")
list_users(vault)
# add travis user
add_travis_user("RevolutionAnalytics/miniCRAN")
list_users()
# the three lines -----------------------------------------------------
?create_vault()
?add_user()
?add_secret()
# clean up ------------------------------------------------------------
setwd(original_wd)
unlink("vault", recursive = TRUE, force = TRUE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment