Skip to content

Commit

Permalink
Bug fix in typespec for lookup_events
Browse files Browse the repository at this point in the history
  • Loading branch information
fmcgeough committed Mar 1, 2019
1 parent 121ef50 commit 30346e5
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
v2.0.2

* Fix: Change typespec for lookup_events and handle list of lists properly

v2.0.1

* Enhancement: Added support for listing all lookup events with ListLookupEvents module.
Expand Down
13 changes: 11 additions & 2 deletions lib/ex_aws/cloud_trail.ex
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ defmodule ExAws.CloudTrail do
@type lookup_attribute :: [attribute_key: binary, attribute_value: binary]
@type lookup_events_opts :: [
end_time: binary,
lookup_attributes: [lookup_attribute, ...],
lookup_attributes: [lookup_attribute, ...] | lookup_attribute,
max_results: integer,
next_token: binary,
start_time: binary
Expand Down Expand Up @@ -590,7 +590,16 @@ defmodule ExAws.CloudTrail do
)
end

defp handle_lookup_attributes(val) do
# AWS only accepts one lookup attribute on lookup_events
defp handle_lookup_attributes(input_val) do
[h | _t] = input_val

val =
case is_list(h) do
true -> Enum.at(input_val, 0)
false -> input_val
end

%{"LookupAttributes" => [camelize_keys(val)]}
end
end
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule ExAwsCloudTrail.MixProject do
use Mix.Project

@version "2.0.1"
@version "2.0.2"

def project do
[
Expand Down
25 changes: 25 additions & 0 deletions test/lookup_events_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,29 @@ defmodule LookupEventsTest do
]
}
end

test "formatting handles a list of lists in lookup_attributes" do
# try and pass multiple lookup attributes. should ignore all but first
op =
ExAws.CloudTrail.lookup_events(
lookup_attributes: [
[attribute_key: "ReadOnly", attribute_value: "false"],
[attribute_key: "AnotherKey", attribute_value: "Another Value"]
]
)

assert op.headers == [
{"x-amz-target", "CloudTrail_20131101.LookupEvents"},
{"content-type", "application/x-amz-json-1.1"}
]

assert op.data == %{
"LookupAttributes" => [
%{
"AttributeKey" => "ReadOnly",
"AttributeValue" => "false"
}
]
}
end
end

0 comments on commit 30346e5

Please sign in to comment.