Skip to content

Commit

Permalink
code review update - minor refactor of process_parts
Browse files Browse the repository at this point in the history
Signed-off-by: Marc Paradise <[email protected]>
  • Loading branch information
Marc Paradise committed Sep 2, 2016
1 parent 9581e0a commit e0c360c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ matrix:
before_script: cd oc-chef-pedant
script: bundle exec rake chef_zero_spec
env:
- "GEMFILE_MOD=\"gem 'rake'; gem 'chef-zero', github: 'chef/chef-zero', branch: 'mp/SPOOL-340' \""
- "GEMFILE_MOD=\"gem 'rake'; gem 'chef-zero', github: 'chef/chef-zero', branch: 'master' \""
# Remove things only used by erlang
install:
after_failure:
Expand All @@ -93,7 +93,7 @@ matrix:
before_script: cd oc-chef-pedant
script: bundle exec rake chef_zero_spec
env:
- "GEMFILE_MOD=\"gem 'rake'; gem 'chef-zero', github: 'chef/chef-zero', branch: 'mp/SPOOL-340' \""
- "GEMFILE_MOD=\"gem 'rake'; gem 'chef-zero', github: 'chef/chef-zero', branch: 'master' \""
- CHEF_FS=1
# Remove things only used by erlang
install:
Expand Down
23 changes: 13 additions & 10 deletions src/oc_erchef/apps/oc_chef_authz/src/oc_chef_authz_acl.erl
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ fetch_cookbook_id(DbContext, Name, OrgId) ->
AuthzId
end.

-spec fetch(chef_type(), id()) -> list() | {error, term()}.
fetch(Type, AuthzId) ->
fetch(Type, AuthzId, undefined).

Expand All @@ -214,7 +215,7 @@ fetch(Type, AuthzId, Granular) ->
Result = oc_chef_authz_http:request(Path, get, ?DEFAULT_HEADERS, [], SuperuserId),
case Result of
{ok, Record} ->
ids_to_names(Record, Granular);
convert_all_ids_to_names(Record, Granular);
{error, forbidden} ->
forbidden;
Other ->
Expand Down Expand Up @@ -334,15 +335,15 @@ convert_actor_ids_to_names(AuthzIds) ->
oc_chef_group:find_users_names(RemainingAuthzIds, fun chef_sql:select_rows/1),
{ClientNames, UserNames, DefunctActorAuthzIds}.

ids_to_names(Record, Granular) ->
Record1 = process_part(<<"create">>, Record, Granular),
Record2 = process_part(<<"read">>, Record1, Granular),
Record3 = process_part(<<"update">>, Record2, Granular),
Record4 = process_part(<<"delete">>, Record3, Granular),
process_part(<<"grant">>, Record4, Granular).

-spec process_part(binary(), ejson_term(), granular|undefined) -> ejson_term().
process_part(Part, Record, Granular) ->
convert_all_ids_to_names(Record, Granular) ->
convert_ids_to_names_in_part([<<"create">>, <<"read">>, <<"update">>, <<"delete">>],
Record, Granular).

-spec convert_ids_to_names_in_part(list(binary()), ejson_term(), granular|undefined) -> ejson_term().
convert_ids_to_names_in_part([], Record, _Granular) ->
Record;
convert_ids_to_names_in_part([Part | Rest], Record, Granular) ->
Members = ej:get({Part}, Record),
ActorIds = ej:get({<<"actors">>}, Members),
GroupIds = ej:get({<<"groups">>}, Members),
Expand All @@ -351,7 +352,9 @@ process_part(Part, Record, Granular) ->
oc_chef_authz_cleanup:add_authz_ids(DefunctActorAuthzIds, DefunctGroupAuthzIds),
Members1 = part_with_actors(Members, ClientNames, UserNames, Granular),
Members2 = ej:set({<<"groups">>}, Members1, GroupNames),
ej:set({Part}, Record, Members2).
NewRecord = ej:set({Part}, Record, Members2),
convert_ids_to_names_in_part(Rest, NewRecord, Granular).


part_with_actors(PartRecord, Clients, Users, granular) ->
PartRecord0 = ej:set({<<"users">>}, PartRecord, Users),
Expand Down
2 changes: 1 addition & 1 deletion src/oc_erchef/rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
{d, 'CHEF_DB_DARKLAUNCH', xdarklaunch_req},
{d, 'CHEF_WM_DARKLAUNCH', xdarklaunch_req},
{parse_transform, lager_transform},
% warnings_as_errors,
warnings_as_errors,
debug_info,
{platform_define, "^[0-9]+", namespaced_types},
{i, "include"},
Expand Down

0 comments on commit e0c360c

Please sign in to comment.