Skip to content

Commit

Permalink
Fix default env variables and add fallback for AWS config
Browse files Browse the repository at this point in the history
  • Loading branch information
ddl-gabrielhaim committed Aug 25, 2022
1 parent 1c4a055 commit 0a637a8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
25 changes: 12 additions & 13 deletions R/config.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@ add_override <- function(..., .override = character()) {
#' @export
add_credentials <- function(auth_type, config = list()) {
if (auth_type == "OAuth") {
credentials <- load_oauth_credentials(Sys.getenv("DOMINO_TOKEN_FILE"))
credentials <- load_oauth_credentials(
Sys.getenv("DOMINO_TOKEN_FILE", "/var/lib/domino/home/.api/token")
)
} else if (is.element(auth_type, c("AWSIAMRole", "AWSIAMRoleWithUsername"))) {
credentials <- load_aws_credentials(
Sys.getenv("AWS_SHARED_CREDENTIALS_FILE"),
Sys.getenv(
"AWS_SHARED_CREDENTIALS_FILE",
"/var/lib/domino/home/.aws/credentials"
),
config[["profile"]]
)
} else {
Expand All @@ -58,17 +63,14 @@ add_credentials <- function(auth_type, config = list()) {
#' @param profile AWS profile or section to use
#'
#' @return named listed of override configuration values
load_aws_credentials <- function(location = NULL, profile = NULL) {
if (is.null(location)) {
location <- "/var/lib/domino/home/.aws/credentials"
}
load_aws_credentials <- function(location, profile = NULL) {
c <- ConfigParser::ConfigParser$new()
c$read(location)

list(
accessKeyID = c$get("aws_access_key_id", section = profile),
secretAccessKey = c$get("aws_secret_access_key", section = profile),
sessionToken = c$get("aws_session_token", section = profile)
accessKeyID = c$get("aws_access_key_id", NULL, section = profile),
secretAccessKey = c$get("aws_secret_access_key", NULL, section = profile),
sessionToken = c$get("aws_session_token", NULL, section = profile)
)
}

Expand All @@ -77,10 +79,7 @@ load_aws_credentials <- function(location = NULL, profile = NULL) {
#' @param location file path where token is located
#'
#' @return named listed of override configuration values
load_oauth_credentials <- function(location = NULL) {
if (is.null(location)) {
location <- "/var/lib/domino/home/.api/token"
}
load_oauth_credentials <- function(location) {
list(
token = readChar(location, file.info(location)$size)
)
Expand Down
2 changes: 1 addition & 1 deletion man/load_aws_credentials.Rd

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

2 changes: 1 addition & 1 deletion man/load_oauth_credentials.Rd

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

0 comments on commit 0a637a8

Please sign in to comment.