keyring icon indicating copy to clipboard operation
keyring copied to clipboard

keyring 1.2.0 not working when kniting R markdown file

Open SueYang opened this issue 4 years ago • 7 comments

Hi, when using latest version (1.2.0) to knit R markdown file, there's no prompt for password.

if(!exists(".pwd")) { tryCatch({ .pwd<- key_get("db", keyring = "ds") # make sure to lock the keyring at the end keyring_lock("ds") }, error = function(e) { cat("Error when unlocking ds") stop() } ) }

And the error message are image

After switching back to older version keyring (1.1.0) the problem is gone.

SueYang avatar Oct 05 '21 20:10 SueYang

Can you please include the error message from keyring?

gaborcsardi avatar Oct 05 '21 20:10 gaborcsardi

Hi I already pasted the error message in the op

SueYang avatar Oct 05 '21 20:10 SueYang

No, it is not. Your code catches the error in e and then ignores it and throws another error without an error message.

E.g.

tryCatch(
  stop("original error message"), 
  error = function(e) { 
    cat("something failed"); stop() 
  }
)
#> something failedError in value[[3L]](cond) :

Btw. it also does not run keyring_lock("ds") on error, if that was your intent.

gaborcsardi avatar Oct 05 '21 20:10 gaborcsardi

Got it. I remove the trycatch part and here's the error message from keyring package: image

SueYang avatar Oct 05 '21 20:10 SueYang

I have this problem and it's really hurting. This works if I use getPass instead.

I could work around this issue if keyring_create allowed an optional password to be passed in. It would be more logic in my code I'm working on.

However at present this blocks me from being able to use keyring to manage api_keys for producing reports in Rmarkdown.

---
title: "test pass"
author: "Biostatistics IT Staff"
date: "11/4/2021"
output: html_document
---

\```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)

library(getPass)
library(askpass)

\```

# getPass

\```{r getpass}
getPass()
\```

# askpass

\```{r askpass}
askpass()
\```

spgarbet avatar Nov 04 '21 18:11 spgarbet

Also I'm using R 4.1.2. RStudio, 2021.09.0 Build 351

spgarbet avatar Nov 04 '21 18:11 spgarbet

This will be eventually fixed in askpass: https://github.com/r-lib/askpass/issues/3

Until then you can use a workaround and query the password with getPass() first:

keyring::keyring_unlock("ds", password = getPass::getPass())
.pwd<- key_get("db", keyring = "ds")

gaborcsardi avatar Nov 28 '21 17:11 gaborcsardi