Skip to content

Commit

Permalink
feat: Automatically extract connect/workbench versions
Browse files Browse the repository at this point in the history
  • Loading branch information
csgillespie committed Jun 24, 2024
1 parent db1e50f commit fd57fae
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 13 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: audit.base
Title: Base package for Posit Checks
Version: 0.6.16
Version: 0.6.17
Authors@R:
person("Jumping", "Rivers", , "[email protected]", role = c("aut", "cre"))
Description: Base package for sharing classes between posit audit
Expand All @@ -25,6 +25,7 @@ Imports:
yaml
Suggests:
jsonlite,
rvest,
testthat (>= 3.0.0)
Remotes:
jumpingrivers/serverHeaders
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# audit.base 0.6.17 _2024-06-24_
- chore: Software bump
- feat: Automatically extract connect/workbench versions

# audit.base 0.6.16 _2024-06-24_
- chore: Use jrStyling

Expand Down
10 changes: 7 additions & 3 deletions R/posit_versions.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ get_posit_versions = function(type = c("connect", "workbench", "drivers")) {
mustWork = TRUE, package = "audit.base"
)
versions = readr::read_csv(fname, comment = "#", col_types = c("c", "c"))
versions = dplyr::arrange(versions, dplyr::desc(name))
versions = dplyr::arrange(versions, dplyr::desc(.data$version))
return(versions)
}

Expand Down Expand Up @@ -45,13 +45,17 @@ audit_posit_version = function(posit_version, type = c("connect", "workbench", "
return(invisible(NULL))
}



lookup_version = function(posit_version, type) {
versions = get_posit_versions(type = type)
version_as_date = version_to_date(posit_version)
if (is.na(version_as_date) || version_as_date < min(versions$date)) {
all_dates = unlist(purrr::map(versions$version, version_to_date))

if (is.na(version_as_date) || version_as_date < min(all_dates)) {
# Older than DB
row_number = NA_integer_
} else if (version_as_date > max(versions$date)) {
} else if (version_as_date > max(all_dates)) {
# Newer than DB
row_number = 1L
} else {
Expand Down
12 changes: 6 additions & 6 deletions R/rvest.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ extract_cves = function(url) {
sections = rvest::html_elements(page, "section")
v_tibbles = purrr::map_df(sections, extract_components)
all_v = get_all_versions(page) |>
dplyr::filter(!.data$name %in% v_tibbles$name) %>%
dplyr::filter(!.data$version %in% v_tibbles$version) %>%
dplyr::bind_rows(v_tibbles) %>%
dplyr::arrange(dplyr::desc(name))
dplyr::arrange(dplyr::desc(.data$version))
all_v
}

extract_components = function(section) {
posit_name = rvest::html_attrs(section)
posit_name = as.vector(posit_name["id"])
posit_id = stringr::str_extract(posit_name, "[0-9]{4}\\.[0-9]{1,2}\\.[0-9]{1,2}")
posit_version = stringr::str_extract(posit_name, "[0-9]{4}\\.[0-9]{1,2}\\.[0-9]{1,2}")

li = section %>%
rvest::html_elements("li") %>%
Expand All @@ -21,10 +21,10 @@ extract_components = function(section) {
cves = stringr::str_extract(li, "^CVE-[0-9]{4}-[0-9]*")
cves = cves[!is.na(cves)]

if (length(cves) == 0L || is.na(posit_id)) {
if (length(cves) == 0L || is.na(posit_version)) {
NULL
} else {
tibble::tibble(name = posit_id, cve = cves)
tibble::tibble(version = posit_version, cve = cves)
}
}

Expand All @@ -33,7 +33,7 @@ get_all_versions = function(page) {
rvest::html_nodes('h2') %>%
rvest::html_text()
v = stringr::str_extract(versions, "202[0-9]\\.[0-9]{2}\\.[0-9]{1,2}")
tibble::tibble(name = v[!is.na(v)], cve = "")
tibble::tibble(version = v[!is.na(v)], cve = "")
}

update_posit_csv = function() {
Expand Down
2 changes: 1 addition & 1 deletion inst/extdata/versions/connect.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name,cve
version,cve
2024.05.0,CVE-2024-24787
2024.05.0,CVE-2024-24788
2024.05.0,CVE-2024-24787
Expand Down
2 changes: 1 addition & 1 deletion inst/extdata/versions/workbench.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name,cve
version,cve
2024.04.2,
2024.04.1,
2024.04.0,
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-quarto-helpers.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
test_that("Quarto Outputs", {
out = list()
out$posit_version = "2022.10.0"
msg = get_quarto_posit_version_msg(out, "connect")
msg = get_quarto_posit_version_msg(out, type = "connect")
expect_true(stringr::str_detect(msg, "CVEs"))

out$posit_version = "2012.10.0"
Expand Down

0 comments on commit fd57fae

Please sign in to comment.