Skip to content

Commit

Permalink
signature version: generate presigned url
Browse files Browse the repository at this point in the history
  • Loading branch information
DyfanJones authored Jul 12, 2023
2 parents 4ef8488 + 2ff3577 commit 2338a9b
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 7 deletions.
17 changes: 14 additions & 3 deletions make.paws/R/custom/s3.R
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ s3_generate_presigned_url <- function(client_method,

original_params <- formals(operation_fun)
original_params <- if(!is.null(original_params)) original_params else list()
if(!is.null(original_params)) original_params else list()
param_check <- setdiff(names(params), names(original_params))
if (!identical(param_check, character(0)) || is.null(param_check)) {

if (length(param_check) > 0) {
stop(sprintf(
"Invalid parameter(s) [`%s`] for client method %s",
paste(param_check, collapse = "`, `"), client_method
Expand Down Expand Up @@ -251,9 +251,20 @@ s3_generate_presigned_url <- function(client_method,
request <- do.call(
"build", list(request = request), envir = getNamespace("paws.common")
)

signer <- function(config, default) {
switch(config[["signature_version"]],
"v1" = "v1_sign_request_handler",
"s3" = "s3_sign_request_handler",
"s3v4" = "s3v4_sign_request_handler",
"v4" = "v4_sign_request_handler",
default
)
}

# sign request
request <- do.call(
"sign_v1_auth_query", list(request = request),
signer(config, "v1_sign_request_handler"), list(request = request),
envir = getNamespace("paws.common")
)

Expand Down
2 changes: 2 additions & 0 deletions make.paws/inst/templates/service_parameter_helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#' addressing, i.e. `http://s3.amazonaws.com/BUCKET/KEY`.
#' @param sts_regional_endpoint Set sts regional endpoint resolver to regional or
#' legacy \url{https://docs.aws.amazon.com/sdkref/latest/guide/feature-sts-regionalized-endpoints.html}
#' @param signature_version The signature version used when signing requests.
#' Note that the default version is Signature Version 4.
#' @param creds \code{creds()} or \code{list} in same format.
#' \itemize{
#' \item{\strong{access_key_id}:} {AWS access key ID}
Expand Down
2 changes: 1 addition & 1 deletion paws.common/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ Collate:
'request.R'
'service_parameter_helper.R'
'signer_v4.R'
'signer_query.R'
'signer_s3.R'
'signer_s3v4.R'
'signer_v1.R'
'signer_v2.R'
'time.R'
1 change: 1 addition & 0 deletions paws.common/NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# paws.common 0.5.9
* add expiration parameter to creds
* add signature_version to config

# paws.common 0.5.8
* fix mismatch apparent method as.list.struct (#634)
Expand Down
3 changes: 2 additions & 1 deletion paws.common/R/client.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ Config <- struct(
use_dual_stack = FALSE,
sleep_delay = NULL,
disable_rest_protocol_uri_cleaning = FALSE,
sts_regional_endpoint = ""
sts_regional_endpoint = "",
signature_version = ""
)

# A Session object stores configuration and request handlers for a service.
Expand Down
5 changes: 4 additions & 1 deletion paws.common/R/service_parameter_helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#' addressing, i.e. `http://s3.amazonaws.com/BUCKET/KEY`.
#' @param sts_regional_endpoint Set sts regional endpoint resolver to regional or
#' legacy \url{https://docs.aws.amazon.com/sdkref/latest/guide/feature-sts-regionalized-endpoints.html}
#' @param signature_version The signature version used when signing requests.
#' Note that the default version is Signature Version 4.
#' @param creds \code{creds()} or \code{list} in same format.
#' \itemize{
#' \item{\strong{access_key_id}:} {AWS access key ID}
Expand Down Expand Up @@ -75,7 +77,8 @@ config <- function (credentials = list(creds = list(access_key_id = "",
secret_access_key = "", session_token = "", access_token = "",
expiration = Inf), profile = "", anonymous = FALSE), endpoint = "",
region = "", close_connection = FALSE, connect_timeout = 60,
s3_force_path_style = FALSE, sts_regional_endpoint = "")
s3_force_path_style = FALSE, sts_regional_endpoint = "",
signature_version = "")
{
.args <- as.list(environment(), all.names = TRUE)
class(.args) <- "struct"
Expand Down
6 changes: 6 additions & 0 deletions paws.common/R/signer_query.R → paws.common/R/signer_v1.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ SigningContextQuery <- struct(
anonymous = FALSE
)

# Generates a presigned request for s3.
# https://docs.aws.amazon.com/AmazonS3/latest/userguide/RESTAuthentication.html#RESTAuthenticationQueryStringAuth
v1_sign_request_handler <- function(request) {
return(sign_v1_auth_query(request))
}

sign_v1_auth_query <- function(request) {
region <- request$client_info$signing_region
if (region == "") {
Expand Down
6 changes: 5 additions & 1 deletion paws.common/man/set_service_parameter.Rd

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

0 comments on commit 2338a9b

Please sign in to comment.