Skip to content
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

use arc_token() to handle empty tokens #126

Merged
merged 6 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ License: Apache License (>= 2)
Encoding: UTF-8
LazyData: true
Imports:
arcgisutils (>= 0.1.0),
arcgisutils (>= 0.1.1.9000),
cli,
httr2 (>= 1.0.0),
jsonify,
Expand All @@ -34,7 +34,7 @@ Imports:
terra,
utils
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.0
Suggests:
dbplyr,
dplyr,
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
- adds cli as an explicit import (has been implicitly imported by httr2)
- repository made public
- add lifecycle badges to all exported functions <https://github.com/R-ArcGIS/arcgislayers/pull/101>
- Use `arcgisutils::arc_token()` to get "ARCGIS_TOKEN" environment variable. This ensures that empty strings do not cause HTTP 498 "invalid token" error.
6 changes: 3 additions & 3 deletions R/add_item.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ add_item <- function(
async = FALSE,
type = "Feature Service",
host = arc_host(),
token = Sys.getenv("ARCGIS_TOKEN")
token = arc_token()
) {

# if async = TRUE stop
Expand Down Expand Up @@ -171,7 +171,7 @@ publish_item <- function(
publish_params = .publish_params(),
file_type = "featureCollection",
host = arc_host(),
token = Sys.getenv("ARCGIS_TOKEN")
token = arc_token()
) {

# create request URL
Expand Down Expand Up @@ -208,7 +208,7 @@ publish_layer <- function(
user = Sys.getenv("ARCGIS_USER"),
publish_params = .publish_params(title, target_crs = sf::st_crs(x)),
host = arc_host(),
token = Sys.getenv("ARCGIS_TOKEN")
token = arc_token()
) {

adtl_args <- rlang::list2(...)
Expand Down
6 changes: 3 additions & 3 deletions R/arc-add-update-delete.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ add_features <- function(
chunk_size = 2000,
match_on = c("name", "alias"),
rollback_on_failure = TRUE,
token = Sys.getenv("ARCGIS_TOKEN")
token = arc_token()
) {

# initial check for type of `x`
Expand Down Expand Up @@ -180,7 +180,7 @@ update_features <- function(
x,
.data,
match_on = c("name", "alias"),
token = Sys.getenv("ARCGIS_TOKEN"),
token = arc_token(),
rollback_on_failure = TRUE,
...
) {
Expand Down Expand Up @@ -293,7 +293,7 @@ delete_features <- function(
filter_geom = NULL,
predicate = "intersects",
rollback_on_failure = TRUE,
token = Sys.getenv("ARCGIS_TOKEN"),
token = arc_token(),
...
) {

Expand Down
2 changes: 1 addition & 1 deletion R/arc-open.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
#' arc_open(map_url)
#'
#'}
arc_open <- function(url, token = Sys.getenv("ARCGIS_TOKEN")) {
arc_open <- function(url, token = arc_token()) {

stopifnot("`url` must be of length 1" = length(url) == 1)

Expand Down
2 changes: 1 addition & 1 deletion R/arc-raster.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ arc_raster <- function(
width = NULL,
height = NULL,
format = "tiff",
token = Sys.getenv("ARCGIS_TOKEN")
token = arc_token()
) {


Expand Down
2 changes: 1 addition & 1 deletion R/arc-read.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ arc_read <- function(
crs = NULL,
...,
fields = NULL,
token = Sys.getenv("ARCGIS_TOKEN")
token = arc_token()
) {
service <- arc_open(url = url, token = token)

Expand Down
4 changes: 2 additions & 2 deletions R/arc-select.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ arc_select <- function(
filter_geom = NULL,
predicate = "intersects",
n_max = Inf,
token = Sys.getenv("ARCGIS_TOKEN"),
token = arc_token(),
...
) {
# Developer note:
Expand Down Expand Up @@ -132,7 +132,7 @@ arc_select <- function(
#' @noRd
collect_layer <- function(x,
n_max = Inf,
token = Sys.getenv("ARCGIS_TOKEN"),
token = arc_token(),
...,
error_call = rlang::caller_env()) {
check_inherits_any(
Expand Down
2 changes: 1 addition & 1 deletion R/create-service.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ create_feature_server <- function(
has_static_data = FALSE,
xss_prevention = xss_defaults(),
host = arc_host(),
token = Sys.getenv("ARCGIS_TOKEN")
token = arc_token()
) {

match.arg(capabilities, several.ok = TRUE)
Expand Down
19 changes: 4 additions & 15 deletions R/get-estimates.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#' @returns
#' A named list containing all estimate info. If `extent` is present,
#' it is available as an object of class `bbox`.
get_layer_estimates <- function(x, token = Sys.getenv("ARCGIS_TOKEN")) {
get_layer_estimates <- function(x, token = arc_token()) {

# check if its a supported layer
obj_check_layer(x)
Expand All @@ -35,20 +35,9 @@ get_layer_estimates <- function(x, token = Sys.getenv("ARCGIS_TOKEN")) {
"getEstimates"
)

# token bug :[
if (token != "") {
req <-
httr2::req_auth_bearer_token(
httr2::req_url_query(est_req, f = "json"),
token
)
resp <- httr2::req_perform(req)
} else {
resp <-
httr2::req_perform(
httr2::req_url_query(est_req, f = "json")
)
}
resp <- httr2::req_perform(
httr2::req_url_query(est_req, f = "json")
)

# process json string
res_raw <- RcppSimdJson::fparse(httr2::resp_body_string(resp))
Expand Down
2 changes: 1 addition & 1 deletion R/truncate.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ truncate_layer <- function(
x,
async = FALSE,
attachment_only = FALSE,
token = Sys.getenv("ARCGIS_TOKEN")
token = arc_token()
) {

# check to see if it is a compatible class
Expand Down
18 changes: 9 additions & 9 deletions R/utils-feature-server.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#' get_layers(fserv, name = c("Tracts", "ZCTAs"))
#' get_all_layers(fserv)
#' }
get_layer <- function(x, id = NULL, name = NULL, token = Sys.getenv("ARCGIS_TOKEN")) {
get_layer <- function(x, id = NULL, name = NULL, token = arc_token()) {
# check for mutual exclusivity between id and name
if (is.null(id) && is.null(name)) {
cli::cli_abort("{.arg id} or {.arg name} must be provided.")
Expand All @@ -55,7 +55,7 @@ get_layer <- function(x, id = NULL, name = NULL, token = Sys.getenv("ARCGIS_TOKE
}

#' @export
get_layer.default <- function(x, id = NULL, name = NULL, token = Sys.getenv("ARCGIS_TOKEN")) {
get_layer.default <- function(x, id = NULL, name = NULL, token = arc_token()) {

if (!is.null(name)) {

Expand Down Expand Up @@ -104,7 +104,7 @@ get_layer.GroupLayer <- function(
x,
id = NULL,
name = NULL,
token = Sys.getenv("ARCGIS_TOKEN")
token = arc_token()
) {
if (!is.null(name)) {

Expand Down Expand Up @@ -148,12 +148,12 @@ get_layer.GroupLayer <- function(

#' @rdname get_layer
#' @export
get_all_layers <- function(x, token = Sys.getenv("ARCGIS_TOKEN")) {
get_all_layers <- function(x, token = arc_token()) {
UseMethod("get_all_layers")
}

#' @export
get_all_layers.default <- function(x, token = Sys.getenv("ARCGIS_TOKEN")) {
get_all_layers.default <- function(x, token = arc_token()) {
layer_ids <- x[["layers"]][["id"]]
table_ids <- x[["tables"]][["id"]]
layers <- lapply(file.path(x[["url"]], layer_ids), arc_open, token = token)
Expand All @@ -168,7 +168,7 @@ get_all_layers.default <- function(x, token = Sys.getenv("ARCGIS_TOKEN")) {
}

#' @export
get_all_layers.GroupLayer <- function(x, token = Sys.getenv("ARCGIS_TOKEN")) {
get_all_layers.GroupLayer <- function(x, token = arc_token()) {
all_layer_ids <- x[["subLayers"]][["id"]]

all_layer_paths <- vapply(
Expand All @@ -187,7 +187,7 @@ get_layers <- function(
x,
id = NULL,
name = NULL,
token = Sys.getenv("ARCGIS_TOKEN")
token = arc_token()
) {
if (is.null(id) && is.null(name)) {
cli::cli_abort("{.arg id} or {.arg name} must be provided.")
Expand All @@ -204,7 +204,7 @@ get_layers <- function(
}

#' @export
get_layers.default <- function(x, id = NULL, name = NULL, token = Sys.getenv("ARCGIS_TOKEN")) {
get_layers.default <- function(x, id = NULL, name = NULL, token = arc_token()) {

if (!is.null(id)) {
# cast as integer
Expand Down Expand Up @@ -260,7 +260,7 @@ get_layers.GroupLayer <- function(
x,
id = NULL,
name = NULL,
token = Sys.getenv("ARCGIS_TOKEN")
token = arc_token()
) {
if (!is.null(id)) {
# cast as integer
Expand Down
2 changes: 1 addition & 1 deletion man/arc_open.Rd

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

2 changes: 1 addition & 1 deletion man/arc_raster.Rd

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

2 changes: 1 addition & 1 deletion man/arc_read.Rd

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

2 changes: 1 addition & 1 deletion man/arc_select.Rd

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

2 changes: 1 addition & 1 deletion man/create_feature_server.Rd

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

6 changes: 3 additions & 3 deletions man/get_layer.Rd

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

2 changes: 1 addition & 1 deletion man/get_layer_estimates.Rd

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

6 changes: 3 additions & 3 deletions man/modify.Rd

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

6 changes: 3 additions & 3 deletions man/publish.Rd

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

7 changes: 1 addition & 6 deletions man/truncate_layer.Rd

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

Loading