Skip to content

Commit dcc15ef

Browse files
committed
feat: Pass tokens as arguments
1 parent 236e746 commit dcc15ef

24 files changed

+231
-229
lines changed

.Rbuildignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@
1717
^docs$
1818
^pkgdown$
1919
^\.github$
20+
^[.]?air[.]toml$
21+
^\.vscode$

.lintr

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
linters: with_defaults(
2-
assignment_linter = NULL,
3-
object_name_linter = NULL,
4-
trailing_whitespace_linter = NULL,
5-
line_length_linter(100)
6-
)
1+
linters: linters_with_defaults(
2+
assignment_linter = NULL,
3+
indentation_linter = NULL,
4+
commented_code_linter = NULL,
5+
object_length_linter = NULL,
6+
object_name_linter = NULL,
7+
line_length_linter(100),
8+
cyclocomp_linter(complexity_limit = 15),
9+
undesirable_operator_linter = undesirable_operator_linter(
10+
op = list("<-" = "Please use '=' for assignment")))

DESCRIPTION

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: oysteR
22
Title: Scans R Projects for Vulnerable Third Party Dependencies
3-
Version: 0.1.3.9001
4-
Authors@R:
3+
Version: 0.1.4
4+
Authors@R:
55
c(person(given = "Jeffry",
66
family = "Hesse",
77
role = "aut",
@@ -33,10 +33,10 @@ Description: Collects a list of your third party R packages, and
3333
use.
3434
License: Apache License 2.0 | file LICENSE
3535
URL: https://github.com/sonatype-nexus-community/oysteR
36-
BugReports:
36+
BugReports:
3737
https://github.com/sonatype-nexus-community/oysteR/issues
3838
Depends:
39-
R (>= 3.5.0)
39+
R (>= 4.0.0)
4040
Imports:
4141
cli,
4242
dplyr,
@@ -57,9 +57,9 @@ Suggests:
5757
knitr,
5858
rmarkdown,
5959
testthat (>= 2.1.0)
60-
VignetteBuilder:
60+
VignetteBuilder:
6161
knitr
6262
Encoding: UTF-8
6363
LazyData: true
6464
Roxygen: list(markdown = TRUE)
65-
RoxygenNote: 7.1.1
65+
RoxygenNote: 7.3.3

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
export(audit)
44
export(audit_conda)
5-
export(audit_deps)
65
export(audit_description)
76
export(audit_installed_r_pkgs)
87
export(audit_renv_lock)

NEWS.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
# oysteR 0.1.3.9001 _2021-05-18_
2-
* Bug: Incorrectly states how many packages were found in the database (see #62)
1+
# oysteR 0.1.4 _2025-10-08_
2+
* bug: Incorrectly states how many packages were found in the database (see #62)
3+
* feat: Pass tokens as arguments
4+
* chore: Formatting via air
5+
* chore: linting
36

4-
# oysteR 0.1.3 _2021-03-11-_
7+
# oysteR 0.1.3 _2021-03-11-_
58
* Internal: Return missing values as `NA`'s (see #59)
69

7-
# oysteR 0.1.2 _2021-02-26_
8-
* Feature: Add `audit_conda()` functions
10+
# oysteR 0.1.2 _2021-02-26_
11+
* Feature: Add `audit_conda()` functions
912
* Feature: Add Josiah Parry as an author
1013
* Feature: Handle missing versions in a nice way
1114

1215
# oysteR 0.1.1 _2021-01-08_
1316
* Use `dontrun{}` in examples that may hit rate limits.
1417

15-
# oysteR 0.1.0 _2020-12-17_
18+
# oysteR 0.1.0 _2020-12-17_
1619
* Feature: Add API caching. Calls are now cached for 12 hours (on R4+ only)
1720
* Feature: Extract packages from `requirements.txt`, `renv.lock`, and `environment.yml` files
1821
* Feature: Handle more general vulnerabilities

R/audit.R

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#' By default it will search all known versions. If not `*`, must be the same length as pkg.
2424
#' @param type The package management environment. For R packages, set equal to "cran".
2525
#' This defaults to \code{"cran"}. See https://ossindex.sonatype.org/ecosystems.
26+
#' @param token If NULL, looks at OSSINDEX_USER & OSSINDEX_TOKEN, env variables. If those
27+
#' aren't available, try `"~/.ossindex/.oss-index-config"`
2628
#' @param verbose Default \code{TRUE}.
2729
#'
2830
#' @export
@@ -32,10 +34,13 @@
3234
#' version = c("1.4-5", "1.4.1")
3335
#' audit(pkg, version, type = "cran")
3436
#' }
35-
audit = function(pkg, version, type, verbose = TRUE) {
36-
37-
if (is.null(pkg)) pkg = character(0)
38-
if (is.null(version)) version = character(0)
37+
audit = function(pkg, version, type, verbose = TRUE, token = NULL) {
38+
if (is.null(pkg)) {
39+
pkg = character(0)
40+
}
41+
if (is.null(version)) {
42+
version = character(0)
43+
}
3944
# Create the purls. Checks will be inherited
4045
purls = generate_purls(pkg, version, type)
4146
## Get cache & remove cached purls
@@ -51,16 +56,20 @@ audit = function(pkg, version, type, verbose = TRUE) {
5156
pkgs = tibble::tibble(package = pkg, version = version, type = type)[!is_cached, ]
5257

5358
## Call OSS index on remaining
54-
results = call_oss_index(purls, verbose = verbose)
59+
results = call_oss_index(purls, verbose = verbose, token = token)
5560
audit = dplyr::bind_cols(pkgs, results)
5661

5762
# Update cache and combine
5863
update_cache(audit)
5964
# Replace NA versions
6065
audit = dplyr::bind_rows(audit, cache) %>%
61-
mutate(description = dplyr::if_else(is.na(version), NA_character_, .data$description),
62-
no_of_vulnerabilities = dplyr::if_else(is.na(version), NA_integer_,
63-
.data$no_of_vulnerabilities),
66+
mutate(
67+
description = dplyr::if_else(is.na(version), NA_character_, .data$description),
68+
no_of_vulnerabilities = dplyr::if_else(
69+
is.na(version),
70+
NA_integer_,
71+
.data$no_of_vulnerabilities
72+
),
6473
)
6574
if (isTRUE(verbose)) {
6675
audit_verbose(audit)
@@ -72,7 +81,7 @@ audit = function(pkg, version, type, verbose = TRUE) {
7281
#'
7382
#' Audits all installed packages by calling \code{installed.packages()}
7483
#' and checking them against the OSS Index.
75-
#' @param verbose Default \code{TRUE}.
84+
#' @inheritParams audit
7685
#' @return A tibble/data.frame.
7786
#' @importFrom utils installed.packages
7887
#' @export
@@ -82,7 +91,7 @@ audit = function(pkg, version, type, verbose = TRUE) {
8291
#' # This calls installed.packages()
8392
#' pkgs = audit_installed_r_pkgs()
8493
#' }
85-
audit_installed_r_pkgs = function(verbose = TRUE) {
94+
audit_installed_r_pkgs = function(verbose = TRUE, token = NULL) {
8695
pkgs = get_r_pkgs(verbose = verbose)
87-
audit(pkg = pkgs$package, version = pkgs$version, type = "cran", verbose = verbose)
96+
audit(pkg = pkgs$package, version = pkgs$version, type = "cran", verbose = verbose, token = token)
8897
}

R/cache.R

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@ get_cache_dir = function() {
66
get_cache_file = function() {
77
dir = get_cache_dir()
88
path = file.path(dir, "cached-deps.rds")
9-
return(path)
9+
path
1010
}
1111

1212
ensure_cache = function() {
1313
path = get_cache_file()
14-
if (file.exists(path)) return(path)
14+
if (file.exists(path)) {
15+
return(path)
16+
}
1517

1618
dir.create(get_cache_dir(), recursive = TRUE, showWarnings = FALSE)
1719
audits = no_purls_case()
1820
audits$time = integer(0)
1921
class(audits$time) = c("POSIXct", "POSIXt")
2022
saveRDS(audits, file = path)
21-
return(path)
23+
path
2224
}
2325

2426
## General cache idea
@@ -29,7 +31,9 @@ ensure_cache = function() {
2931
#' @importFrom rlang .data
3032
get_cache = function() {
3133
## Only available for R4+
32-
if (getRversion() < "4.0.0") return(no_purls_case())
34+
if (getRversion() < "4.0.0") {
35+
return(no_purls_case())
36+
}
3337
path = ensure_cache()
3438
audits = readRDS(path) %>%
3539
dplyr::filter(.data$time > Sys.time() - 60 * 60 * 12) %>%
@@ -38,7 +42,9 @@ get_cache = function() {
3842
}
3943

4044
update_cache = function(audits) {
41-
if (getRversion() < "4.0.0") return(audits)
45+
if (getRversion() < "4.0.0") {
46+
return(audits)
47+
}
4248
audits$time = Sys.time()
4349
path = ensure_cache()
4450

@@ -49,7 +55,7 @@ update_cache = function(audits) {
4955
dplyr::bind_rows(audits)
5056

5157
saveRDS(audits, file = path)
52-
return(audits)
58+
audits
5359
}
5460

5561
#' Remove cache
@@ -60,6 +66,8 @@ update_cache = function(audits) {
6066
#' @export
6167
remove_cache = function() {
6268
path = get_cache_file()
63-
if (file.exists(path)) file.remove(path)
64-
return(NULL)
69+
if (file.exists(path)) {
70+
file.remove(path)
71+
}
72+
NULL
6573
}

0 commit comments

Comments
 (0)