Keep your secrets safe and sound in the cloud! 🚀
An R package that makes it easy and secure to manage your secrets using Google Cloud Secret Manager. Whether you're building a Shiny app, running R scripts in production, or managing sensitive configuration, googlesecretmanager has got you covered!
# Install the package
# remotes::install_github("brancengregory/googlesecretmanager")
install.packages("googlesecretmanager", repos = c('https://brancengregory.r-universe.dev', 'https://cloud.r-project.org'))
# Load and authenticate (opens browser)
library(googlesecretmanager)
gargle::credentials_app_default()
# Start managing secrets!
sm_project_set("my-project-id")
sm_secret_create("api-key", replication = list(automatic = list()))
sm_secret_version_add("api-key", "your-secret-value")
You can install the development version of googlesecretmanager from GitHub using:
# install.packages("remotes")
# remotes::install_github("brancengregory/googlesecretmanager")
install.packages("googlesecretmanager", repos = c('https://brancengregory.r-universe.dev', 'https://cloud.r-project.org'))
This package uses gargle for secure authentication with Google Cloud. Choose your preferred method:
library(googlesecretmanager)
gargle::credentials_app_default() # Opens browser for authentication
library(googlesecretmanager)
gargle::credentials_service_account(
path = "path/to/service-account-key.json"
)
library(googlesecretmanager)
token <- gargle::token_fetch(
scopes = "https://www.googleapis.com/auth/cloud-platform"
)
googlesecretmanager_auth(token = token)
# Store an API key
sm_secret_create("stripe-api-key")
sm_secret_version_add("stripe-api-key", "sk_live_...")
# Retrieve in your application
api_key <- sm_secret_version_access("stripe-api-key")
# Store database credentials
db_config <- list(
host = "db.example.com",
user = "admin",
password = "secret123"
)
sm_secret_create("db-config")
sm_secret_version_add("db-config", jsonlite::toJSON(db_config))
# Use in your application
config <- jsonlite::fromJSON(sm_secret_version_access("db-config"))
# Add a new version
sm_secret_version_add("api-key", "new-secret-value")
# List versions
versions <- sm_secret_version_ls("api-key")
# Delete old versions
sm_secret_version_delete("api-key", "old-version-id")
Authentication Failed
Secret Not Found
Permission Denied
This package is built with:
Contributions are welcome! Please:
This project is licensed under the MIT License - see the LICENSE file for details.