control how many times conditions are thrown

Package API:

  • snif_secrets_pkg
  • snif_one
  • snif_secrets_fixtures
  • sniffer

Installation

remotes::install_github("ropenscilabs/trufflesniffer")
library("trufflesniffer")

snif through a directory

Sys.setenv(A_KEY = "a8d#d%d7g7g4012a4s2")
path <- file.path(tempdir(), "foobar")
dir.create(path)
# no matches
snif_one(path, Sys.getenv("A_KEY"))
#> named list()
# add files with the secret
cat(paste0("foo\nbar\nhello\nworld\n", 
    Sys.getenv("A_KEY"), "\n"), file = file.path(path, "stuff.R"))
# matches!
snif_one(path, Sys.getenv("A_KEY"))
#> $stuff.R
#> [1] 5

look across package in general

make a fake package

snif out any secrets

snif_secrets_pkg(dir = pkgpath, secrets = c("mysecretkey"))
#> $mysecretkey
#> $mysecretkey$foo.R
#> [1] 3

cleanup

unlink(pkgpath)

check in test fixtures

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)
#> [1] "DESCRIPTION"        "man"                "NAMESPACE"         
#> [4] "R"                  "Read-and-delete-me" "tests"
list.files(file.path(pkgpath, "tests/testthat"))
#> [1] "helper-herpkg.R"
readLines(file.path(pkgpath, "tests/testthat/helper-herpkg.R"))
#> [1] "library(vcr)"                                                        
#> [2] "vcr::vcr_configure('../fixtures', "                                  
#> [3] "  filter_sensitive_data = list('<<mytoken>>' = Sys.getenv('MY_KEY'))"
#> [4] ")"
list.files(file.path(pkgpath, "tests/fixtures"))
#> [1] "foo.yml"
readLines(file.path(pkgpath, "tests/fixtures/foo.yml"))
#> [1] "a2s323223asd423adsf4"

snif out any secrets

Sys.setenv('MY_KEY' = 'a2s323223asd423adsf4')
snif_secrets_fixtures(pkgpath)
#> $MY_KEY
#> $MY_KEY$foo.yml
#> [1] 1

Meta

rofooter