forked from abitdodgy/ex_aws_iam
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from stygia/feature/add-list-roles
Added ListRoles and ListRoleTags
- Loading branch information
Showing
8 changed files
with
254 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
defmodule ExAws.Iam.Parsers.Role do | ||
@moduledoc """ | ||
Defines parsers for handling AWS IAM `Role` query reponses. | ||
""" | ||
|
||
import SweetXml, only: [sigil_x: 2] | ||
import ExAws.Iam.Utils, only: [response_metadata_path: 0] | ||
|
||
@doc """ | ||
Parses XML from IAM `ListRoles` response. | ||
""" | ||
def parse(xml, "ListRoles") do | ||
SweetXml.xpath(xml, ~x"//ListRolesResponse", | ||
list_roles_result: [ | ||
~x"//ListRolesResult", | ||
is_truncated: ~x"./IsTruncated/text()"s, | ||
marker: ~x"./Marker/text()"o, | ||
roles: [ | ||
~x"./Roles/member"l, | ||
path: ~x"./Path/text()"s, | ||
role_name: ~x"./RoleName/text()"s, | ||
arn: ~x"./Arn/text()"s, | ||
role_id: ~x"./RoleId/text()"s, | ||
create_date: ~x"./CreateDate/text()"s, | ||
max_session_duration: ~x"./MaxSessionDuration/text()"s, | ||
assume_role_policy_document: | ||
~x"./AssumeRolePolicyDocument/text()"s |> SweetXml.transform_by(&URI.decode/1) | ||
] | ||
], | ||
response_metadata: response_metadata_path() | ||
) | ||
end | ||
|
||
@doc """ | ||
Parses XML from IAM `ListRoleTags` response. | ||
""" | ||
def parse(xml, "ListRoleTags") do | ||
SweetXml.xpath(xml, ~x"//ListRoleTagsResponse", | ||
list_role_tags_result: [ | ||
~x"//ListRoleTagsResult", | ||
is_truncated: ~x"./IsTruncated/text()"s, | ||
marker: ~x"./Marker/text()"o, | ||
tags: [ | ||
~x"./Tags/member"l, | ||
key: ~x"./Key/text()"s, | ||
value: ~x"./Value/text()"s | ||
] | ||
], | ||
response_metadata: response_metadata_path() | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
defmodule ExAws.Iam.Parsers.RoleTest do | ||
use ExUnit.Case | ||
|
||
import ExAws.Iam.TestHelper, only: [read_file: 2] | ||
|
||
alias ExAws.Iam.Parser | ||
|
||
test "list_roles/2" do | ||
xml = read_file("role", "list_roles") | ||
response = {:ok, %{body: xml, status_code: 200}} | ||
|
||
expected = | ||
{:ok, | ||
%{ | ||
body: %{ | ||
list_roles_result: %{ | ||
is_truncated: "false", | ||
marker: nil, | ||
roles: [ | ||
%{ | ||
arn: "arn:aws:iam::085326204011:role/foo", | ||
assume_role_policy_document: | ||
"{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"Service\":\"ec2.amazonaws.com\"},\"Action\":\"sts:AssumeRole\"}]}", | ||
create_date: "2018-10-19T22:04:37Z", | ||
max_session_duration: "3600", | ||
path: "/", | ||
role_id: "AGPAIDI3XY2DD433B73WG", | ||
role_name: "foo" | ||
} | ||
] | ||
}, | ||
response_metadata: %{request_id: "81ca4919-d3fb-11e8-986e-5fbe089ad211"} | ||
}, | ||
status_code: 200 | ||
}} | ||
|
||
assert expected == Parser.parse(response, "ListRoles") | ||
end | ||
|
||
test "list_role_tags/2" do | ||
xml = read_file("role", "list_role_tags") | ||
response = {:ok, %{body: xml, status_code: 200}} | ||
|
||
expected = | ||
{:ok, | ||
%{ | ||
body: %{ | ||
list_role_tags_result: %{ | ||
is_truncated: "false", | ||
marker: nil, | ||
tags: [ | ||
%{key: "UserRole", value: "developer"} | ||
] | ||
}, | ||
response_metadata: %{request_id: "81ca4919-d3fb-11e8-986e-5fbe089ad211"} | ||
}, | ||
status_code: 200 | ||
}} | ||
|
||
assert expected == Parser.parse(response, "ListRoleTags") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<ListRoleTagsResponse xmlns="https://iam.amazonaws.com/doc/2010-05-08/"> | ||
<ListRoleTagsResult> | ||
<IsTruncated>false</IsTruncated> | ||
<Tags> | ||
<member> | ||
<Value>developer</Value> | ||
<Key>UserRole</Key> | ||
</member> | ||
</Tags> | ||
</ListRoleTagsResult> | ||
<ResponseMetadata> | ||
<RequestId>81ca4919-d3fb-11e8-986e-5fbe089ad211</RequestId> | ||
</ResponseMetadata> | ||
</ListRoleTagsResponse> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<ListRolesResponse xmlns="https://iam.amazonaws.com/doc/2010-05-08/"> | ||
<ListRolesResult> | ||
<IsTruncated>false</IsTruncated> | ||
<Roles> | ||
<member> | ||
<Path>/</Path> | ||
<AssumeRolePolicyDocument>%7B%22Version%22%3A%222012-10-17%22%2C%22Statement%22%3A%5B%7B%22Effect%22%3A%22Allow%22%2C%22Principal%22%3A%7B%22Service%22%3A%22ec2.amazonaws.com%22%7D%2C%22Action%22%3A%22sts%3AAssumeRole%22%7D%5D%7D</AssumeRolePolicyDocument> | ||
<MaxSessionDuration>3600</MaxSessionDuration> | ||
<RoleId>AGPAIDI3XY2DD433B73WG</RoleId> | ||
<RoleName>foo</RoleName> | ||
<Arn>arn:aws:iam::085326204011:role/foo</Arn> | ||
<CreateDate>2018-10-19T22:04:37Z</CreateDate> | ||
</member> | ||
</Roles> | ||
</ListRolesResult> | ||
<ResponseMetadata> | ||
<RequestId>81ca4919-d3fb-11e8-986e-5fbe089ad211</RequestId> | ||
</ResponseMetadata> | ||
</ListRolesResponse> |