Skip to content

Commit

Permalink
Revert "Set features for low-level calls"
Browse files Browse the repository at this point in the history
This reverts commit 94742ab.
This reverts commit 2c8a648.
This reverts commit c2c015d32119c705cfa558e09dd8580279b57f66.
  • Loading branch information
omus committed Sep 24, 2021
1 parent 5f69c45 commit e122a20
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 75 deletions.
4 changes: 1 addition & 3 deletions src/AWSConfig.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ function aws_account_number(aws::AWSConfig)
end

function _update_creds!(aws_config::AWSConfig)
r = AWSServices.sts(
"GetCallerIdentity"; aws_config=aws_config, features=DEFAULT_SERVICE_FEATURES
)
r = AWSServices.sts("GetCallerIdentity"; aws_config=aws_config)
r = r["GetCallerIdentityResult"]
creds = aws_config.credentials

Expand Down
6 changes: 1 addition & 5 deletions src/AWSCredentials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,7 @@ function ec2_instance_credentials(profile::AbstractString)
params["DurationSeconds"] = parse(Int, duration)
end
resp = @mock AWSServices.sts(
"AssumeRole",
params;
aws_config=AWSConfig(; creds=instance_profile_creds),
features=DEFAULT_SERVICE_FEATURES,
"AssumeRole", params; aws_config=AWSConfig(; creds=instance_profile_creds)
)
role_creds = resp["AssumeRoleResult"]["Credentials"]
role_user = resp["AssumeRoleResult"]["AssumedRoleUser"]
Expand Down Expand Up @@ -522,7 +519,6 @@ function credentials_from_webtoken()
"WebIdentityToken" => web_identity,
);
aws_config=AWSConfig(; creds=nothing),
features=DEFAULT_SERVICE_FEATURES,
)

role_creds = resp["AssumeRoleWithWebIdentityResult"]["Credentials"]
Expand Down
4 changes: 1 addition & 3 deletions src/utilities/credentials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ function _aws_get_role(role::AbstractString, ini::Inifile)

# RoleSessionName Documentation
# https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html
role = @mock AWSServices.sts(
"AssumeRole", params; aws_config=config, features=DEFAULT_SERVICE_FEATURES
)
role = @mock AWSServices.sts("AssumeRole", params; aws_config=config)

role_creds = role["AssumeRoleResult"]["Credentials"]

Expand Down
93 changes: 31 additions & 62 deletions test/AWS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ end
end

@testset "low-level" begin
response = AWSServices.sts("GetCallerIdentity"; LOW_LVL_KWARGS...)
response = AWSServices.sts("GetCallerIdentity")
d = response["GetCallerIdentityResult"]

@test Set(keys(d)) == Set(["Arn", "UserId", "Account"])
Expand Down Expand Up @@ -599,7 +599,7 @@ end

function _get_secret_string(secret_name)
response = AWSServices.secrets_manager(
"GetSecretValue", LittleDict("SecretId" => secret_name); LOW_LVL_KWARGS...
"GetSecretValue", LittleDict("SecretId" => secret_name)
)

return response["SecretString"]
Expand All @@ -611,8 +611,7 @@ end
"Name" => secret_name,
"SecretString" => secret_string,
"ClientRequestToken" => string(uuid4()),
);
LOW_LVL_KWARGS...,
),
)

try
Expand All @@ -622,8 +621,7 @@ end
"DeleteSecret",
LittleDict(
"SecretId" => secret_name, "ForceDeleteWithoutRecovery" => "true"
);
LOW_LVL_KWARGS...,
),
)
end

Expand Down Expand Up @@ -683,27 +681,23 @@ end
LittleDict(
"PolicyName" => expected_policy_name,
"PolicyDocument" => expected_policy_document,
);
LOW_LVL_KWARGS...,
),
)
policy_arn = response["CreatePolicyResult"]["Policy"]["Arn"]

