Skip to content

refactor: use v1 keys API in integration test setup #409

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

Merged
merged 3 commits into from
May 13, 2025
Merged
Changes from all commits
Commits
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
72 changes: 28 additions & 44 deletions R/utils-ci.R
Original file line number Diff line number Diff line change
Expand Up @@ -199,59 +199,43 @@ build_test_env <- function(
)
}

# set up the first admin
create_first_admin <- function(
url,
user,
password,
email,
keyname = "first-key",
provider = "password"
) {
create_first_admin <- function(url, user, password, email) {
warn_dire("create_first_admin")
check_connect_license(url)

# Use HackyConnect to create the user and log in with password,
# then create an API key.
client <- HackyConnect$new(server = url, api_key = NULL)

if (provider == "password") {
tryCatch(
{
client$POST(
path = v1_url("users"),
body = list(
username = user,
password = password,
email = email
)
)
},
error = function(e) {
message(glue::glue("Error creating first admin: {e}"))
}
)
} else if (provider %in% c("ldap", "pam")) {
# can just log in using user / password
} else {
stop("Unsupported authentication provider")
}

client$login(
user = user,
password = password
new_user_payload <- list(
username = user,
password = password,
email = email
)

# Is this called to ensure that it succeeds?
# It was flagged by lintr as assigning a variable that is not used.
client$me()

api_key <- client$POST(
path = unversioned_url("keys"),
body = list(name = keyname)
tryCatch(
new_user <- client$POST(path = v1_url("users"), body = new_user_payload),
error = function(e) {
message(glue::glue("Error creating first admin: {e}"))
}
)

return(
connect(url, api_key$key)
client$login(user = user, password = password)

api_key <- tryCatch(
client$POST(
path = v1_url("users", new_user[["guid"]], "keys"),
body = list(name = "first-key")
),
error = function(e) {
client$POST(
unversioned_fallback_url("keys"),
body = list(name = "first-key")
)
}
)

# Then we return a non-hacky Connect object with the API key
connect(url, api_key$key)
}

HackyConnect <- R6::R6Class(
Expand Down