cloudyr / aws.ec2metadata
Showing 1 of 1 files from the diff.

@@ -2,6 +2,34 @@
Loading
2 2
    strsplit(x, "\n")[[1]]
3 3
}
4 4
5 +
get_timeout <- function(default_timeout="1") {
6 +
    # check for timeout in env vars
7 +
    timeout <- Sys.getenv("AWS_METADATA_SERVICE_TIMEOUT", default_timeout)
8 +
    timeout <- as.integer(timeout)
9 +
    if (is.na(timeout)) {
10 +
        timeout <- 1
11 +
    }
12 +
    return(timeout*1000)
13 +
}
14 +
15 +
fetch <- function(uri) {
16 +
    timeout <- get_timeout()
17 +
    handle <- curl::new_handle(timeout_ms = timeout)
18 +
    
19 +
    response <- try(
20 +
        curl::curl_fetch_memory(uri,
21 +
                                handle = handle),
22 +
        silent = TRUE
23 +
    )
24 +
    
25 +
    if (inherits(response, "try-error")) {
26 +
        return(NULL)
27 +
    } else {
28 +
        return(response)
29 +
    }
30 +
31 +
}
32 +
5 33
get_instance_metadata <- function(item,
6 34
                                  version = "latest",
7 35
                                  base_url = "http://169.254.169.254/", 
@@ -12,8 +40,8 @@
Loading
12 40
    } else {
13 41
        uri <- base_url
14 42
    }
15 -
    response <- try(curl::curl_fetch_memory(uri, handle = curl::new_handle(timeout_ms = 1000)), silent = TRUE)
16 -
    if (inherits(response, "try-error")) {
43 +
    response <- fetch(uri)
44 +
    if (is.null(response)) {
17 45
        stop("Request failed", call. = FALSE)
18 46
    } else if (response[["status_code"]] >= 400) {
19 47
        return(NULL)
@@ -198,8 +226,10 @@
Loading
198 226
ecs_metadata <- function(base_url = "http://169.254.170.2") {
199 227
    container_relative <- Sys.getenv(ENV_CONTAINER_CREDS)
200 228
    uri <- paste0(base_url, container_relative)
201 -
    response <- try(curl::curl_fetch_memory(uri, handle = curl::new_handle(timeout_ms = 1000)), silent = TRUE)
202 -
    if (inherits(response, "try-error")) {
229 +
    
230 +
    response <- fetch(uri)
231 +
    
232 +
    if (is.null(response)) {
203 233
        out <- NULL
204 234
    } else {
205 235
        out <- jsonlite::fromJSON(rawToChar(response[["content"]]))
Files Coverage
R 71.74%
Project Totals (2 files) 71.74%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading