Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ rsconnect/
^report.html$
^README\.Rmd$
^\.github$
^[.]?air[.]toml$
^\.vscode$
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ Config/testthat/edition: 3
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# audit.connect 0.7.6 _2025-07-16_
- chore: Formatting using air
- chore: Update linting

# audit.connect 0.7.5 _2024-07-24_
- fix: Remove feature usage - experimental API no longer works

# audit.connect 0.7.5 _2024-06-10_
- fix: Use latest version of {connactapi}
- chore: Fix Rd warnings due to R4.4
Expand Down
30 changes: 19 additions & 11 deletions R/audit_details.R
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@

audit_details = function(server, token) {
user_details = summarise_user(server, token)
c(user_details,
list(server = server,
time = Sys.time(),
version = utils::packageVersion("audit.connect"))
c(
user_details,
list(
server = server,
time = Sys.time(),
version = utils::packageVersion("audit.connect")
)
)
}

# Details on the user running this audit
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)))
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}>")
cli::cli_alert_info(
"{content$first_name} {content$last_name} <{content$email}>"
)
cli::cli_alert_info("Username: {content$username}")
cli::cli_alert_info("Role: {content$user_role}")
set_key("username", content$username)
set_key("connect_account", content$username)
return(invisible(content))
invisible(content)
}

