Skip to content

Commit

Permalink
invalidate cache on (serialized) client config change
Browse files Browse the repository at this point in the history
  • Loading branch information
daroczig committed Jan 24, 2025
1 parent 3827d61 commit f7e865c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
9 changes: 8 additions & 1 deletion R/botor.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@ botor_client <- function(service, type = c('client', 'resource'), cache = TRUE,
get(service, envir = clients, inherits = FALSE),
error = function(e) NULL)

if (cache == TRUE && !is.null(client) && attr(client, 'uuid') == botor_session_uuid()) {
client_params <- list(...)
if (cache == TRUE && !is.null(client) &&
attr(client, 'uuid') == botor_session_uuid() &&
## compare custom client/resource parameters
all.equal(client_params, attr(client, 'botor_client_params')) &&
## compare serialized configs
all.equal(client_params$config$`__dict__`, attr(client, 'botor_client_params')$config$`__dict__`)) {
return(client)
}

Expand All @@ -98,6 +104,7 @@ botor_client <- function(service, type = c('client', 'resource'), cache = TRUE,
} else {
client <- botor()$resource(service, ...)
}
attr(client, 'botor_client_params') <- client_params

if (cache == FALSE) {
return(client)
Expand Down
11 changes: 4 additions & 7 deletions R/s3.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@
#' @importFrom logger log_trace log_debug log_info log_warn log_error
#' @param disable_signing boolean if requests should be signed. Set to \code{FALSE} when interacting with public S3 buckets requiring unauthenticated access.
s3 <- function(disable_signing = getOption('botor-s3-disable-signing')) {
client <- botor_client('s3', type = 'resource', cache = FALSE)
if (isTRUE(disable_signing)) {
client$meta$client$meta$events$register(
'choose-signer.s3.*',
require_python_module('botocore')$handlers$disable_signing)
}
client
botocore <- require_python_module('botocore')
botor_client('s3', type = 'resource', config = botocore$config$Config(
signature_version = if (isTRUE(disable_signing)) botocore$UNSIGNED else 's3v4'
))
}


Expand Down

0 comments on commit f7e865c

Please sign in to comment.