Browse Source

examples/tests/workflow

batman
boB Rudis 10 months ago
parent
commit
c01888a9a1
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 4
      .github/workflows/R-CMD-check.yaml
  2. 1
      NAMESPACE
  3. 17
      R/pcap_to_zeek.R
  4. 12
      R/read-zeek-logs.R
  5. 2
      R/zeekr-package.R
  6. 18
      inst/tinytest/test_zeekr.R
  7. 5
      man/find_zeek.Rd
  8. 12
      man/pcap_to_zeek.Rd
  9. 12
      man/read_zeek_logs.Rd

4
.github/workflows/R-CMD-check.yaml

@ -6,7 +6,7 @@ on:
- batman
pull_request:
branches:
- batmsn
- batman
name: R-CMD-check
@ -16,6 +16,8 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: r-lib/actions/setup-r@master
- name: Install Zeek
uses: brew install zeek
- name: Install dependencies
run: |
install.packages(c("remotes", "rcmdcheck"))

1
NAMESPACE

@ -12,3 +12,4 @@ import(ndjson)
importFrom(tools,file_ext)
importFrom(tools,file_path_sans_ext)
importFrom(utils,browseURL)
importFrom(utils,help)

17
R/pcap_to_zeek.R

@ -15,9 +15,15 @@
#' look for the `zeek` binary.
#' @export
#' @examples
#' loc <- pcap_to_zeek(system.file("pcap/ssh.pcap", package = "zeekr"))
#' read_zeek_logs(loc)
#' unlink(loc) # don't do this IRL until you're done working with or saving.
#' loc <- tryCatch(
#' pcap_to_zeek(system.file("pcap/ssh.pcap", package = "zeekr")),
#' error = function(e) message("No Zeek")
#' )
#'
#' if (!is.null(loc)) {
#' read_zeek_logs(loc)
#' unlink(loc) # don't do this IRL until you're done working with or saving.
#' }
pcap_to_zeek <- function(pcap, out_dir = tempfile(pattern = "zeek"), zeek_opts = c(), ...) {
pcap <- path.expand(pcap[1])
@ -84,7 +90,10 @@ pcap_to_zeek <- function(pcap, out_dir = tempfile(pattern = "zeek"), zeek_opts =
#' @export
#' @return length 1 character vector of the path to the zeek binary or `""`
#' @examples
#' find_zeek()
#' loc <- tryCatch(
#' find_zeek(),
#' error = function(e) message("No Zeek")
#' )
find_zeek <- function(path = Sys.getenv("ZEEK_PATH", "")) {
if (path != "") {

12
R/read-zeek-logs.R

@ -4,9 +4,15 @@
#' @param log_dir directory of zeek logs
#' @export
#' @examples
#' loc <- pcap_to_zeek(system.file("pcap/ssh.pcap", package = "zeekr"))
#' read_zeek_logs(loc)
#' unlink(loc) # don't do this IRL until you're done working with or saving.
#' loc <- tryCatch(
#' pcap_to_zeek(system.file("pcap/ssh.pcap", package = "zeekr")),
#' error = function(e) message("No Zeek")
#' )
#'
#' if (!is.null(loc)) {
#' read_zeek_logs(loc)
#' unlink(loc) # don't do this IRL until you're done working with or saving.
#' }
read_zeek_logs <- function(log_dir) {
log_dir <- path.expand(log_dir[1])

2
R/zeekr-package.R

@ -10,6 +10,6 @@
#' @author Bob Rudis (bob@@rud.is)
#' @import arrow
#' @import ndjson
#' @importFrom utils browseURL
#' @importFrom utils browseURL help
#' @importFrom tools file_path_sans_ext file_ext
"_PACKAGE"

18
inst/tinytest/test_zeekr.R

@ -1,4 +1,18 @@
library(zeekr)
# Placeholder with simple test
expect_equal(1 + 1, 2)
if (Sys.info()["sysname"] == "Darwin") {
Sys.setenv(ZEEK_PATH = "/opt/homebrew/bin:/usr/local/bin")
loc <- tryCatch(
pcap_to_zeek(system.file("pcap/ssh.pcap", package = "zeekr")),
error = function(e) message("No Zeek")
)
if (!is.null(loc)) {
read_zeek_logs(loc)
unlink(loc)
}
}

5
man/find_zeek.Rd

@ -17,5 +17,8 @@ Use the environment variable \code{ZEEK_PATH} or specify the directory in
the call to this function.
}
\examples{
find_zeek()
loc <- tryCatch(
find_zeek(),
error = function(e) message("No Zeek")
)
}

12
man/pcap_to_zeek.Rd

@ -32,7 +32,13 @@ environment variable \code{ZEEK_PATH} as a hint where \code{\link[=find_zeek]{fi
look for the \code{zeek} binary.
}
\examples{
loc <- pcap_to_zeek(system.file("pcap/ssh.pcap", package = "zeekr"))
read_zeek_logs(loc)
unlink(loc) # don't do this IRL until you're done working with or saving.
loc <- tryCatch(
pcap_to_zeek(system.file("pcap/ssh.pcap", package = "zeekr")),
error = function(e) message("No Zeek")
)
if (!is.null(loc)) {
read_zeek_logs(loc)
unlink(loc) # don't do this IRL until you're done working with or saving.
}
}

12
man/read_zeek_logs.Rd

@ -16,7 +16,13 @@ Read zeek logs from a processed PCAP into a list
Logs must be in Parquet or JSON format.
}
\examples{
loc <- pcap_to_zeek(system.file("pcap/ssh.pcap", package = "zeekr"))
read_zeek_logs(loc)
unlink(loc) # don't do this IRL until you're done working with or saving.
loc <- tryCatch(
pcap_to_zeek(system.file("pcap/ssh.pcap", package = "zeekr")),
error = function(e) message("No Zeek")
)
if (!is.null(loc)) {
read_zeek_logs(loc)
unlink(loc) # don't do this IRL until you're done working with or saving.
}
}

Loading…
Cancel
Save