Skip to content

Commit

Permalink
rename file
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau-lilly committed Sep 15, 2023
1 parent ece3d0d commit 0bd39b1
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 54 deletions.
21 changes: 17 additions & 4 deletions R/crew_assert.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,30 @@ crew_assert <- function(
#' alternative = "use the scale argument of push(), pop(), and wait()."
#' )
#' )
crew_deprecate <- function(name, date, version, alternative) {
crew_deprecate <- function(
name,
date,
version,
alternative,
condition = "warning"
) {
message <- sprintf(
"%s was deprecated on %s (crew version %s). Alternative: %s.",
name,
date,
version,
alternative
)
crew_warn(
message = message,
class = c("crew_deprecate", "crew_warning", "crew")
if_any(
condition == "warning",
crew_warn(
message = message,
class = c("crew_deprecate", "crew_warning", "crew")
),
rlang::inform(
message = message,
class = c("crew_deprecate", "crew_message", "crew")
)
)
}

Expand Down
10 changes: 6 additions & 4 deletions R/crew_client.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,23 @@ crew_client <- function(
seconds_interval = 0.25,
seconds_timeout = 10
) {
# TODO: turn these into warnings:
if (!is.null(tls_enable)) {
crew_deprecate(
name = "tls_enable",
date = "2023-09-15",
version = "0.4.1",
alternative = "argument tls and function crew_tls()"
alternative = "argument tls and function crew_tls()",
condition = "message"
)
}
if (!is.null(tls_config)) {
crew_deprecate(
name = "tls_config",
date = "2023-09-15",
version = "0.4.1",
alternative = "argument tls and function crew_tls()"
alternative = "argument tls and function crew_tls()",
condition = "message"
)
}
name <- as.character(name %|||% crew_random_name())
Expand Down Expand Up @@ -214,7 +217,7 @@ crew_class_client <- R6::R6Class(
get_password <- function() {
self$tls$password
}
args <- list(
mirai::daemons(
n = self$workers,
url = url,
dispatcher = TRUE,
Expand All @@ -224,7 +227,6 @@ crew_class_client <- R6::R6Class(
token = TRUE,
.compute = self$name
)
do.call(what = mirai::daemons, args = args)
# TODO: remove code that gets the dispatcher PID if the dispatcher
# process becomes a C thread.
# Begin dispatcher code.
Expand Down
18 changes: 13 additions & 5 deletions R/crew_launcher.R
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,13 @@ crew_class_launcher <- R6::R6Class(
crew_assert(identical(colnames(self$workers), cols))
crew_assert(nrow(self$workers) > 0L)
}
crew_assert(
inherits(self$tls, "crew_class_tls"),
message = "field tls must be an object created by crew_tls()"
)
# TODO: forbid NULL tls objects:
if (!is.null(self$tls)) {
crew_assert(
inherits(self$tls, "crew_class_tls"),
message = "field tls must be an object created by crew_tls()"
)
}
invisible()
},
#' @description List of arguments for `mirai::daemon()`.
Expand All @@ -321,7 +324,12 @@ crew_class_launcher <- R6::R6Class(
timerstart = self$tasks_timers,
exitlinger = self$seconds_exit * 1000,
cleanup = cleanup,
tls = self$tls$worker(name = self$name),
# TODO: always use tls objects:
tls = if_any(
is.null(self$tls),
NULL,
self$tls$worker(name = self$name)
),
rs = mirai::nextstream(self$name)
)
},
Expand Down
2 changes: 1 addition & 1 deletion man/crew_deprecate.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/testthat/test-crew_client.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ crew_test("crew_client() works", {
})

crew_test("crew_client() deprecate tls_enable", {
expect_warning(
expect_message(
crew_client(host = "127.0.0.1", tls_enable = TRUE),
class = "crew_deprecate"
)
})

crew_test("crew_client() deprecate tls_config", {
expect_warning(
expect_message(
crew_client(host = "127.0.0.1", tls_config = list()),
class = "crew_deprecate"
)
Expand Down
102 changes: 102 additions & 0 deletions tests/tls/test-crew_tls.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
test_that("mirai client can start using custom credentials", {
skip_on_os("windows")
on.exit(unlink(c("fd.key", "fd.csr", "fd.crt")))
system(
paste(
"openssl genpkey -out fd.key -algorithm RSA -outform PEM",
"-pkeyopt rsa_keygen_bits:2048 -des3 -pass pass:crew"
)
)
system(
paste(
"openssl req -new -key fd.key -out fd.csr",
"-subj \"/CN=127.0.0.1\" -passin pass:crew"
)
)
system(
paste(
"openssl x509 -req -days 365 -in fd.csr -signkey",
"fd.key -out fd.crt -passin pass:crew"
)
)
get_password <- function() {
"crew"
}
mirai::daemons(
n = 1L,
url = "wss://127.0.0.1:0",
dispatcher = TRUE,
seed = NULL,
tls = c(
paste(readLines("fd.crt"), collapse = "\n"),
paste(readLines("fd.key"), collapse = "\n")
),
pass = get_password(),
token = TRUE,
.compute = "name"
)
mirai::daemons(n = 0L)
})

test_that("crew_tls() custom works on real credentials", {
skip_on_os("windows")
on.exit(unlink(c("fd.key", "fd.csr", "fd.crt")))
system(
paste(
"openssl genpkey -out fd.key -algorithm RSA",
"-outform PEM -pkeyopt rsa_keygen_bits:2048"
)
)
system("openssl req -new -key fd.key -out fd.csr -subj \"/CN=127.0.0.1\"")
system("openssl x509 -req -days 365 -in fd.csr -signkey fd.key -out fd.crt")
tls <- crew_tls(mode = "custom", key = "fd.key", certificates = "fd.crt")
expect_silent(tls$validate())
x <- crew_controller_local(tls = tls)
x$start()
x$push("57")
x$wait()
expect_equal(x$pop()$result[[1L]], "57")
})

test_that("crew_tls() custom works on real credentials with custom password", {
skip_on_os("windows")
on.exit(unlink(c("fd.key", "fd.csr", "fd.crt")))
system(
paste(
"openssl genpkey -out fd.key -algorithm RSA -outform PEM",
"-pkeyopt rsa_keygen_bits:2048 -des3 -pass pass:crew"
)
)
system(
paste(
"openssl req -new -key fd.key -out fd.csr",
"-subj \"/CN=127.0.0.1\" -passin pass:crew"
)
)
system(
paste(
"openssl x509 -req -days 365 -in fd.csr -signkey",
"fd.key -out fd.crt -passin pass:crew"
)
)
tls <- crew_tls(
mode = "custom",
key = "fd.key",
password = "crew",
certificates = "fd.crt"
)
expect_silent(tls$validate())
x <- crew_controller_local(tls = tls)
x$start()
x$push("57")
x$wait()
expect_equal(x$pop()$result[[1L]], "57")
})

test_that("crew_tls() automatic", {
x <- crew_controller_local(tls = crew_tls(mode = "automatic"))
x$start()
x$push("57")
x$wait()
expect_equal(x$pop()$result[[1L]], "57")
})
38 changes: 0 additions & 38 deletions tests/tls/test-tls_config.R

This file was deleted.

0 comments on commit 0bd39b1

Please sign in to comment.