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

my attempt at allowing storage of password in Sys env #38

Merged
merged 36 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
8c012bf
my attempt at storing in Sys env
SanderDevisscher Mar 28, 2024
dbb04c9
use keyring?
SanderDevisscher Mar 29, 2024
4c1e6e7
Update get_access_token.Rd
SanderDevisscher Mar 29, 2024
9d27097
import keyring
SanderDevisscher Mar 29, 2024
1fb4669
Update DESCRIPTION
SanderDevisscher Mar 29, 2024
1c8b705
Merge branch 'main' into 20-pass-credentials-via-sys-env
PietrH Mar 29, 2024
5312aef
devtools::document()
PietrH Mar 29, 2024
cada905
Merge branch 'main' into 20-pass-credentials-via-sys-env
PietrH Mar 29, 2024
12b344c
Increment version number to 0.0.1
PietrH Mar 29, 2024
2e938d3
Increment version number to 0.0.1.9000
PietrH Mar 29, 2024
5aaf33c
fix spelling mistake
PietrH Mar 29, 2024
6bf2e9e
directly fetch and hash key when building `httr` request
PietrH Mar 29, 2024
45d5e1e
assert keyring support
PietrH Mar 29, 2024
bea9519
document to set username within the keyring instead
PietrH Mar 29, 2024
cdc7995
Check for multiple stored passwords
PietrH Mar 29, 2024
63c8c78
Stylr
PietrH Mar 29, 2024
d1ecd1d
check if iasset keyring exists
PietrH Apr 2, 2024
81c8510
check if a username is set
PietrH Apr 2, 2024
9183212
prompt if credentials are missing
PietrH Apr 2, 2024
8488e96
add custom message for credentials prompt
PietrH Apr 2, 2024
fd3a4a5
add helper to fetch username associated with credentials
PietrH Apr 2, 2024
d2f56e8
export `get_username()`
PietrH Apr 2, 2024
29d7fe0
set default option for username
PietrH Apr 2, 2024
36e1b60
devtools::document()
PietrH Apr 2, 2024
02119ef
use helper instead
PietrH Apr 2, 2024
892a4de
simply message
PietrH Apr 2, 2024
a32ca64
don't attempt the example
PietrH Apr 2, 2024
6e2bfea
warn, don't stop on missing service
PietrH Apr 2, 2024
92e0bf2
move string assertion to behind where we construct a username sometimes
PietrH Apr 2, 2024
41248a8
check for single user earlier on, fail earlier
PietrH Apr 2, 2024
8055e72
a failing username can also be `characterj(0)`
PietrH Apr 2, 2024
e801285
add whitespace for readability
PietrH Apr 2, 2024
e86c68a
hardcode what username to get the pwd for
PietrH Apr 2, 2024
ea7ed7d
update documentation
PietrH Apr 2, 2024
4f9c60b
remove keyring from namespace + devtools::document()
PietrH Apr 2, 2024
f504bd3
expand multiple usernames error
SanderDevisscher Apr 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: iassetR
Title: Use the iAsset API in R
Version: 0.0.0.9000
Version: 0.0.1.9000
Authors@R: c(
person("Pieter", "Huybrechts", , "[email protected]", role = "aut",
comment = c(ORCID = "0000-0002-6658-6062")),
Expand All @@ -19,6 +19,7 @@ Imports:
glue,
httr2,
janitor,
keyring,
magrittr,
openssl,
purrr,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export("%>%")
export(get_access_token)
export(get_fields)
export(get_records)
import(keyring)
importFrom(magrittr,"%>%")
importFrom(rlang,.data)
30 changes: 26 additions & 4 deletions R/get_access_token.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,43 @@
#' @return Invisibily, an access token upon succes
#' @export
#'
#' @examples \dontrun{get_access_token("my_username")}
#' @details
#' This function uses keyring to retrieve the password. If no password has been
#' set using keyring you'll be prompted to enter your password using askpass.
#' Setting the password using keyring should best be done interactively
#' (in the console) using
#' `keyring::key_set("iasset_password", username = "my_username")`.
#' Keyring uses secret environment variables on GitHub Actions.
#'
#' @import keyring
#' @examples \dontrun{
#' get_access_token("my_username")
#' }
get_access_token <-
function(username, quiet = FALSE) {
# check input params
assertthat::assert_that(assertthat::is.string(username))
assertthat::assert_that(assertthat::is.flag(quiet))
# check for keyring support
assertthat::assert_that(keyring::has_keyring_support())

Check warning on line 27 in R/get_access_token.R

View check run for this annotation

Codecov / codecov/patch

R/get_access_token.R#L27

Added line #L27 was not covered by tests
# check that only one keyring is set
number_of_keyrings <- nrow(keyring::key_list(service = "iasset_password"))
assertthat::assert_that(number_of_keyrings <= 1,
msg = paste(
"iassetR currently only supports storing one iAsset account at a time.",
"Delete any other accounts using",
'keyring::key_delete(service = "iasset_password",',
'username = "username_to_delete")'

Check warning on line 35 in R/get_access_token.R

View check run for this annotation

Codecov / codecov/patch

R/get_access_token.R#L29-L35

Added lines #L29 - L35 were not covered by tests
)
)
# build a request and perform it
login_request <-
httr2::request(base_url = "https://api.iasset.nl/login/")
hash <- askpass::askpass() %>%
openssl::md5()

login_response <- login_request %>%
httr2::req_body_form(
username = username,
password = hash,
password = openssl::md5(keyring::key_get("iasset_password")),

Check warning on line 45 in R/get_access_token.R

View check run for this annotation

Codecov / codecov/patch

R/get_access_token.R#L45

Added line #L45 was not covered by tests
domain = "riparias",
version = "9.7"
) %>%
Expand Down
7 changes: 7 additions & 0 deletions man/get_access_token.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading