Skip to content

Commit

Permalink
fix crash on erlcloud_ec2:describe_instance_attribute if attribute is…
Browse files Browse the repository at this point in the history
… empty
  • Loading branch information
fogfish committed Jan 16, 2013
1 parent f989cd9 commit 18eebe1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ _build
ebin/*.beam
ebin/*.app
.eunit/
rebar
*.sublime-*
deps/
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
REBAR=$(shell which rebar || echo ./rebar)

all: get-deps compile

get-deps:
@$(REBAR) get-deps

all: compile

clean:
@$(REBAR) clean

compile:
@$(REBAR) compile

eunit: compile
@$(REBAR) eunit skip_deps=true
@$(REBAR) eunit skip_deps=true
30 changes: 19 additions & 11 deletions src/erlcloud_ec2.erl
Original file line number Diff line number Diff line change
Expand Up @@ -621,19 +621,27 @@ describe_instance_attribute(InstanceID, Attribute, Config)
block_device_mapping -> "blockDeviceMapping"
end,
Doc = ec2_query(Config, "DescribeInstanceAttribute", [{"InstanceId", InstanceID}, {"Attribute", AttributeName}]),
Node = case Attribute of
block_device_mapping -> hd(xmerl_xpath:string("/DescribeInstanceAttributeResponse/" ++ AttributeName, Doc));
_ -> hd(xmerl_xpath:string("/DescribeInstanceAttributeResponse/" ++ AttributeName ++ "/value", Doc))
end,
case Attribute of
user_data -> base64:decode(get_text(Node));
disable_api_termination -> list_to_existing_atom(get_text(Node));
instance_initiated_shutdown_behavior -> list_to_existing_atom(get_text(Node));
block_device_mapping ->
[extract_block_device_mapping_status(Item) || Item <- xmerl_xpath:string("item", Node)];
_ -> get_text(Node)
case xmerl_xpath:string(attribute_xpath(Attribute, AttributeName), Doc) of
% attribute might not be defined
[] ->
undefined;
[Node | _] ->
case Attribute of
user_data -> base64:decode(get_text(Node));
disable_api_termination -> list_to_existing_atom(get_text(Node));
instance_initiated_shutdown_behavior -> list_to_existing_atom(get_text(Node));
block_device_mapping ->
[extract_block_device_mapping_status(Item) || Item <- xmerl_xpath:string("item", Node)];
_ -> get_text(Node)
end
end.

attribute_xpath(block_device_mapping, AttributeName) ->
"/DescribeInstanceAttributeResponse/" ++ AttributeName;
attribute_xpath(_, AttributeName) ->
"/DescribeInstanceAttributeResponse/" ++ AttributeName ++ "/value".


-spec(describe_instances/0 :: () -> proplist()).
describe_instances() -> describe_instances([]).

Expand Down

0 comments on commit 18eebe1

Please sign in to comment.