try
response_policy_version = AWSServices.iam(
"GetPolicyVersion",
LittleDict("PolicyArn" => policy_arn, "VersionId" => "v1");
LOW_LVL_KWARGS...,
LittleDict("PolicyArn" => policy_arn, "VersionId" => "v1"),
)
response_document = response_policy_version["GetPolicyVersionResult"]["PolicyVersion"]["Document"]
@test HTTP.unescapeuri(response_document) == expected_policy_document
finally
AWSServices.iam(
"DeletePolicy", LittleDict("PolicyArn" => policy_arn); LOW_LVL_KWARGS...
)
AWSServices.iam("DeletePolicy", LittleDict("PolicyArn" => policy_arn))
end

@test_throws AWSException AWSServices.iam(
"GetPolicy", LittleDict("PolicyArn" => policy_arn); LOW_LVL_KWARGS...
"GetPolicy", LittleDict("PolicyArn" => policy_arn)
)
end

Expand Down Expand Up @@ -764,17 +758,13 @@ end
expected_message = "Hello for AWS.jl"

function _get_queue_url(queue_name)
result = AWSServices.sqs(
"GetQueueUrl", LittleDict("QueueName" => queue_name); LOW_LVL_KWARGS...
)
result = AWSServices.sqs("GetQueueUrl", LittleDict("QueueName" => queue_name))

return result["GetQueueUrlResult"]["QueueUrl"]
end

# Create Queue
AWSServices.sqs(
"CreateQueue", LittleDict("QueueName" => queue_name); LOW_LVL_KWARGS...
)
AWSServices.sqs("CreateQueue", LittleDict("QueueName" => queue_name))

queue_url = _get_queue_url(queue_name)
@test !isempty(queue_url)
Expand All @@ -785,12 +775,11 @@ end

AWSServices.sqs(
"SendMessage",
LittleDict("QueueUrl" => queue_url, "MessageBody" => expected_message);
LOW_LVL_KWARGS...,
LittleDict("QueueUrl" => queue_url, "MessageBody" => expected_message),
)

response = AWSServices.sqs(
"ReceiveMessage", LittleDict("QueueUrl" => queue_url); LOW_LVL_KWARGS...
"ReceiveMessage", LittleDict("QueueUrl" => queue_url)
)
receipt_handle = response["ReceiveMessageResult"]["Message"]["ReceiptHandle"]

Expand All @@ -804,8 +793,7 @@ end
"ReceiptHandle" => receipt_handle,
),
],
);
LOW_LVL_KWARGS...,
),
)

message_id = response["DeleteMessageBatchResult"]["DeleteMessageBatchResultEntry"]["Id"]
Expand All @@ -814,20 +802,15 @@ end
# Send message
AWSServices.sqs(
"SendMessage",
LittleDict("QueueUrl" => queue_url, "MessageBody" => expected_message);
LOW_LVL_KWARGS...,
LittleDict("QueueUrl" => queue_url, "MessageBody" => expected_message),
)

# Receive Message
result = AWSServices.sqs(
"ReceiveMessage", LittleDict("QueueUrl" => queue_url); LOW_LVL_KWARGS...
)
result = AWSServices.sqs("ReceiveMessage", LittleDict("QueueUrl" => queue_url))
message = result["ReceiveMessageResult"]["Message"]["Body"]
@test message == expected_message
finally
AWSServices.sqs(
"DeleteQueue", LittleDict("QueueUrl" => queue_url); LOW_LVL_KWARGS...
)
AWSServices.sqs("DeleteQueue", LittleDict("QueueUrl" => queue_url))
end

@test_throws AWSException _get_queue_url(queue_name)
Expand Down Expand Up @@ -902,7 +885,7 @@ end

function _bucket_exists(bucket_name)
try
AWSServices.s3("HEAD", "/$bucket_name"; LOW_LVL_KWARGS...)
AWSServices.s3("HEAD", "/$bucket_name")
return true
catch e
if e isa AWSException && e.cause.status == 404
Expand All @@ -917,28 +900,22 @@ end
@test _bucket_exists(bucket_name) == false

# PUT operation
AWSServices.s3("PUT", "/$bucket_name"; LOW_LVL_KWARGS...)
AWSServices.s3("PUT", "/$bucket_name")
@test _bucket_exists(bucket_name)

