| 1202 | |
| 1203 | |
| 1204 | Future<Owned<ObjectApprovers>> ObjectApprovers::create( |
| 1205 | const Option<Authorizer*>& authorizer, |
| 1206 | const Option<Principal>& principal, |
| 1207 | std::initializer_list<authorization::Action> actions) |
| 1208 | { |
| 1209 | // Ensures there are no repeated elements. |
| 1210 | // Note: `set` is necessary because we relay in the order of the elements |
| 1211 | // while doing `zip` below. |
| 1212 | set<authorization::Action> _actions(actions); |
| 1213 | |
| 1214 | Option<authorization::Subject> subject = |
| 1215 | authorization::createSubject(principal); |
| 1216 | |
| 1217 | if (authorizer.isNone()) { |
| 1218 | hashmap<authorization::Action, shared_ptr<const ObjectApprover>> approvers; |
| 1219 | |
| 1220 | foreach (authorization::Action action, _actions) { |
| 1221 | approvers.put(action, std::make_shared<AcceptingObjectApprover>()); |
| 1222 | } |
| 1223 | |
| 1224 | return Owned<ObjectApprovers>( |
| 1225 | new ObjectApprovers(std::move(approvers), principal)); |
| 1226 | } |
| 1227 | |
| 1228 | return process::collect(lambda::map<vector>( |
| 1229 | [&](authorization::Action action) { |
| 1230 | return authorizer.get()->getApprover(subject, action); |
| 1231 | }, |
| 1232 | _actions)) |
| 1233 | .then([=](const vector<shared_ptr<const ObjectApprover>>& _approvers) { |
| 1234 | return Owned<ObjectApprovers>( |
| 1235 | new ObjectApprovers(lambda::zip(_actions, _approvers), principal)); |
| 1236 | }); |
| 1237 | } |
| 1238 | |
| 1239 | |
| 1240 | process::Future<bool> authorizeEndpoint( |
no test coverage detected