@@ -94,11 +94,9 @@ launch_remote <- function(n = 1L, remote = remote_config(), ..., tls = NULL, .co
94
94
dots <- if (... length()) parse_dots(envir , ... ) else envir [[" dots" ]]
95
95
if (is.null(tls )) tls <- envir [[" tls" ]]
96
96
97
- if (length(remote ) == 2L && remote [[" platform" ]] == " posit_workbench" ) {
98
- args <- remote [[" args" ]]
99
- tools <- posit_tools()
100
- is.environment(tools ) || stop(._ [[" posit_api" ]])
101
- return (posit_workbench_launch(n , args , tools ))
97
+ if (length(remote ) == 2L ) {
98
+ remote [[" platform" ]] == " posit_workbench" || stop(._ [[" posit_api" ]])
99
+ return (posit_workbench_launch(n , args , Sys.getenv(" PWB_API_KEY" )))
102
100
}
103
101
104
102
command <- remote [[" command" ]]
@@ -404,6 +402,8 @@ cluster_config <- function(command = "sbatch", options = "", rscript = "Rscript"
404
402
# ' Generates a remote configuration for launching daemons via the default
405
403
# ' configured Posit Workbench launcher method.
406
404
# '
405
+ # ' @param apikey your 32 character Posit Workbench API key.
406
+ # '
407
407
# ' @inherit remote_config return
408
408
# '
409
409
# ' @seealso [ssh_config()], [cluster_config()], and [remote_config()] for other
@@ -420,10 +420,9 @@ cluster_config <- function(command = "sbatch", options = "", rscript = "Rscript"
420
420
# '
421
421
# ' @export
422
422
# '
423
- posit_workbench_config <- function () {
424
- tools <- posit_tools()
425
- is.null(tools ) && stop(._ [[" posit_api" ]])
426
- args <- posit_get_info(tools )
423
+ posit_workbench_config <- function (apikey = Sys.getenv(" PWB_API_KEY" )) {
424
+ args <- posit_get_info(apikey )
425
+ is.null(args ) && stop(._ [[" posit_api" ]])
427
426
list (platform = " posit_workbench" , args = args )
428
427
}
429
428
@@ -512,48 +511,32 @@ find_dot <- function(args) {
512
511
sel
513
512
}
514
513
515
- posit_tools <- function () {
516
- from_json <- get0(" .rs.fromJSON" )
517
- cookie <- Sys.getenv(" RS_SESSION_RPC_COOKIE" )
514
+ posit_get_info <- function (apikey ) {
518
515
server <- Sys.getenv(" RS_SERVER_ADDRESS" )
519
- is.function(from_json ) && nzchar(cookie ) && nzchar(server ) || return ()
520
- list (from_json = from_json , cookie = cookie , server = server )
521
- }
522
-
523
- posit_get_info <- function (tools ) {
516
+ nzchar(server ) || return ()
524
517
info <- ncurl(
525
- url = file.path(tools [[ " server" ]] , " api" , " get_compute_envs" ),
526
- headers = c(cookie = tools [[ " cookie " ]] )
518
+ url = file.path(server , " api" , " get_compute_envs" ),
519
+ headers = c(Authorization = sprintf( " Bearer %s " , apikey ) )
527
520
)
528
- data <- tools [[" from_json" ]](info [[" data" ]])
529
- cluster <- .subset2(data , c(1L , 1L , 1L ))
530
- list (name = cluster [[" name" ]], image = cluster [[" defaultImage" ]])
521
+ info [[" status" ]] == 200L || return ()
522
+ json <- info [[" data" ]]
523
+ image <- sub(' .*"defaultImage"\\ s*:\\ s*"([^"]*)".*' , ' \\ 1' , json , perl = TRUE )
524
+ list (name = " Kubernetes" , image = image )
531
525
}
532
526
533
- posit_workbench_launch <- function (n , args , tools ) {
534
- tools <- posit_tools()
527
+ posit_workbench_launch <- function (n , args , apikey ) {
528
+ server <- Sys.getenv(" RS_SERVER_ADDRESS" )
529
+ nzchar(server ) || return ()
535
530
json <- sprintf(
536
- ' {"method":"launch_job","kwparams":{"job":{"cluster":"%s","container":{"image":"%s"},"name":"mirai_daemon","exe":"Rscript","args":["-e","mirai::daemon(\\ "%s\\ ")"]}}}' ,
531
+ ' {"method":"launch_job","kwparams":{"job":{"cluster":"%s","container":{"image":"%s"},"resourceProfile":"default"," name":"mirai_daemon","exe":"Rscript","args":["-e","mirai::daemon(\\ "%s\\ ")"]}}}' ,
537
532
args [[" name" ]],
538
533
args [[" image" ]],
539
534
nextget(" url" )
540
535
)
541
- info <- ncurl(
542
- url = file.path(tools [[ " server" ]] , " api" , " launch_job" ),
536
+ res <- ncurl(
537
+ url = file.path(server , " api" , " launch_job" ),
543
538
method = " POST" ,
544
- headers = c(cookie = tools [[ " cookie " ]] ),
539
+ headers = c(Authorization = sprintf( " Bearer %s " , apikey ) ),
545
540
data = json
546
541
)
547
- cluster <- args [[" name" ]]
548
- container <- new_container(args [[" image" ]])
549
- cmds <- launch_remote(n )
550
- lapply(cmds , function (cmd )
551
- submit_job(
552
- sprintf(" mirai_daemon_%s" , random(3L )),
553
- cluster = cluster ,
554
- command = cmd ,
555
- container = container
556
- )
557
- )
558
- cmds
559
542
}
0 commit comments