-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add user-friendly functions to add locations #184
Changes from 3 commits
da98c5f
61229b9
7e33034
db393fd
b4f12a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: orderly2 | ||
Title: Orderly Next Generation | ||
Version: 1.99.41 | ||
Version: 1.99.42 | ||
Authors@R: c(person("Rich", "FitzJohn", role = c("aut", "cre"), | ||
email = "[email protected]"), | ||
person("Robert", "Ashton", role = "aut"), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,12 @@ | |
##' based locations are supported, with limited support for custom | ||
##' locations. Note that adding a location does *not* pull metadata | ||
##' from it, you need to call | ||
##' [orderly2::orderly_location_pull_metadata] first. | ||
##' [orderly2::orderly_location_pull_metadata] first. The function | ||
##' `orderly_location_add` can add any sort of location, but the other | ||
##' functions documented here (`orderly_location_add_path`, etc) will | ||
##' typically be much easier to use in practice. | ||
##' | ||
##' We currently support two types of locations - `path`, which points | ||
##' We currently support three types of locations - `path`, which points | ||
##' to an outpack archive accessible by path (e.g., on the same | ||
##' computer or on a mounted network share), `http`, which requires | ||
##' that an outpack server is running at some url and uses an HTTP API | ||
|
@@ -14,13 +17,12 @@ | |
##' options to these location types will definitely be needed in | ||
##' future. | ||
##' | ||
##' Configuration options for different location types: | ||
##' Configuration options for different location types are described | ||
##' in the arguments to their higher-level functions. | ||
##' | ||
##' **Path locations**: | ||
##' | ||
##' * `path`: The path to the other archive root. This should | ||
##' generally be an absolute path, or the behaviour of outpack will | ||
##' be unreliable. | ||
##' Use `orderly_location_add_path`, which accepts a `path` argument. | ||
##' | ||
##' **HTTP locations**: | ||
##' | ||
|
@@ -29,24 +31,16 @@ | |
##' the API, but also as we move to support things like TLS and | ||
##' authentication. | ||
##' | ||
##' * `url`: The location of the server, including protocol, for | ||
##' example `http://example.com:8080` | ||
##' Use `orderly_location_add_http`, which accepts a `url` argument. | ||
##' | ||
##' **Packit locations**: | ||
##' | ||
##' Packit locations work over HTTPS, and include everything in an | ||
##' outpack location but also provide authentication and later will | ||
##' have more capabilities we think. | ||
##' | ||
##' * `url`: The location of the server | ||
##' | ||
##' * `token`: The value for your your login token (currently this is | ||
##' a GitHub token with `read:org` scope). If missing or NULL, orderly2 will | ||
##' perform an interactive authentication against GitHub to obtain one. | ||
##' | ||
##' * `save_token`: If no token is provided and interactive authentication is | ||
##' used, this controls whether the GitHub token should be saved to disk. | ||
##' Defaults to TRUE if missing. | ||
##' Use `orderly_location_add_packit`, which accepts `url`, `token` | ||
##' and `save_token` arguments. | ||
##' | ||
##' **Custom locations**: | ||
##' | ||
|
@@ -100,26 +94,16 @@ orderly_location_add <- function(name, type, args, root = NULL, locate = TRUE) { | |
|
||
loc <- new_location_entry(name, type, args, call = environment()) | ||
if (type == "path") { | ||
## We won't be necessarily be able to do this _generally_ but | ||
## here, let's confirm that we can read from the outpack archive | ||
## at the requested path; this will just fail but without | ||
## providing the user with anything actionable yet. | ||
assert_scalar_character(loc$args[[1]]$path, name = "args$path", | ||
call = environment()) | ||
root_open(loc$args[[1]]$path, locate = FALSE, require_orderly = FALSE) | ||
assert_scalar_character(args$path, name = "path") | ||
root_open(args$path, locate = FALSE, require_orderly = FALSE) | ||
} else if (type == "http") { | ||
assert_scalar_character(loc$args[[1]]$url, name = "args$url", | ||
call = environment()) | ||
assert_scalar_character(args$url, name = "url") | ||
} else if (type == "packit") { | ||
assert_scalar_character(loc$args[[1]]$url, name = "args$url", | ||
call = environment()) | ||
assert_scalar_character(loc$args[[1]]$token, name = "args$token", | ||
allow_null = TRUE, | ||
call = environment()) | ||
assert_scalar_logical(loc$args[[1]]$save_token, name = "args$save_token", | ||
allow_null = TRUE, | ||
call = environment()) | ||
if (!is.null(loc$args[[1]]$token) && !is.null(loc$args[[1]]$save_token)) { | ||
assert_scalar_character(args$url, name = "url") | ||
assert_scalar_character(args$token, name = "token", allow_null = TRUE) | ||
assert_scalar_logical(args$save_token, name = "save_token", | ||
allow_null = TRUE) | ||
if (!is.null(args$token) && !is.null(args$save_token)) { | ||
cli::cli_abort("Cannot specify both 'token' and 'save_token'") | ||
} | ||
} | ||
|
@@ -132,6 +116,44 @@ orderly_location_add <- function(name, type, args, root = NULL, locate = TRUE) { | |
} | ||
|
||
|
||
##' @rdname orderly_location_add | ||
##' | ||
##' @param path The path to the other archive root. This should | ||
##' generally be an absolute path, or the behaviour of outpack will | ||
##' be unreliable. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be worth cleaning up and defining the semantics of a relative path at some point (not in this PR). IMO it should be relative to the orderly root, and be resolved each time we use the location, not when it is first added. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you thinking here again of people on the cluster where directories "move"? |
||
orderly_location_add_path <- function(name, path, root = NULL) { | ||
args <- list(path = path) | ||
orderly_location_add(name, "path", args, root = root) | ||
} | ||
|
||
|
||
##' @rdname orderly_location_add | ||
##' | ||
##' @param url The location of the server, including protocol, for | ||
##' example `http://example.com:8080` | ||
orderly_location_add_http <- function(name, url, root = NULL) { | ||
args <- list(url = url) | ||
orderly_location_add(name, "http", args, root = root) | ||
} | ||
|
||
|
||
##' @rdname orderly_location_add | ||
##' | ||
##' @param token The value for your your login token (currently this | ||
##' is a GitHub token with `read:org` scope). If `NULL`, orderly2 | ||
##' will perform an interactive authentication against GitHub to | ||
##' obtain one. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically this can be a Packit JWT instead of a GitHub PAT, but we don't really publicize any way of obtaining those so I think it is fine if you don't want to mention it here. This is the only place a JWT would be used today: https://github.com/mrc-ide/orderly-action/blob/main/packit-login.R#L65-L69 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just copied this in from the string that was present in the Details for now |
||
##' | ||
##' @param save_token If no token is provided and interactive | ||
##' authentication is used, this controls whether the GitHub token | ||
##' should be saved to disk. Defaults to `TRUE` if `NULL`. | ||
orderly_location_add_packit <- function(name, url, token = NULL, | ||
save_token = NULL, root = NULL) { | ||
args <- list(url = url, token = token, save_token = save_token) | ||
orderly_location_add(name, "packit", args, root = root) | ||
} | ||
|
||
|
||
##' Rename an existing location | ||
##' | ||
##' @title Rename a location | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
two types of locations and off by one errors 😁