Skip to content

Commit

Permalink
Merge pull request #685 from DyfanJones/service_endpoint
Browse files Browse the repository at this point in the history
Service endpoint
  • Loading branch information
DyfanJones authored Oct 5, 2023
2 parents 9392efc + ee11603 commit 213be0a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion paws.common/NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# paws.common 0.6.1.9000
* fix how `read_ini` reads empty profiles from ini files
* fix is.atomic behavior for R v4.4+
* support service specific endpoints (#667)
* support service specific endpoints (#667). Thanks to @dpprdan for raising ticket and testing methods

# paws.common 0.6.1
* support nested content within ini files (#667) [Configuration and credential file settings](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html#cli-configure-files-s3)
Expand Down
15 changes: 7 additions & 8 deletions paws.common/R/iniutil.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,27 @@ read_ini <- function(file_name) {
scan(file_name, what = "", sep = "\n", quiet = T),
perl = TRUE
)
content_length <- length(content)

# An empty credentials file is valid when using SSO
# In that case, length(content) is 0. Don't loop
# in such a case, since 'grepl(..., content[i])'
# will return logical(0), causing the 'if' to error out
if (content_length == 0) return(list())
if (length(content) == 0) return(list())

# Get the profile name from an ini file
found <- grep("^\\[.*\\]", content)
rm_els <- grep("(^;)|(^#)", content)
rm_els <- grep("(^;)|(^\\s+;)|(^#)|(^\\s+#)", content, perl = TRUE)
if (length(rm_els) > 0) content <- content[-rm_els]

found <- grep("^\\[.*\\]", content, perl = TRUE)

profile_nms <- gsub("\\[|\\]", "", content[found])
profiles <- vector("list", length = length(profile_nms))
names(profiles) <- profile_nms

start <- (found + 1)
end <- c(found[-1]-1, content_length)
end <- c(found[-1]-1, length(content))
split_content <- strsplit(sub("=", "\n", content, fixed = T), "\n", fixed = T)
for (i in which(start <= end)) {
els <- seq.int(start[i], end[i])
sub_content <- split_content[els[!(els %in% rm_els)]]
sub_content <- split_content[seq.int(start[i], end[i])]
found_nested_content <- lengths(sub_content) == 1

if (any(found_nested_content)) {
Expand Down
7 changes: 6 additions & 1 deletion paws.common/tests/testthat/data_ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Empty comment

[default]
arg1=value1
arg2=value2
Expand Down Expand Up @@ -36,10 +38,12 @@ nested1 =
arg1 = value1
arg2 = value2
arg3 = value3
nested2 =
nested2 =
arg4 = value4
; arg2=value2

[empty2]
# Empty comment

[profile minio]
region=us-east-1
Expand All @@ -49,3 +53,4 @@ services = profileminio
[services profileminio]
s3 =
endpoint_url = http://localhost:9000
# Empty comment

0 comments on commit 213be0a

Please sign in to comment.