Skip to content

Commit

Permalink
fix: Force server to have https (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
csgillespie authored Apr 4, 2024
1 parent 882d4be commit 116a59f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: audit.connect
Title: Posit Connect Health Check
Version: 0.7.3
Version: 0.7.4
Authors@R:
person("Jumping", "Rivers", , "[email protected]", role = c("aut", "cre"))
Description: Posit Connect Health Check. Deploys various content types to
Expand Down
6 changes: 5 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# audit.connect 0.7.4 _2024-04-04_
- feat: Force `server` to have `http(?s)`
- feat: Improved error message when testing status response

# audit.connect 0.7.3 _2024-03-27_
- fix: Remove additional / from user api call

# audit.connect 0.7.2 _2024-01-24_
- fix: If NA, return 0 locked apps

Expand Down
3 changes: 3 additions & 0 deletions R/audit_details.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

audit_details = function(server, token) {
user_details = summarise_user(server, token)
c(user_details,
Expand All @@ -12,6 +13,7 @@ summarise_user = function(server, token) {
cli::cli_h2("User Summary")
res = httr::GET(paste0(server, "__api__/v1/user"),
httr::add_headers(Authorization = paste("Key", token)))

check_api_status_code(res)
content = httr::content(res)
cli::cli_alert_info("{content$first_name} {content$last_name} <{content$email}>")
Expand All @@ -29,6 +31,7 @@ check_api_status_code = function(res) {
cli::cli_alert_danger("Likely causes are: bad token or bad server URL")
cli::cli_alert_danger("{res$url} has status code {status}")
cli::cli_alert_danger("{httr::http_status(status)$message}")
cli::cli_alert_danger("You could try changing http <-> https in the server URL")
cli::cli_abort("Status code: {status}")
}
return(invisible(NULL))
Expand Down
5 changes: 4 additions & 1 deletion R/summarise_setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ standardise_server_url = function(server) {
server = paste0(server, "/")
}

# We need to enforce adding http, otherwise things get messy. E.g.
# APIs typically need SSL, but if we only have http, that's "OK" to use http.
# But if we try http, and https is needed, it fails.
start_address = stringr::str_starts(server, pattern = "http")
if (isFALSE(start_address)) {
server = paste0("http://", server)
cli::cli_abort("Please add https (or http) to the server URL.")
}
cli::cli_alert_info("Server: {cli::col_green(server)}")
return(invisible(server))
Expand Down

0 comments on commit 116a59f

Please sign in to comment.