check_api_status_code = function(res) {
Expand All @@ -31,8 +37,10 @@ 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_alert_danger(
"You could try changing http <-> https in the server URL"
)
cli::cli_abort("Status code: {status}")
}
return(invisible(NULL))
invisible(NULL)
}
22 changes: 13 additions & 9 deletions R/check.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,27 @@
#' @importFrom rlang .data .env
#' @import audit.base
#' @export
check = function(server = NULL, token = NULL,
dir = ".",
debug_level = 0:2) {

check = function(server = NULL, token = NULL, dir = ".", debug_level = 0:2) {
debug_level = get_debug_level(force(debug_level))
check_list = list()
check_list$setup = summarise_setup(server, token)
check_list$audit_details = audit_details(get_server(), get_token())
check_list$server_headers = audit.base::check_server_headers(get_server())
check_list$posit_version = check_posit_version(get_server(), get_token(),
debug_level = debug_level)
check_list$posit_version = check_posit_version(
get_server(),
get_token(),
debug_level = debug_level
)
check_list$sys_deps = check_sys_deps(debug_level = debug_level)
check_list$versions = summarise_versions(get_server(), get_token())

# check_list$feature_usage = summarise_feature_usage(get_server(), get_token())
# check_list$feature_usage = summarise_feature_usage(get_server(), get_token()) #nolint
check_list$audit_details = audit_details(get_server(), get_token())
check_list$users_details = summarise_users(get_server(), get_token(), debug_level = debug_level)
check_list$users_details = summarise_users(
get_server(),
get_token(),
debug_level = debug_level
)
register_uat_user(get_server(), get_token(), account = get_account())

check_list$results = check_deployments(dir, debug_level)
Expand All @@ -53,5 +57,5 @@ init_r6_check = function(export, dir, file) {
} else {
obj = NULL
}
return(obj)
obj
}
2 changes: 1 addition & 1 deletion R/check_deployments.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ check_deployments = function(dir, debug_level) {
cli::cli_h2("Document Deployment Checks")
r6_inits = init_r6_checks(dir = dir, file = "config-uat-rsc.yml")
lapply(r6_inits, function(r6) r6$check(debug_level = debug_level))
deployments = purrr::map_dfr(r6_inits, ~.x$get_log())
deployments = purrr::map_dfr(r6_inits, ~ .x$get_log())
deployments = dplyr::arrange(deployments, .data$group, .data$short)
deployments
}
7 changes: 5 additions & 2 deletions R/check_posit_version.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ check_posit_version = function(server, token, debug_level) {
client = suppress(connectapi::connect(server = server, api_key = token))

posit_version = client$server_settings()$version
audit.base::audit_posit_version(posit_version = posit_version, type = "connect")
return(posit_version)
audit.base::audit_posit_version(
posit_version = posit_version,
type = "connect"
)
posit_version
}
37 changes: 26 additions & 11 deletions R/check_sys_deps.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,24 @@ check_sys_deps = function(debug_level = 0:2) {
debug_level = get_debug_level(debug_level)

app_dir = file.path(tempdir(), "pkg")
pkg_dir = system.file("extdata", "check_sys_deps",
package = "audit.connect",
mustWork = TRUE)
pkg_dir = system.file(
"extdata",
"check_sys_deps",
package = "audit.connect",
mustWork = TRUE
)
fs::dir_copy(pkg_dir, app_dir, overwrite = TRUE)
on.exit(cleanup_plumber(app_dir, content, debug_level))
content = try(setup_plumber_sys_deps_endpoint(app_dir, debug_level), silent = TRUE)
content = try(
setup_plumber_sys_deps_endpoint(app_dir, debug_level),
silent = TRUE
)
if ("try-error" %in% class(content)) {
cli::cli_alert_info("Can't deploy plumber end point - odd?")
cli::cli_alert_info("Check the logs on {get_server()}")
cli::cli_alert_info("In the past, it was due to a missing sodium linux dependency")
cli::cli_alert_info(
"In the past, it was due to a missing sodium linux dependency"
)
return(NA)
}

Expand All @@ -31,21 +39,28 @@ check_sys_deps = function(debug_level = 0:2) {
audit.base::check_sys_deps(rtn$os_release, clean_libs, debug_level)
}

setup_plumber_sys_deps_endpoint = function(app_dir, debug_level) { #nolint
setup_plumber_sys_deps_endpoint = function(app_dir, debug_level) {
suppress = get_suppress(debug_level)
# Deploy plumber
client = suppress(connectapi::connect(server = get_server(), api_key = get_token()))
client = suppress(connectapi::connect(
server = get_server(),
api_key = get_token()
))
bundle = suppress(connectapi::bundle_dir(app_dir))
name = paste("UAT_check_package-", Sys.Date(), sep = "_")
content = suppress(connectapi::deploy(client, bundle, name = name))
suppress(connectapi::poll_task(content))
return(content)
content
}

# Extracting the URL differs on first deployment and subsequent deployments
get_deploy_url = function(content) {
url = content$get_url()
if (is.null(url)) url = content$get_content()$url
if (is.null(url)) stop("Missing deploy url")
return(url)
if (is.null(url)) {
url = content$get_content()$url
}
if (is.null(url)) {
stop("Missing deploy url")
}
url
}
6 changes: 4 additions & 2 deletions R/create_config.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@
#' * force: overwrite existing file
#' * error: if a config file exists, raise an error
#' @export
create_config = audit.base::create_config(file = "config-uat-rsc.yml",
pkg_name = "audit.connect")
create_config = audit.base::create_config(
file = "config-uat-rsc.yml",
pkg_name = "audit.connect"
)
29 changes: 21 additions & 8 deletions R/deploy_app.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# utility functions for testing Rmd | shiny deployments
deploy_app = function(rmd_dir, debug_level, appFiles = c("index.Rmd", "app.R")) { #nolint
deploy_app = function(
rmd_dir,
debug_level,
appFiles = c("index.Rmd", "app.R") #nolint
) {
tmp_dir = tempdir()

file.copy(rmd_dir, tmp_dir, recursive = TRUE)
Expand All @@ -10,7 +14,7 @@ deploy_app = function(rmd_dir, debug_level, appFiles = c("index.Rmd", "app.R"))
deploy_name = get_deploy_name(app_dir)
push_to_connect(bundle_dir = app_dir, deploy_name = deploy_name, debug_level)

return(invisible(TRUE))
invisible(TRUE)
}

get_deploy_name = function(rmd_path) {
Expand All @@ -22,20 +26,29 @@ get_deploy_name = function(rmd_path) {
push_to_connect = function(bundle_dir, deploy_name, debug_level) {
suppress = get_suppress(debug_level)
# Need: CONNECT_API_KEY and CONNECT_SERVER
client = suppress(connectapi::connect(server = get_server(), api_key = get_token()))
client = suppress(connectapi::connect(
server = get_server(),
api_key = get_token()
))
bundle = suppress(connectapi::bundle_dir(bundle_dir))

# If deploy not successful, content not created
content = suppress(connectapi::deploy(client, bundle, title = deploy_name))
on.exit(cleanup_app(bundle_dir, content, debug_level))
suppress(connectapi::poll_task(content))
return(invisible(NULL))
invisible(NULL)
}

cleanup_app = function(bundle_dir, content, debug_level) {
if (debug_level == 2) return(invisible(NULL))
if (debug_level == 2) {
return(invisible(NULL))
}
suppress = get_suppress(debug_level)
if (exists("content")) suppress(connectapi::content_delete(content, force = TRUE))
if (!is.null(bundle_dir) && file.exists(bundle_dir)) fs::dir_delete(bundle_dir)
return(invisible(NULL))
if (exists("content")) {
suppress(connectapi::content_delete(content, force = TRUE))
}
if (!is.null(bundle_dir) && file.exists(bundle_dir)) {
fs::dir_delete(bundle_dir)
}
invisible(NULL)
}
23 changes: 15 additions & 8 deletions R/deploy_flask-r6.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,22 @@ check_deploy_python_flask = R6::R6Class(
check = function(debug_level) {
if (isFALSE(.connect$rsconnect_python)) {
cli::cli_alert_info("rsconnect-python missing. Skipping Python test.")
return(invisible(NULL))
invisible(NULL)
}
python_dir = system.file("extdata", private$group, private$short,
package = "audit.connect", mustWork = TRUE)
private$checker(deploy_python(python_dir,
python_files = "app.py",
rsconnect_type = "api",
debug_level = debug_level))
return(invisible(NULL))
python_dir = system.file(
"extdata",
private$group,
private$short,
package = "audit.connect",
mustWork = TRUE
)
private$checker(deploy_python(
python_dir,
python_files = "app.py",
rsconnect_type = "api",
debug_level = debug_level
))
invisible(NULL)
}
),
private = list(
Expand Down
10 changes: 6 additions & 4 deletions R/deploy_git-r6.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ check_deploy_github = R6::R6Class(
#' @description Deploy a shiny application from github
#' @param debug_level See check() for details
check = function(debug_level) {
private$checker(deploy_git(repository = "https://github.com/uat-examples/old-faithful",
debug_level = debug_level,
title = paste("UAT", private$short)))
return(invisible(NULL))
private$checker(deploy_git(
repository = "https://github.com/uat-examples/old-faithful",
debug_level = debug_level,
title = paste("UAT", private$short)
))
invisible(NULL)
}
),
private = list(
Expand Down
20 changes: 12 additions & 8 deletions R/deploy_git.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
deploy_git = function(repository, debug_level, title) {
suppress = get_suppress(debug_level)

client = suppress(connectapi::connect(server = get_server(), api_key = get_token()))
content = suppress(connectapi::deploy_repo(client,
repository,
branch = "main",
subdirectory = ".",
title = "UAT")
)
client = suppress(connectapi::connect(
server = get_server(),
api_key = get_token()
))
content = suppress(connectapi::deploy_repo(
client,
repository,
branch = "main",
subdirectory = ".",
title = "UAT"
))

# If deploy not successful, content not created
on.exit(cleanup_app(bundle_dir = NULL, content, debug_level))
suppress(connectapi::poll_task(content))

return(invisible(TRUE))
invisible(TRUE)
}
2 changes: 1 addition & 1 deletion R/deploy_pins-r6.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ check_deploy_pins_rds = R6::R6Class(
#' @param debug_level See check() for details
check = function(debug_level) {
private$checker(deploy_pins(debug_level = debug_level))
return(invisible(NULL))
invisible(NULL)
}
),
private = list(
Expand Down
19 changes: 13 additions & 6 deletions R/deploy_pins.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
deploy_pins = function(debug_level) {
suppress = get_suppress(debug_level)
board = suppress(pins::board_connect(auth = "manual", versioned = TRUE,
server = get_server(),
key = get_token()))
board = suppress(pins::board_connect(
auth = "manual",
versioned = TRUE,
server = get_server(),
key = get_token()
))

tmp_env = new.env()
utils::data("mtcars", package = "datasets", envir = tmp_env)
Expand All @@ -19,8 +22,12 @@ deploy_pins = function(debug_level) {
type = "rds"
)
)
if (debug_level != 2L) on.exit(pins::pin_delete(board, deployed_pin))
if (debug_level != 2L) {
on.exit(pins::pin_delete(board, deployed_pin))
}
pulled_data = pins::pin_read(board, deployed_pin)
if (!identical(pulled_data, tmp_env$mtcars)) stop("Corrupted pins data")
return(invisible(TRUE))
if (!identical(pulled_data, tmp_env$mtcars)) {
stop("Corrupted pins data")
}
invisible(TRUE)
}
Loading
Loading