knitr::opts_chunk$set( comment = "#>", collapse = TRUE )
Scan secrets in r scripts, packages, or projects
Package API:
cat(paste(" -", paste(sprintf("`%s`", getNamespaceExports("trufflesniffer")), collapse = "\n - ")))
remotes::install_github("ropensci/trufflesniffer")
library("trufflesniffer")
Sys.setenv(A_KEY = "a8d#d%d7g7g4012a4s2") path <- file.path(tempdir(), "foobar") dir.create(path) # no matches sniff_one(path, Sys.getenv("A_KEY")) # add files with the secret cat(paste0("foo\nbar\nhello\nworld\n", Sys.getenv("A_KEY"), "\n"), file = file.path(path, "stuff.R")) # matches! sniff_one(path, Sys.getenv("A_KEY"))
make a fake package
foo <- function(key = NULL) { if (is.null(key)) key <- "mysecretkey" } package.skeleton(name = "mypkg", list = "foo", path = tempdir()) pkgpath <- file.path(tempdir(), "mypkg") # check that you have a pkg at mypkg list.files(pkgpath)
sniff out any secrets
sniff_secrets_pkg(dir = pkgpath, secrets = c("mysecretkey"))
unlink(pkgpath)
make a fake package with tests and fixtures
foo <- function(key = NULL) { if (is.null(key)) key <- "a2s323223asd423adsf4" } package.skeleton("herpkg", list = "foo", path = tempdir()) pkgpath <- file.path(tempdir(), "herpkg") dir.create(file.path(pkgpath, "tests/testthat"), recursive = TRUE) dir.create(file.path(pkgpath, "tests/fixtures"), recursive = TRUE) cat("library(vcr) vcr::vcr_configure('../fixtures', filter_sensitive_data = list('<<mytoken>>' = Sys.getenv('MY_KEY')) )\n", file = file.path(pkgpath, "tests/testthat/helper-herpkg.R")) cat("a2s323223asd423adsf4\n", file = file.path(pkgpath, "tests/fixtures/foo.yml")) # check that you have a pkg at herpkg list.files(pkgpath) list.files(file.path(pkgpath, "tests/testthat")) cat(readLines(file.path(pkgpath, "tests/testthat/helper-herpkg.R")), sep = "\n") list.files(file.path(pkgpath, "tests/fixtures")) readLines(file.path(pkgpath, "tests/fixtures/foo.yml"))
sniff out any secrets
Sys.setenv('MY_KEY' = 'a2s323223asd423adsf4') sniff_secrets_fixtures(pkgpath)
trufflesniffer
in R doing citation(package = 'trufflesniffer')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.