Permalink
Browse files

Add support for accepting wrapped data bag items as provided by knife

  • Loading branch information...
1 parent b901f8c commit a3ec21e631c8502c8430363f0fbc8a4d856dd8c5 @seth seth committed Aug 30, 2012
Showing with 13 additions and 1 deletion.
  1. +13 −1 src/chef_data_bag_item.erl
View
@@ -67,7 +67,7 @@ parse_binary_json(Bin, Action) ->
%% currently without any additional information. Do we want to
%% emit the JSON we recieved (size limited) or some details of the
%% parse error from ejson if we can extract it?
- DataBagItem = ejson:decode(Bin),
+ DataBagItem = maybe_unwrap(ejson:decode(Bin)),
validate_data_bag_item(DataBagItem, Action).
validate_data_bag_item(DataBagItem, create) ->
@@ -92,3 +92,15 @@ validate_data_bag_item(DataBagItem, {update, UrlName}) ->
Mismatch ->
throw({url_json_name_mismatch, {UrlName, Mismatch, "DataBagItem"}})
end.
+
+maybe_unwrap(Ejson) ->
+ case is_wrapped_item(Ejson) of
+ true ->
+ ej:get({<<"raw_data">>}, Ejson);
+ false ->
+ Ejson
+ end.
+
+is_wrapped_item(Ejson) ->
+ (undefined =/= ej:get({<<"raw_data">>}, Ejson) andalso
+ <<"Chef::DataBagItem">> =:= ej:get({<<"json_class">>}, Ejson)).

0 comments on commit a3ec21e

Please sign in to comment.