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

Implement simple paths #44

Merged
merged 9 commits into from
Mar 28, 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
5 changes: 4 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,23 @@ Depends:
Imports:
cli,
desc,
dplyr,
fs,
glue,
httptest2,
lubridate,
nectar,
purrr,
rapid,
rapid (>= 0.0.0.9003),
rlang (>= 1.1.0),
rprojroot,
S7,
snakecase,
stringr,
styler,
testthat,
tibble,
tidyr,
usethis,
utils,
yaml
Expand Down
13 changes: 13 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ export(generate_pkg_agent)
export(use_beekeeper)
if (getRversion() < "4.3.0") importFrom("S7", "@")
importFrom(S7,class_any)
importFrom(S7,class_data.frame)
importFrom(S7,class_list)
importFrom(cli,cli_abort)
importFrom(cli,cli_warn)
importFrom(desc,desc)
importFrom(dplyr,filter)
importFrom(fs,file_delete)
importFrom(fs,file_exists)
importFrom(fs,is_dir)
importFrom(fs,path)
importFrom(fs,path_dir)
Expand All @@ -20,23 +25,31 @@ importFrom(lubridate,now)
importFrom(lubridate,parse_date_time)
importFrom(nectar,call_api)
importFrom(nectar,stabilize_string)
importFrom(purrr,imap_chr)
importFrom(purrr,list_rbind)
importFrom(purrr,map)
importFrom(purrr,map2)
importFrom(purrr,map_chr)
importFrom(purrr,pmap)
importFrom(purrr,quietly)
importFrom(rapid,as_rapid)
importFrom(rapid,class_api_key_security_scheme)
importFrom(rapid,class_paths)
importFrom(rapid,class_security_scheme_details)
importFrom(rapid,class_security_schemes)
importFrom(rlang,.data)
importFrom(rlang,check_dots_empty)
importFrom(rlang,set_names)
importFrom(rlang,try_fetch)
importFrom(rprojroot,find_package_root_file)
importFrom(snakecase,to_snake_case)
importFrom(stringr,str_remove)
importFrom(stringr,str_squish)
importFrom(styler,style_file)
importFrom(testthat,test_that)
importFrom(tibble,as_tibble)
importFrom(tidyr,nest)
importFrom(tidyr,unnest)
importFrom(usethis,proj_get)
importFrom(usethis,proj_path)
importFrom(usethis,use_build_ignore)
Expand Down
182 changes: 0 additions & 182 deletions R/as_bk_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,191 +13,9 @@ as_bk_data <- S7::new_generic(
dispatch_args = "x"
)

S7::method(as_bk_data, class_security_schemes) <- function(x) {
if (!length(x)) {
return(list())
}
security_schemes <- .security_schemes_collect(x)
return(.security_scheme_collection_finalize(security_schemes))
}

.security_schemes_collect <- function(x) {
pmap(
list(
x@name,
x@details,
x@description %|0|% rep(NA_character_, length(x@name))
),
.security_scheme_rotate
)
}

.security_scheme_rotate <- function(name, details, description) {
security_scheme <- c(
list(
name = to_snake_case(name),
description = description
),
as_bk_data(details)
)
security_scheme$description <- .security_scheme_description_fill(
description,
security_scheme$type
)
return(security_scheme)
}

.security_scheme_description_fill <- function(description, type) {
if (is.na(description)) {
return(
switch(type,
api_key = .security_scheme_description_api_key,
NA_character_
)
)
}
return(description) # nocov
}

.security_scheme_description_api_key <- paste(
"An API key provided by the API provider.",
"This key is not clearly documented in the API description.",
"Check the API documentation for details."
)

.security_scheme_collection_finalize <- function(security_schemes) {
security_scheme_data <- c(
list(
has_security = TRUE,
security_schemes = security_schemes
),
.security_args_compile(security_schemes)
)
return(security_scheme_data)
}

.security_args_compile <- function(security_schemes) {
security_args <- sort(unique(map_chr(security_schemes, "arg_name")))
return(list(
security_arg_names = security_args,
security_arg_list = .collapse_comma(
glue("{security_args} = {security_args}")
),
security_arg_helps = .generate_security_arg_help(
security_schemes,
security_args
)
))
}

