knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(gwangmyeongseong3)

Best practises and hiding passwords and usernames

In this vignette we will be exploring the Lodestar software for sequence annotation and comparative genomics. In the canonical code examples included we will be connecting to a database server that uses a username and password that I would prefer not to be shown in a public-facing technical document.

The Lodestar software uses the r-lib/keyring package to cache and encrypt username::password pairs that are associated with a given RDBMS and database instance.

Thekeyring works out of the box on Windows and MacOS - if you are using a Linux computer please ensure that e.g. libsecret-1-dev has been installed on your system.

# define the objects required for the key ...
RDBMS <- "dummy_psql" 
database <- "lodestar_drosophila"
username <- "dr_evil"
password <- "topsecret"

# define the key object - this will be saved in ~/.config/r-keyring
creds <- lodestar_creds(
  username=username, password=password, 
  service=database, keyring=RDBMS)

# let's see what has been saved in the keychain
creds$keyring_is_locked(RDBMS)
creds$list(keyring = RDBMS, service=database)

# and show how the password can be extracted again ...
creds$get(keyring = RDBMS, service=database, username=username)

# delete this keyring
creds$keyring_delete(RDBMS)

Users working with simple installations should only need to define a simple lodestar_creds configuration once; other steps within this Vignette will automatically pick up these config facets.

Connecting to a PostgreSQL database server

On this development and documentation server, I am running a Postgres server. The installation defines a user, stephen who with the appropriate password is allowed to connect to an exemplar database called lodestar.

lsconn <- LodestarConn$new()
conn <- lsconn$connection()
print(conn)
clist = c("a", "b", "c")
cli::cli_alert_success("Downloaded {length(clist)} packages")


sagrudd/gwangmyeongseong3 documentation built on Jan. 25, 2021, 5:44 a.m.