signature_v2_auth: Signature Version 2

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/v2.R

Description

Generates AWS Signature Version 2

Usage

1
2
3
4
signature_v2_auth(datetime = format(Sys.time(), "%Y-%M-%dT%H:%M:%S", tz
  = "UTC"), verb, service, path, query_args = list(),
  key = Sys.getenv("AWS_ACCESS_KEY_ID"),
  secret = Sys.getenv("AWS_SECRET_ACCESS_KEY"))

Arguments

datetime

A character string containing a date in the form of “YYYY-MM-DDTH:M:S”. If missing, it is generated automatically using Sys.time.

verb

A character string specify an HTTP verb/method (e.g., “GET”).

service

A character string containing the full hostname of an AWS service (e.g., “iam.amazonaws.com”, etc.)

path

A character string specify the path to the API endpoint.

query_args

A list containing named query arguments.

key

An AWS Access Key ID. If missing, it is retrieved using Sys.getenv("AWS_ACCESS_KEY_ID").

secret

An AWS Secret Access Key. If missing, it is retrieved using Sys.getenv("AWS_SECRET_ACCESS_KEY").

Details

This function generates an AWS Signature Version 2 for authorizing API requests. The function returns both an updated set of query string parameters, containing the required signature-related entries, as well as a Signature field containing the Signature string itself.

Value

A list

Author(s)

Thomas J. Leeper <[email protected]>

References

AWS General Reference: Signature Version 2 Signing Process

See Also

signature_v4_auth, use_credentials

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# examples from:
# http://docs.aws.amazon.com/general/latest/gr/signature-version-2.html

true_string <- paste0("GET\n",
"elasticmapreduce.amazonaws.com\n",
"/\n",
"AWSAccessKeyId=AKIAIOSFODNN7EXAMPLE",
"&Action=DescribeJobFlows",
"&SignatureMethod=HmacSHA256",
"&SignatureVersion=2",
"&Timestamp=2011-10-03T15\%3A19\%3A30",
"&Version=2009-03-31", collapse = "")
true_sig <- "i91nKc4PWAt0JJIdXwz9HxZCJDdiy6cf/Mj6vPxyYIs="

q1 <- 
list(Action = "DescribeJobFlows",
     Version = "2009-03-31",
     AWSAccessKeyId = "AKIAIOSFODNN7EXAMPLE",
     SignatureVersion = "2",
     SignatureMethod = "HmacSHA256",
     Timestamp = "2011-10-03T15:19:30")

sig1 <- 
signature_v2_auth(datetime = "2011-10-03T15:19:30",
                  service = "elasticmapreduce.amazonaws.com",
                  verb = "GET",
                  path = "/",
                  query_args = q1,
                  key = q1$AWSAccessKeyId,
                  secret = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY")
identical(true_string, sig1$CanonicalRequest)
identical(true_sig, sig1$Signature)

# leaving out some defaults
q2 <- 
list(Action = "DescribeJobFlows",
     Version = "2009-03-31",
     Timestamp = "2011-10-03T15:19:30")
sig2 <- 
signature_v2_auth(datetime = "2011-10-03T15:19:30",
                  service = "elasticmapreduce.amazonaws.com",
                  verb = "GET",
                  path = "/",
                  query_args = q2,
                  key = "AKIAIOSFODNN7EXAMPLE",
                  secret = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY")
identical(true_string, sig2$CanonicalRequest)
identical(true_sig, sig2$Signature)

zhangxing-love/qingstor.signature documentation built on May 23, 2019, 9:35 a.m.