Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keyring 1.2.0 not working when kniting R markdown file #116

Open
SueYang opened this issue Oct 5, 2021 · 7 comments
Open

keyring 1.2.0 not working when kniting R markdown file #116

SueYang opened this issue Oct 5, 2021 · 7 comments
Labels
bug an unexpected problem or unintended behavior

Comments

@SueYang
Copy link

SueYang commented Oct 5, 2021

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.

@gaborcsardi
Copy link
Member

Can you please include the error message from keyring?

@SueYang
Copy link
Author

SueYang commented Oct 5, 2021

Hi I already pasted the error message in the op

@gaborcsardi
Copy link
Member

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.

@SueYang
Copy link
Author

SueYang commented Oct 5, 2021

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

@spgarbet
Copy link

spgarbet commented Nov 4, 2021

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
Copy link

spgarbet commented Nov 4, 2021

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

@gaborcsardi
Copy link
Member

This will be eventually fixed in askpass: r-lib/askpass#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 gaborcsardi added the bug an unexpected problem or unintended behavior label Nov 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

3 participants