.generate_security_arg_help <- function(security_schemes, security_args) {
security_arg_description <- set_names(
map_chr(security_schemes, "description"),
map_chr(security_schemes, "arg_name")
)
security_arg_description <- unname(security_arg_description[security_args])
return(
map2(
security_arg_description,
security_args,
.security_arg_description_clean
)
)
}

.security_arg_description_clean <- function(arg_description, arg_name) {
list(name = arg_name, description = arg_description)
}

S7::method(as_bk_data, class_security_scheme_details) <- function(x) {
map(x, as_bk_data)
}

S7::method(as_bk_data, class_api_key_security_scheme) <- function(x) {
if (length(x)) {
return(
list(
parameter_name = x@parameter_name,
arg_name = str_remove(to_snake_case(x@parameter_name), "^x_"),
location = x@location,
type = "api_key",
api_key = TRUE
)
)
}
return(list())
}

S7::method(as_bk_data, class_any) <- function(x) {
cli_warn(
"No method for as_bk_data() for class {.cls {class(x)}}."
)
return(list())
}

# S7::method(as_bk_data, rapid::class_oauth2_authorization_code_flow) <- function(x) {
# if (!length(x)) {
# return(list())
# }
# return(
# list(
# refresh_url = x@refresh_url,
# scopes = as_bk_data(x@scopes),
# authorization_url = x@authorization_url,
# token_url = x@token_url
# )
# )
# }

# S7::method(as_bk_data, rapid::class_oauth2_implicit_flow) <- function(x) {
# if (!length(x)) {
# return(list())
# }
# return(
# list(
# refresh_url = x@refresh_url,
# scopes = as_bk_data(x@scopes),
# authorization_url = x@authorization_url
# )
# )
# }

# S7::method(as_bk_data, rapid::class_scopes) <- function(x) {
# if (!length(x)) {
# return(list())
# }
# return(
# list(
# name = x@name,
# description = x@description
# )
# )
# }

# S7::method(as_bk_data, rapid::class_oauth2_token_flow) <- function(x) {
# if (!length(x)) {
# return(list())
# }
# return(
# list(
# refresh_url = x@refresh_url,
# scopes = as_bk_data(x@scopes),
# token_url = x@token_url
# )
# )
# }

# S7::method(as_bk_data, rapid::class_oauth2_security_scheme) <- function(x) {
# if (!length(x)) {
# return(list())
# }
# return(
# list(
# implicit_flow = as_bk_data(x@implicit_flow),
# password_flow = as_bk_data(x@password_flow),
# client_credentials_flow = as_bk_data(x@client_credentials_flow),
# authorization_code_flow = as_bk_data(x@authorization_code_flow),
# type = "oauth2"
# )
# )
# }
13 changes: 13 additions & 0 deletions R/beekeeper-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#' @importFrom cli cli_abort
#' @importFrom cli cli_warn
#' @importFrom desc desc
#' @importFrom dplyr filter
#' @importFrom fs file_delete
#' @importFrom fs file_exists
#' @importFrom fs is_dir
#' @importFrom fs path
#' @importFrom fs path_dir
Expand All @@ -17,24 +20,34 @@
#' @importFrom lubridate parse_date_time
#' @importFrom nectar call_api
#' @importFrom nectar stabilize_string
#' @importFrom purrr imap_chr
#' @importFrom purrr list_rbind
#' @importFrom purrr map
#' @importFrom purrr map_chr
#' @importFrom purrr map2
#' @importFrom purrr pmap
#' @importFrom purrr quietly
#' @importFrom rapid as_rapid
#' @importFrom rapid class_api_key_security_scheme
#' @importFrom rapid class_paths
#' @importFrom rapid class_security_scheme_details
#' @importFrom rapid class_security_schemes
#' @importFrom rlang .data
#' @importFrom rlang check_dots_empty
#' @importFrom rlang set_names
#' @importFrom rlang try_fetch
#' @importFrom rprojroot find_package_root_file
#' @importFrom S7 class_any
#' @importFrom S7 class_data.frame
#' @importFrom S7 class_list
#' @importFrom snakecase to_snake_case
#' @importFrom stringr str_remove
#' @importFrom stringr str_squish
#' @importFrom styler style_file
#' @importFrom testthat test_that
#' @importFrom tibble as_tibble
#' @importFrom tidyr nest
#' @importFrom tidyr unnest
#' @importFrom usethis proj_get
#' @importFrom usethis proj_path
#' @importFrom usethis use_build_ignore
Expand Down
Loading
Loading