-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8106cae
commit f81f526
Showing
25 changed files
with
278 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
.check_api_key <- function(security_schemes) { | ||
api_key_scheme_idx <- purrr::map_lgl( | ||
security_schemes@details, | ||
function(x) { | ||
inherits(x, "rapid::api_key_security_scheme") | ||
} | ||
) | ||
if (any(api_key_scheme_idx)) { | ||
return( | ||
.extract_api_key_details(security_schemes, api_key_scheme_idx) | ||
) | ||
} | ||
return(list()) | ||
} | ||
|
||
.extract_api_key_details <- function(security_schemes, api_key_scheme_idx) { | ||
purrr::pmap( | ||
list( | ||
security_schemes@name[api_key_scheme_idx], | ||
security_schemes@details[api_key_scheme_idx], | ||
security_schemes@description[api_key_scheme_idx] | ||
), | ||
function(security_scheme_name, details, description) { | ||
if (is.na(description)) { | ||
description <- "An API key provided by the API provider. This key is not clearly documented in the API description. Check the API documentation for details." | ||
} | ||
list( | ||
name = snakecase::to_snake_case(security_scheme_name), | ||
arg_name = stringr::str_remove( | ||
snakecase::to_snake_case(details@parameter_name), | ||
"^x_" | ||
), | ||
location = details@location, | ||
parameter_name = details@parameter_name, | ||
description = description | ||
) | ||
} | ||
) | ||
} | ||
|
||
.generate_security <- function(api_abbr, security_schemes) { | ||
security_data <- list() | ||
api_key_data <- .check_api_key(security_schemes) | ||
if (length(api_key_data)) { | ||
security_data$api_schemes <- api_key_data | ||
security_data$has_security <- TRUE | ||
security_arg_names <- sort( | ||
unique(purrr::map_chr(api_key_data, "arg_name")) | ||
) | ||
security_data$security_arg_names <- security_arg_names | ||
.bk_use_template( | ||
template = "020-security.R", | ||
data = c( | ||
security_data, | ||
api_abbr = api_abbr | ||
) | ||
) | ||
security_data$security_args <- glue::glue_collapse( | ||
glue::glue( | ||
"{security_arg_names} = {security_arg_names}" | ||
), | ||
sep = ",\n" | ||
) | ||
|
||
# For help. | ||
security_arg_description <- rlang::set_names( | ||
purrr::map_chr(api_key_data, "description"), | ||
purrr::map_chr(api_key_data, "arg_name") | ||
) | ||
security_arg_description <- unname( | ||
security_arg_description[security_arg_names] | ||
) | ||
security_data$security_arg_helps <- purrr::map2( | ||
security_arg_description, | ||
security_arg_names, | ||
function(arg_description, arg_name) { | ||
list( | ||
name = arg_name, | ||
description = arg_description | ||
) | ||
} | ||
) | ||
|
||
env_vars <- toupper(glue::glue( | ||
"{api_abbr}_{security_arg_names}" | ||
)) | ||
security_data$security_signature <- glue::glue_collapse( | ||
c( | ||
"", | ||
glue::glue( | ||
"{security_arg_names} = Sys.getenv(\"{env_vars}\")" | ||
) | ||
), | ||
sep = ",\n" | ||
) | ||
} | ||
return(security_data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
url: https://jonthegeek.github.io/beekeeper/ | ||
url: https://beekeeper.api2r.org | ||
template: | ||
bootstrap: 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# These functions were generated by the {beekeeper} package, based on | ||
# components@security_schemes from the source API description. You may want to | ||
# delete unused options. In addition, APIs often have additional security | ||
# options that are not formally documented in the API description. For example, | ||
# for any `location = query` `api_key` options, it might be possible to instead | ||
# pass the same parameter in a header, possibly with a different name. Consult | ||
# the text description of authentication in your API documentation. | ||
|
||
{{api_abbr}}_security <- function(req, {{security_arg_names}}) { | ||
{{#api_schemes}} | ||
req <- {{api_abbr}}_security_{{name}}(req, {{arg_name}}) | ||
{{/api_schemes}} | ||
return(req) | ||
} | ||
|
||
{{#api_schemes}} | ||
{{#description}} | ||
# {{description}} | ||
{{/description}} | ||
{{api_abbr}}_security_{{name}} <- function(req, {{arg_name}}) { | ||
nectar::security_api_key( | ||
req, | ||
location = "{{location}}", | ||
parameter_name = "{{parameter_name}}", | ||
api_key = {{arg_name}} | ||
) | ||
} | ||
|
||
{{/api_schemes}} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
apid_url <- "https://api.apis.guru/v2/specs/apis.guru/2.2.0/openapi.yaml" | ||
api_abbr <- "guru" | ||
rapid_write_path <- test_path(glue::glue("_fixtures/{api_abbr}_rapid.rds")) | ||
config_path <- test_path(glue::glue("_fixtures/{api_abbr}_beekeeper.yml")) | ||
rapid <- apid_url |> | ||
url() |> | ||
rapid::as_rapid() | ||
use_beekeeper( | ||
rapid, | ||
api_abbr = api_abbr, | ||
config_file = config_path, | ||
rapid_file = rapid_write_path | ||
) | ||
|
||
apid_url <- "https://api.apis.guru/v2/specs/fec.gov/1.0/openapi.yaml" | ||
api_abbr <- "fec" | ||
rapid_write_path <- test_path(glue::glue("_fixtures/{api_abbr}_rapid.rds")) | ||
config_path <- test_path(glue::glue("_fixtures/{api_abbr}_beekeeper.yml")) | ||
rapid <- apid_url |> | ||
url() |> | ||
rapid::as_rapid() | ||
use_beekeeper( | ||
rapid, | ||
api_abbr = api_abbr, | ||
config_file = config_path, | ||
rapid_file = rapid_write_path | ||
) | ||
|
||
apid_url <- "https://api.apis.guru/v2/specs/trello.com/1.0/openapi.yaml" | ||
api_abbr <- "trello" | ||
rapid_write_path <- test_path(glue::glue("_fixtures/{api_abbr}_rapid.rds")) | ||
config_path <- test_path(glue::glue("_fixtures/{api_abbr}_beekeeper.yml")) | ||
rapid <- apid_url |> | ||
url() |> | ||
rapid::as_rapid() | ||
use_beekeeper( | ||
rapid, | ||
api_abbr = api_abbr, | ||
config_file = config_path, | ||
rapid_file = rapid_write_path | ||
) | ||
|
||
warning("Revert .Rbuildignore") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
api_title: OpenFEC | ||
api_abbr: fec | ||
api_version: '1.0' | ||
rapid_file: fec_rapid.rds | ||
updated_on: 2023-10-11 14:59:01.432621 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
api_title: APIs.guru | ||
api_abbr: guru | ||
api_version: 2.2.0 | ||
rapid_file: _beekeeper_rapid.rds | ||
updated_on: 2023-09-14 19:12:19.405029 | ||
rapid_file: guru_rapid.rds | ||
updated_on: 2023-10-11 14:56:48.892847 |
Binary file not shown.
Oops, something went wrong.