Browse Source

progress bars and fixed issue when 0 api results came back

master
boB Rudis 3 years ago
parent
commit
cd1a2ca1d2
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 7
      DESCRIPTION
  2. 1
      NAMESPACE
  3. 4
      NEWS.md
  4. 2
      R/assessments.R
  5. 4
      R/attackerkb-package.R
  6. 2
      R/contributor.R
  7. 2
      R/topics.R
  8. 20
      R/utils.R
  9. 4
      man/attackerkb.Rd
  10. 2
      man/attackerkb_api_key.Rd
  11. 3
      man/kb_assessments.Rd
  12. 3
      man/kb_contributors.Rd
  13. 3
      man/kb_topics.Rd

7
DESCRIPTION

@ -1,8 +1,8 @@
Package: attackerkb
Type: Package
Title: Tools to Query the Rapid7 AttackerKB API
Version: 0.1.0
Date: 2020-04-15
Version: 0.1.1
Date: 2020-04-18
Authors@R: c(
person("Bob", "Rudis", email = "bob@rud.is", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-5670-2640"))
@ -22,6 +22,7 @@ Depends:
Imports:
httr,
jsonlite,
data.table
data.table,
progress
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.0

1
NAMESPACE

@ -10,3 +10,4 @@ export(kd_contributor)
import(httr)
importFrom(data.table,rbindlist)
importFrom(jsonlite,fromJSON)
importFrom(progress,progress_bar)

4
NEWS.md

@ -1,2 +1,6 @@
0.1.1
* Fixed an issue where errors wld be thrown if zero API results came back
* Added progress spinner for API calls vs the hacky dots
0.1.0
* Initial release

2
R/assessments.R

@ -3,6 +3,8 @@
#' The main `kb_contributors` function maps 1:1 to the API. Leave values
#' `NULL` that you do not want included in the search parameters.
#'
#' Set the option `progress_enabled` to `FALSE` to disable progress spinner.
#'
#' @param assessment_id UUID of a specific assessment to return
#' @param editor_id UUID of a contributor.
#' @param topid_id UUID of the topic this assessment was based on.

4
R/attackerkb-package.R

@ -4,6 +4,9 @@
#' various aspects of emergent or existing vulnerabilities and the community can query and
#' retrieve results. Tools are provided to query the AttackerKB API.
#'
#' For all API calls, set the option `progress_enabled` to `FALSE` to disable
#' progress spinner.
#'
#' @md
#' @name attackerkb
#' @keywords internal
@ -11,4 +14,5 @@
#' @import httr
#' @importFrom jsonlite fromJSON
#' @importFrom data.table rbindlist
#' @importFrom progress progress_bar
"_PACKAGE"

2
R/contributor.R

@ -3,6 +3,8 @@
#' The main `kb_contributors` function maps 1:1 to the API. Leave values
#' `NULL` that you do not want included in the search parameters.
#'
#' Set the option `progress_enabled` to `FALSE` to disable progress spinner.
#'
#' @param contributor_id UUID of a specific contributror to return
#' @param username Return contributors with the matching username.
#' @param avatar Return all contributors where avatar matches the given value

2
R/topics.R

@ -3,6 +3,8 @@
#' The main `kb_topics` function maps 1:1 to the API. Leave values
#' `NULL` that you do not want included in the search parameters.
#'
#' Set the option `progress_enabled` to `FALSE` to disable progress spinner.
#'
#' @param topic_id UUID of a specific topic to return
#' @param editor_id UUID of a contributor
#' @param name Text to query the name attribute. A substring match is performed

20
R/utils.R

@ -1,9 +1,18 @@
date_convert <- function(.x) {
as.POSIXct(.x, format="%Y-%m-%dT%H:%M:%OS", tz="GMT")
}
.kb_reshape <- function(.x, path) {
if (length(.x) == 0) return(data.frame(stringsAsFactors=FALSE))
if (path == "/topics") {
easy_cols <- .x[, c("id", "editorId", "name", "created", "revisionDate", "disclosureDate", "document")]
easy_cols[["created"]] <- date_convert(easy_cols[["created"]])
easy_cols[["revisionDate"]] <- date_convert(easy_cols[["revisionDate"]])
easy_cols$references <- .x[["metadata"]][["references"]]
cvss_v3 <- .x[["metadata"]][["baseMetricV3"]][["cvssV3"]]
@ -46,12 +55,16 @@
} else if (path == "/contributors") {
.x[["created"]] <- date_convert(.x[["created"]])
.x
} else if (path == "/assessments") {
easy_cols <- .x[,c("id", "editorId", "topicId", "created", "revisionDate", "document", "score")]
easy_cols[["created"]] <- date_convert(easy_cols[["created"]])
easy_cols[["revisionDate"]] <- date_convert(easy_cols[["revisionDate"]])
metadata <- easy_cols[["metadata"]]
easy_cols$tags <- metadata[["tags"]]
@ -79,6 +92,9 @@
handle_response <- function(.x, api_key = attackerkb_api_key()) {
.pb <- progress::progress_bar$new(format = "(:spin)", total = NA)
.pb$tick()
path <- .x[["links"]][["self"]][["href"]]
ret <- .x[["data"]]
@ -89,7 +105,7 @@ handle_response <- function(.x, api_key = attackerkb_api_key()) {
while(length(next_href)) {
cat(".")
.pb$tick()
httr::GET(
url = sprintf("https://api.attackerkb.com%s", next_href),
@ -108,8 +124,6 @@ handle_response <- function(.x, api_key = attackerkb_api_key()) {
}
cat("\n")
class(ret) <- c("tbl_df", "tbl", "data.frame")
ret

4
man/attackerkb.Rd

@ -10,6 +10,10 @@ Rapid7 manages a service — \url{https://attackerkb.com/} - where experts can e
various aspects of emergent or existing vulnerabilities and the community can query and
retrieve results. Tools are provided to query the AttackerKB API.
}
\details{
For all API calls, set the option \code{progress_enabled} to \code{FALSE} to disable
progress spinner.
}
\seealso{
Useful links:
\itemize{

2
man/attackerkb_api_key.Rd

@ -10,7 +10,7 @@ attackerkb_api_key(force = FALSE)
\item{force}{Force setting a new AttackerKB key for the current environment?}
}
\value{
atomic character vector containing the AttackerKB api key
atomic character vector containing the AttackerKB API key
}
\description{
The API wrapper functions in this package all rely on a AttackerKB API

3
man/kb_assessments.Rd

@ -45,6 +45,9 @@ kb_assessment(assessment_id, api_key = attackerkb_api_key())
The main \code{kb_contributors} function maps 1:1 to the API. Leave values
\code{NULL} that you do not want included in the search parameters.
}
\details{
Set the option \code{progress_enabled} to \code{FALSE} to disable progress spinner.
}
\references{
\url{https://api.attackerkb.com/api-docs/docs}
}

3
man/kb_contributors.Rd

@ -36,6 +36,9 @@ kd_contributor(contributor_id, api_key = attackerkb_api_key())
The main \code{kb_contributors} function maps 1:1 to the API. Leave values
\code{NULL} that you do not want included in the search parameters.
}
\details{
Set the option \code{progress_enabled} to \code{FALSE} to disable progress spinner.
}
\references{
\url{https://api.attackerkb.com/api-docs/docs}
}

3
man/kb_topics.Rd

@ -51,6 +51,9 @@ kb_topic(
The main \code{kb_topics} function maps 1:1 to the API. Leave values
\code{NULL} that you do not want included in the search parameters.
}
\details{
Set the option \code{progress_enabled} to \code{FALSE} to disable progress spinner.
}
\references{
\url{https://api.attackerkb.com/api-docs/docs}
}

Loading…
Cancel
Save