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
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}
0 commit comments