Skip to content

Commit 981f19e

Browse files
committed
Make AWSConfig its own type
Rather than defining `AWSConfig` as a `SymbolDict` with no restrictions on the contents, we can make it its own type, which gives more control over how things are stored and accessed. Fixes #53
1 parent ec40010 commit 981f19e

File tree

2 files changed

+59
-33
lines changed

2 files changed

+59
-33
lines changed

src/AWSCore.jl

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,69 @@ using DataStructures: OrderedDict
2222
using JSON
2323
using LazyJSON
2424

25+
# NOTE: This needs to be defined before AWSConfig. Methods defined on AWSCredentials are
26+
# in src/AWSCredentials.jl.
27+
"""
28+
AWSCredentials
29+
30+
A type which holds AWS credentials.
31+
When you interact with AWS, you specify your
32+
[AWS Security Credentials](http://docs.aws.amazon.com/general/latest/gr/aws-security-credentials.html)
33+
to verify who you are and whether you have permission to access the resources that you are
34+
requesting. AWS uses the security credentials to authenticate and authorize your requests.
35+
36+
The fields `access_key_id` and `secret_key` hold the access keys used to authenticate API
37+
requests (see [Creating, Modifying, and Viewing Access
38+
Keys](http://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html#Using_CreateAccessKey)).
39+
40+
[Temporary Security Credentials](http://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp.html)
41+
require the extra session `token` field.
2542
43+
The `user_arn` and `account_number` fields are used to cache the result of the
44+
[`aws_user_arn`](@ref) and [`aws_account_number`](@ref) functions.
45+
46+
The `AWSCredentials()` constructor tries to load local Credentials from
47+
environment variables, `~/.aws/credentials`, `~/.aws/config`, or EC2 instance credentials.
48+
To specify the profile to use from `~/.aws/credentials`, do, for example,
49+
`AWSCredentials(profile="profile-name")`.
2650
"""
27-
Most `AWSCore` functions take a `AWSConfig` dictionary as the first argument.
28-
This dictionary holds [`AWSCredentials`](@ref) and AWS region configuration.
51+
mutable struct AWSCredentials
52+
access_key_id::String
53+
secret_key::String
54+
token::String
55+
user_arn::String
56+
account_number::String
57+
58+
function AWSCredentials(access_key_id, secret_key,
59+
token="", user_arn="", account_number="")
60+
new(access_key_id, secret_key, token, user_arn, account_number)
61+
end
62+
end
2963

30-
```julia
31-
aws = AWSConfig(:creds => AWSCredentials(), :region => "us-east-1")`
64+
"""
65+
AWSConfig
66+
67+
Most `AWSCore` functions take an `AWSConfig` object as the first argument.
68+
This type holds [`AWSCredentials`](@ref), region, and output configuration.
69+
70+
```julia-repl
71+
julia> AWSConfig(creds=AWSCredentials(), region="us-east-1")
72+
AWSConfig((AKIDEXAMPLE, wJa...)
73+
, "us-east-1", "json")
3274
```
3375
"""
34-
const AWSConfig = SymbolDict
76+
mutable struct AWSConfig
77+
creds::AWSCredentials
78+
region::String
79+
output::String
80+
end
81+
AWSConfig(; creds, region, output="json") = AWSConfig(creds, region, output)
3582

83+
# Relics of using SymbolDict
84+
import Base: getindex, setindex!
85+
Base.@deprecate AWSConfig(pairs::Pair...) AWSConfig(; pairs...)
86+
Base.@deprecate getindex(conf::AWSConfig, x::Symbol) getfield(conf, x)
87+
Base.@deprecate setindex!(conf::AWSConfig, val, var::Symbol) setfield!(conf, var, val)
3688

3789
"""
3890
The `AWSRequest` dictionary describes a single API request:
@@ -57,7 +109,6 @@ include("names.jl")
57109
include("mime.jl")
58110

59111

60-
61112
#------------------------------------------------------------------------------#
62113
# Configuration.
63114
#------------------------------------------------------------------------------#

src/AWSCredentials.jl

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,7 @@ export AWSCredentials,
1717
aws_account_number
1818

1919

20-
"""
21-
When you interact with AWS, you specify your [AWS Security Credentials](http://docs.aws.amazon.com/general/latest/gr/aws-security-credentials.html) to verify who you are and whether you have permission to access the resources that you are requesting. AWS uses the security credentials to authenticate and authorize your requests.
22-
23-
The fields `access_key_id` and `secret_key` hold the access keys used to authenticate API requests (see [Creating, Modifying, and Viewing Access Keys](http://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html#Using_CreateAccessKey)).
24-
25-
[Temporary Security Credentials](http://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp.html) require the extra session `token` field.
26-
27-
28-
The `user_arn` and `account_number` fields are used to cache the result of the [`aws_user_arn`](@ref) and [`aws_account_number`](@ref) functions.
29-
30-
The `AWSCredentials()` constructor tries to load local Credentials from
31-
environment variables, `~/.aws/credentials`, `~/.aws/config` or EC2 instance credentials.
32-
To specify the profile to use from `~/.aws/credentials`, do, for example, `AWSCredentials(profile="profile-name")`.
33-
"""
34-
mutable struct AWSCredentials
35-
access_key_id::String
36-
secret_key::String
37-
token::String
38-
user_arn::String
39-
account_number::String
40-
41-
function AWSCredentials(access_key_id, secret_key,
42-
token="", user_arn="", account_number="")
43-
new(access_key_id, secret_key, token, user_arn, account_number)
44-
end
45-
end
20+
# AWSCredentials type defined in src/AWSCore.jl
4621

4722
function Base.show(io::IO,c::AWSCredentials)
4823
println(io, string(c.user_arn,
@@ -322,7 +297,7 @@ function aws_get_role(role::AbstractString, ini::Inifile)
322297
end
323298
credentials = dot_aws_credentials(source_profile)
324299

325-
config = AWSConfig(:creds=>credentials, :region=>aws_get_region(source_profile, ini))
300+
config = AWSConfig(creds=credentials, region=aws_get_region(source_profile, ini))
326301

327302
role = Services.sts(
328303
config,

0 commit comments

Comments
 (0)