This repository was archived by the owner on Sep 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
111 lines (87 loc) · 3.08 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
trufflesniffer
===========
```{r echo=FALSE}
knitr::opts_chunk$set(
comment = "#>",
collapse = TRUE
)
```
[](https://www.repostatus.org/#active)
[](https://github.com/ropensci/trufflesniffer/actions?query=workflow%3AR-CMD-check)
Scan secrets in r scripts, packages, or projects
Package API:
```{r echo=FALSE, comment=NA, results="asis"}
cat(paste(" -", paste(sprintf("`%s`", getNamespaceExports("trufflesniffer")), collapse = "\n - ")))
```
## Installation
```{r eval=FALSE}
remotes::install_github("ropensci/trufflesniffer")
```
```{r}
library("trufflesniffer")
```
## sniff through a directory
```{r}
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"))
```
## look across package in general
make a fake package
```{r message=FALSE}
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
```{r}
sniff_secrets_pkg(dir = pkgpath, secrets = c("mysecretkey"))
```
```{r echo=FALSE}
unlink(pkgpath)
```
## check in test fixtures
make a fake package with tests and fixtures
```{r message=FALSE}
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
```{r}
Sys.setenv('MY_KEY' = 'a2s323223asd423adsf4')
sniff_secrets_fixtures(pkgpath)
```
## Meta
* Please [report any issues or bugs](https://github.com/ropensci/trufflesniffer/issues).
* License: MIT
* Get citation information for `trufflesniffer` in R doing `citation(package = 'trufflesniffer')`
* Please note that this package is released with a [Contributor Code of Conduct](https://ropensci.org/code-of-conduct/). By contributing to this project, you agree to abide by its terms.