Skip to content

Commit

Permalink
Merge pull request nationalparkservice#117 from RobLBaker/master
Browse files Browse the repository at this point in the history
REST API update and get_user_email function
  • Loading branch information
RobLBaker authored Jul 9, 2024
2 parents 69b520b + 8cc0cb2 commit 268c7aa
Show file tree
Hide file tree
Showing 11 changed files with 193 additions and 10 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Authors@R: c(
)
Maintainer: Rob Baker <robert_baker@nps.gov>
Description: This package contains a set of useful functions for data munging, quality control, and data flagging. Functions are contributed by multiple U.S. National Park Service staff, contractors, partners and others. These functions will likely be most useful for quality control of NPS data but may have utility beyond their intended functions.
License: CC0
License: CC0 + file LICENSE
Encoding: UTF-8
LazyData: true
Imports:
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export(get_dp_flags)
export(get_elevation)
export(get_park_polygon)
export(get_taxon_rank)
export(get_user_email)
export(get_utm_zone)
export(long2UTM)
export(order_cols)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# QCkit v0.1.8 (not yet released)

2024-07-09
* Added function `get_user_email()`, which accesses NPS active directory via a powershell function to return the user's email address. Probably won't work for non-NPS users and probably won't work for non-windows users.
* Updated rest API from legacy v6 to current v7.

2024-06-28
* Updated `get_park_polygon()` to use the new API (had been using a legacy API). Added documentation to specify that the function is getting the convexhull for the park, which may not work particularly well for some parks.
2024-06-27
Expand Down
36 changes: 32 additions & 4 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
.pkgglobalenv <- new.env(parent=emptyenv())

#data_store API base URL:
assign("QC_ds_api", "https://irmaservices.nps.gov/datastore/v6/rest/", envir=.pkgglobalenv)
assign("QC_ds_api", "https://irmaservices.nps.gov/datastore/v7/rest/", envir=.pkgglobalenv)

#data_store secure API base URL:
assign("QC_ds_secure_api", "https://irmaservices.nps.gov/datastore-secure/v6/rest/", envir=.pkgglobalenv)
assign("QC_ds_secure_api", "https://irmaservices.nps.gov/datastore-secure/v7/rest/", envir=.pkgglobalenv)

#data_store dev api (requires secure)
assign("QC_ds_dev_api", "https://irmadevservices.nps.gov/datastore-secure/v6/rest/", envir = .pkgglobalenv)
assign("QC_ds_dev_api", "https://irmadevservices.nps.gov/datastore-secure/v7/rest/", envir = .pkgglobalenv)

.QC_ds_api <- function(x){
get("QC_ds_api", envir = .pkgglobalenv)
Expand Down Expand Up @@ -39,4 +39,32 @@ globalVariables(c("any_of",
"_UTMJOINCOL",
"decimalLatitude",
"decimalLongitude",
"LatLong_CRS"))
"LatLong_CRS"))


#' Retrieves an NPS user's email address
#'
#' @details The function accesses the system username and then uses a powershell wrapper to access NPS active directory and supply information about the user. That information is then parsed down to the user's email address.
#'
#' This function probaby won't work for anyone outside of NPS and likely won't work for anyone who is not using a Windows machine. So build those prerequisites (NPS = FALSE) in when calling it from within other function.
#'
#' @return String. The user's email address.
#' @export
#'
#' @examples
#' \dontrun{
#' email <- get_user_email()
#' }
get_user_email <- function() {
powershell_command <- '([adsisearcher]\\"(samaccountname=$env:USERNAME)\\").findone().properties.proxyaddresses'

proxy_addresses <- system2("powershell",
args = c("-command",
powershell_command),
stdout = TRUE)

email_address <- stringr::str_subset(proxy_addresses, "@") |>
stringr::str_remove("SMTP:")

return(email_address)
}
1 change: 1 addition & 0 deletions docs/news/index.html

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

2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ articles:
DRR_Purpose_and_Scope: DRR_Purpose_and_Scope.html
Starting-a-DRR: Starting-a-DRR.html
Using-the-DRR-Template: Using-the-DRR-Template.html
last_built: 2024-06-28T15:11Z
last_built: 2024-07-09T14:49Z

117 changes: 117 additions & 0 deletions docs/reference/get_user_email.html

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

4 changes: 4 additions & 0 deletions docs/reference/index.html

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

3 changes: 3 additions & 0 deletions docs/sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@
<url>
<loc>/reference/get_taxon_rank.html</loc>
</url>
<url>
<loc>/reference/get_user_email.html</loc>
</url>
<url>
<loc>/reference/get_utm_zone.html</loc>
</url>
Expand Down
24 changes: 24 additions & 0 deletions man/get_user_email.Rd

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

9 changes: 5 additions & 4 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
test_that("multiplication works", {
expect_equal(2 * 2, 4)
})

test_that(".QC_ds_api returns correct url", {
expect_equal(.QC_ds_api(x), "https://irmaservices.nps.gov/datastore/v6/rest/")
})
Expand All @@ -12,4 +8,9 @@ test_that(".QC_ds_secure_api returns correct url", {

test_that(".QC_ds_dev_api returns correct url", {
expect_equal(.QC_ds_dev_api(x), "https://irmadevservices.nps.gov/datastore-secure/v6/rest/")
})

test_that("get_user_email returns a string approximating an email", {
email <- get_user_email()
expect_equal(grep("@", email), 1)
})

0 comments on commit 268c7aa

Please sign in to comment.