Anonymous avatar Anonymous committed 77f15bb

expose ability to set bucket_mod over HTTP

PUT /jiak/BucketName
Content-type: application/json

{"bucket_mod":"jiak_example"}

Warning: it is not possible to un-set the bucket_mod property. This means that it's not possible to revert to PUTting {"allowed_method":..."required_method":...} schemas after you have defined a bucket as using a specific erlang module as its "bucket_mod".

Comments (0)

Files changed (1)

src/jiak_resource.erl

         {ok, _SchemaObj={struct, SchemaPL0}} ->
             ReqProps = [list_to_binary(atom_to_list(P)) || 
                            P <- jiak_util:jiak_required_props()],
-            {struct, SchemaPL} = proplists:get_value(<<"schema">>,SchemaPL0),
-            case lists:filter(
-                   fun(I) -> 
-                           proplists:get_value(I, SchemaPL) =:= undefined
-                   end, 
-                   ReqProps) of
-                [] ->
-                    {false, ReqData, Context#ctx{incoming=SchemaPL}};
-                L ->
-                    {true, 
-                     wrq:append_to_response_body(
-                     io_lib:format("missing required schema fields: ~p~n",[L]),
-                       ReqData),
-                     Context}
+            case proplists:get_value(<<"schema">>,SchemaPL0) of
+                {struct, SchemaPL} ->
+                    case lists:filter(
+                           fun(I) -> 
+                                   proplists:get_value(I, SchemaPL) =:= undefined
+                           end, 
+                           ReqProps) of
+                        [] ->
+                            {false, ReqData, Context#ctx{incoming=SchemaPL}};
+                        L ->
+                            {true, 
+                             wrq:append_to_response_body(
+                               io_lib:format("missing required schema fields: ~p~n",[L]),
+                               ReqData),
+                             Context}
+                    end;
+                undefined ->
+                    case proplists:get_value(<<"bucket_mod">>, SchemaPL0) of
+                        BMStr when is_binary(BMStr) ->
+                            case catch list_to_existing_atom(binary_to_list(BMStr)) of
+                                BM when is_atom(BM) ->
+                                    {false, ReqData,
+                                     Context#ctx{incoming=[{<<"bucket_mod">>, BM}]}};
+                                _ ->
+                                    {true,
+                                     wrq:append_to_response_body(
+                                       io_lib:format("no module '~s' found", [BMStr]),
+                                       ReqData),
+                                     Context}
+                            end;
+                        undefined ->
+                            {true, 
+                             wrq:append_to_response_body(
+                               io_lib:format("missing required schema fields: ~p~n",
+                                             [ReqProps]),
+                               ReqData),
+                             Context}
+                    end
             end;
         Err ->
             {true,
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.