Skip to content

Commit

Permalink
Merge pull request #34 from vimc/vimc-4748
Browse files Browse the repository at this point in the history
  • Loading branch information
richfitz committed Jun 9, 2021
2 parents bfeb917 + c00636e commit 8e90453
Show file tree
Hide file tree
Showing 90 changed files with 6,224 additions and 5,856 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Expand Up @@ -12,3 +12,4 @@
^man-roxygen$
^appveyor\.yml$
^\.github$
^\.lintr$
7 changes: 7 additions & 0 deletions .lintr
@@ -0,0 +1,7 @@
linters: with_defaults(
object_length_linter = NULL,
object_usage_linter = NULL,
todo_comment_linter = NULL,
cyclocomp_linter = NULL
)
exclusions: list("tests/testthat.R")
7 changes: 4 additions & 3 deletions DESCRIPTION
Expand Up @@ -6,7 +6,7 @@ Authors@R: c(person("Rich", "FitzJohn", role = c("aut", "cre"),
person("Imperial College of Science, Technology and Medicine",
role = "cph"))
Title: Vault Client for Secrets and Sensitive Data
Version: 1.0.5
Version: 1.1.0
Description: Provides an interface to a 'HashiCorp' vault server over
its http API (typically these are self-hosted; see
<https://www.vaultproject.io>). This allows for secure storage and
Expand All @@ -15,7 +15,7 @@ Description: Provides an interface to a 'HashiCorp' vault server over
several backends including user name/password and authentication via
'GitHub'.
License: MIT + file LICENSE
URL: https://github.com/vimc/vaultr, https://vimc.github.io/vaultr/
URL: https://github.com/vimc/vaultr, https://www.vaccineimpact.org/vaultr/
BugReports: https://github.com/vimc/vaultr/issues
SystemRequirements: vault
Imports:
Expand All @@ -30,7 +30,8 @@ Suggests:
rmarkdown,
testthat,
withr
RoxygenNote: 7.0.0
RoxygenNote: 7.1.1
Encoding: UTF-8
VignetteBuilder: knitr
Language: en-GB
Roxygen: list(markdown = TRUE)
23 changes: 23 additions & 0 deletions R/aaa.R
@@ -1,4 +1,19 @@
##' Base object used by vaultr for all objects
##'
##' @title Base object type
##'
##' @name vault_client_object
##'
##' @importFrom R6 R6Class
##' @examples
##'
##' server <- vaultr::vault_test_server(if_disabled = message)
##'
##' if (!is.null(server)) {
##' client <- vaultr::vault_client(addr = server$addr)
##' client$operator$format()
##' client$operator$format(TRUE)
##' }
vault_client_object <- R6::R6Class(
"vault_client_object",
cloneable = FALSE,
Expand All @@ -10,16 +25,24 @@ vault_client_object <- R6::R6Class(
),

public = list(
##' @description Construct an object
##'
##' @param description Description for the object, will be printed
initialize = function(description) {
private$name <- sub("^(vault_|vault_client_)", "", class(self)[[1L]])
private$help_name <- class(self)[[1L]]
private$description <- description
},

##' @description Format method, overriding the R6 default
##'
##' @param brief Logical, indicating if this is the full format or
##' a brief (one line) format.
format = function(brief = FALSE) {
vault_client_format(self, brief, private$name, private$description)
},

##' @description Display help for this object
help = function() {
utils::help(private$help_name, package = "vaultr")
}
Expand Down
83 changes: 42 additions & 41 deletions R/server_manager.R
@@ -1,48 +1,47 @@
##' Control a server for use with testing. This is designed to be
##' used only by other packages that wish to run tests against a vault
##' server. You will need to set \code{VAULTR_TEST_SERVER_BIN_PATH}
##' server. You will need to set `VAULTR_TEST_SERVER_BIN_PATH`
##' to point at the directory containing the vault binary.
##'
##' Once created with \code{vault_test_server}, a server will stay
##' alive for as long as the R process is alive \emph{or} until the
##' \code{vault_server_instance} object goes out of scope and is
##' garbage collected. Calling \code{$kill()} will explicitly stop
##' Once created with `vault_test_server`, a server will stay
##' alive for as long as the R process is alive *or* until the
##' `vault_server_instance` object goes out of scope and is
##' garbage collected. Calling `$kill()` will explicitly stop
##' the server, but this is not strictly needed. See below for
##' methods to control the server instance.
##'
##' The function \code{vault_test_server_install} will install a test
##' server, but \emph{only} if the user sets the following environmental
##' The function `vault_test_server_install` will install a test
##' server, but *only* if the user sets the following environmental
##' variables:
##' \itemize{
##' \item \code{VAULTR_TEST_SERVER_INSTALL} to \code{"true"} to opt in
##' to the download.
##' \item \code{VAULTR_TEST_SERVER_BIN_PATH} to the directory where
##' the binary should be downloaded to.
##' \item \code{NOT_CRAN} to \code{"true"} to indicate this is not running
##' on CRAN as it requires installation of a binary from a website.
##' }
##' This will download a ~100MB binary from \url{https://vaultproject.io}
##' so use with care. It is intended \emph{only} for use in automated
##' testing environments.
##'
##' @template vault_server_instance
##' * `VAULTR_TEST_SERVER_INSTALL` to `"true"` to opt in to the
##' download.
##'
##' * `VAULTR_TEST_SERVER_BIN_PATH` to the directory where the binary
##' should be downloaded to.
##'
##' * `NOT_CRAN` to `"true"` to indicate this is not running on CRAN
##' as it requires installation of a binary from a website.
##'
##' This will download a ~100MB binary from https://vaultproject.io
##' so use with care. It is intended *only* for use in automated
##' testing environments.
##'
##' @section Warning:
##'
##' Starting a server in test mode must \emph{not} be used for
##' production under any circumstances. As the name suggests,
##' \code{vault_test_server} is a server suitable for \emph{tests}
##' only and lacks any of the features required to make vault
##' secure. Please see
##' \url{https://www.vaultproject.io/docs/concepts/dev-server.html}
##' Starting a server in test mode must *not* be used for production
##' under any circumstances. As the name suggests,
##' `vault_test_server` is a server suitable for *tests* only and
##' lacks any of the features required to make vault secure. Please
##' see https://www.vaultproject.io/docs/concepts/dev-server.html
##' for more information
##'
##' @section Warning:
##'
##' The \code{vault_test_server_install} function will download a
##' The `vault_test_server_install` function will download a
##' binary from HashiCorp in order to use a vault server. Use this
##' function with care. The download will happen from
##' \url{https://releases.hashicorp.com/vault} (over https). This
##' https://releases.hashicorp.com/vault (over https). This
##' function is primarily designed to be used from continuous
##' integration services only and for local use you are strongly
##' recommended to curate your own installations.
Expand All @@ -51,24 +50,24 @@
##'
##' @param https Logical scalar, indicating if a https-using server
##' should be created, rather than the default vault dev-mode
##' server. This is still \emph{entirely} insecure, and uses self
##' server. This is still *entirely* insecure, and uses self
##' signed certificates that are bundled with the package.
##'
##' @param init Logical scalar, indicating if the https-using server
##' should be initialised.
##'
##' @param if_disabled Callback function to run if the vault server is
##' not enabled. The default, designed to be used within tests, is
##' \code{testthat::skip}. Alternatively, inspect the
##' \code{$enabled} property of the returned object.
##' `testthat::skip`. Alternatively, inspect the
##' `$enabled` property of the returned object.
##'
##' @export
##' @rdname vault_test_server
##' @aliases vault_server_instance
##' @examples
##'
##' # Try and start a server; if one is not enabled (see details
##' # above) then this will return \code{NULL}
##' # above) then this will return NULL
##' server <- vault_test_server(if_disabled = message)
##'
##' if (!is.null(server)) {
Expand All @@ -85,7 +84,7 @@
##'
##' # The server stops automatically when the server object is
##' # garbage collected, or it can be turned off with the
##' # \code{kill} method:
##' # 'kill' method:
##' server$kill()
##' tryCatch(client$status(), error = function(e) message(e$message))
##' }
Expand All @@ -98,14 +97,18 @@ vault_test_server <- function(https = FALSE, init = TRUE,
##' @rdname vault_test_server
##'
##' @param quiet Suppress progress bars on install
##' @param path Path in which to install vault test server. Leave as NULL to use the
##' \emph{VAULTR_TEST_SERVER_BIN_PATH} environment variable.
##'
##' @param path Path in which to install vault test server. Leave as
##' `NULL` to use the `VAULTR_TEST_SERVER_BIN_PATH` environment
##' variable.
##'
##' @param version Version of vault to install
##' @param platform For testing, overwrite the platform vault is being installed
##' on, with either "windows", "darwin" or "linux".
##'
##' @param platform For testing, overwrite the platform vault is being
##' installed on, with either "windows", "darwin" or "linux".
##'
##' @export
vault_test_server_install <- function(path = NULL, quiet = FALSE,
vault_test_server_install <- function(path = NULL, quiet = FALSE,
version = "1.0.0",
platform = vault_platform()) {
if (!identical(Sys.getenv("NOT_CRAN"), "true")) {
Expand All @@ -120,7 +123,7 @@ vault_test_server_install <- function(path = NULL, quiet = FALSE,
stop("VAULTR_TEST_SERVER_BIN_PATH is not set")
}
}

dir_create(path)
dest <- file.path(path, vault_exe_filename(platform))
if (file.exists(dest)) {
Expand Down Expand Up @@ -269,8 +272,6 @@ vault_server_start_dev <- function(bin, port) {
Sys.sleep(0.5) # nocov
}

txt2 <- readLines(process$get_error_file())

## See https://www.vaultproject.io/docs/secrets/kv/kv-v2.html#setup
##
## > when running a dev-mode server, the v2 kv secrets engine is
Expand Down Expand Up @@ -350,7 +351,7 @@ vault_url <- function(version, platform = vault_platform(), arch = "amd64") {
}

vault_exe_filename <- function(platform = vault_platform()) {
if (platform == 'windows') {
if (platform == "windows") {
"vault.exe"
} else {
"vault"
Expand Down
13 changes: 7 additions & 6 deletions R/util.R
Expand Up @@ -9,11 +9,11 @@ to_json <- function(x) {
}


`%||%` <- function(a, b) {
`%||%` <- function(a, b) { # nolint
if (is.null(a)) b else a
}

`%&&%` <- function(a, b) {
`%&&%` <- function(a, b) { # nolint
if (is.null(a)) NULL else b
}

Expand All @@ -31,10 +31,11 @@ is_absolute_path <- function(path) {
substr(path, 1, 1) == "/"
}

vlapply <- function(X, FUN, ...) {
vlapply <- function(X, FUN, ...) { # nolint
vapply(X, FUN, logical(1), ...)
}
vcapply <- function(X, FUN, ...) {

vcapply <- function(X, FUN, ...) { # nolint
vapply(X, FUN, character(1), ...)
}

Expand All @@ -53,7 +54,7 @@ strsub <- function(str, tr) {
str
}

Sys_getenv <- function(name, unset = NULL, mode = "character") {
Sys_getenv <- function(name, unset = NULL, mode = "character") { # nolint
value <- Sys.getenv(name, NA_character_)
if (is.na(value)) {
value <- unset
Expand Down Expand Up @@ -171,7 +172,7 @@ decode64 <- function(input) {
}


isFALSE <- function(x) {
isFALSE <- function(x) { # nolint
is.logical(x) && length(x) == 1L && !is.na(x) && !x
}

Expand Down

0 comments on commit 8e90453

Please sign in to comment.