try
# PUT with parameters operation
body = Array{UInt8}("sample-file-body")
AWSServices.s3(
"PUT", "/$bucket_name/$file_name", Dict("body" => body); LOW_LVL_KWARGS...
)
@test AWSServices.s3(
"GET", "/$bucket_name/$file_name"; LOW_LVL_KWARGS...
).body == body
AWSServices.s3("PUT", "/$bucket_name/$file_name", Dict("body" => body))
@test AWSServices.s3("GET", "/$bucket_name/$file_name") == body

# GET operation
result = AWSServices.s3("GET", "/$bucket_name"; LOW_LVL_KWARGS...)
result = AWSServices.s3("GET", "/$bucket_name")
@test result["Contents"]["Key"] == file_name

# GET with parameters operation
max_keys = 1
result = AWSServices.s3(
"GET", "/$bucket_name", Dict("max_keys" => max_keys); LOW_LVL_KWARGS...
)
result = AWSServices.s3("GET", "/$bucket_name", Dict("max_keys" => max_keys))
@test length([result["Contents"]]) == max_keys

# POST with parameters operation
Expand All @@ -950,15 +927,11 @@ end
</Delete>
"""

AWSServices.s3(
"POST", "/$bucket_name?delete", Dict("body" => body); LOW_LVL_KWARGS...
)
@test_throws AWSException AWSServices.s3(
"GET", "/$bucket_name/$file_name"; LOW_LVL_KWARGS...
)
AWSServices.s3("POST", "/$bucket_name?delete", Dict("body" => body))
@test_throws AWSException AWSServices.s3("GET", "/$bucket_name/$file_name")
finally
# DELETE operation
AWSServices.s3("DELETE", "/$bucket_name"; LOW_LVL_KWARGS...)
AWSServices.s3("DELETE", "/$bucket_name")

sleep(2)
end
Expand Down Expand Up @@ -1020,23 +993,19 @@ end

# PUT
for vault in vault_names
AWSServices.glacier("PUT", "/-/vaults/$vault"; LOW_LVL_KWARGS...)
AWSServices.glacier("PUT", "/-/vaults/$vault")
end

try
# POST
tags = Dict("Tags" => LittleDict("Tag-01" => "Tag-01", "Tag-02" => "Tag-02"))

for vault in vault_names
AWSServices.glacier(
"POST", "/-/vaults/$vault/tags?operation=add", tags; LOW_LVL_KWARGS...
)
AWSServices.glacier("POST", "/-/vaults/$vault/tags?operation=add", tags)
end

for vault in vault_names
result_tags = Dict(
AWSServices.glacier("GET", "/-/vaults/$vault/tags"; LOW_LVL_KWARGS...)
)
result_tags = Dict(AWSServices.glacier("GET", "/-/vaults/$vault/tags"))
@test result_tags == tags
end

Expand All @@ -1045,17 +1014,17 @@ end
# "class com.amazon.coral.value.json.numbers.TruncatingBigNumber can not be converted to an String"
limit = "1"
params = LittleDict("limit" => limit)
result = AWSServices.glacier("GET", "/-/vaults/", params; LOW_LVL_KWARGS...)
result = AWSServices.glacier("GET", "/-/vaults/", params)

@test length(result["VaultList"]) == parse(Int, limit)
finally
# DELETE
for vault in vault_names
AWSServices.glacier("DELETE", "/-/vaults/$vault"; LOW_LVL_KWARGS...)
AWSServices.glacier("DELETE", "/-/vaults/$vault")
end
end

result = AWSServices.glacier("GET", "/-/vaults"; LOW_LVL_KWARGS...)
result = AWSServices.glacier("GET", "/-/vaults")
res_vault_names = [v["VaultName"] for v in result["VaultList"]]

for vault in vault_names
Expand Down
2 changes: 0 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ const TEST_MINIO = begin
all(k -> haskey(ENV, k), ("MINIO_ACCESS_KEY", "MINIO_SECRET_KEY", "MINIO_REGION_NAME"))
end

const LOW_LVL_KWARGS = (; features=(; use_response_type=true))

aws = AWSConfig()

function _now_formatted()
Expand Down

0 comments on commit e122a20

Please sign in to comment.