~hrbrmstr/sergeant

ref: 37922db9db2d59c813924b4bec024fdc2fb3462b sergeant/R/utils.r -rw-r--r-- 910 bytes
37922db9hrbrmstr Merge branch 'master' of github.com:hrbrmstr/sergeant 8 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
try_require <- function(package, fun) {
  if (requireNamespace(package, quietly = TRUE)) {
    library(package, character.only = TRUE)
    return(invisible())
  }

  stop("Package `", package, "` required for `", fun , "`.\n", # nocov start
       "Please install and try again.", call. = FALSE) # nocov end
}

# authenticate to drill
# sets up a cookie in the httr handle pool ref for the drill REST API url
auth_drill <- function(ssl, host, port, username, password) {

  httr::set_config(config(ssl_verifypeer = 0L))

  httr::RETRY(
    "POST",
    url = sprintf("%s://%s:%s", ifelse(ssl[1], "https", "http"), host, port),
    path = "/j_security_check",
    encode = "form",
    body = list(
      j_username = username,
      j_password = password
    ),
    terminate_on = c(403, 404)
  ) -> res

  httr::stop_for_status(res)

}

set_names <- function(object = nm, nm) {
  names(object) <- nm
  object
}