| 2149 | |
| 2150 | |
| 2151 | pair<Response, Option<Master::ReadOnlyHandler::PostProcessing>> |
| 2152 | Master::ReadOnlyHandler::getOperations( |
| 2153 | ContentType outputContentType, |
| 2154 | const hashmap<std::string, std::string>& query, |
| 2155 | const process::Owned<ObjectApprovers>& approvers) const |
| 2156 | { |
| 2157 | // We consider a principal to be authorized to view an operation if it |
| 2158 | // is authorized to view the resources the operation is performed on. |
| 2159 | auto approved = [&approvers](const Operation& operation) { |
| 2160 | Try<Resources> consumedResources = |
| 2161 | protobuf::getConsumedResources(operation.info()); |
| 2162 | |
| 2163 | if (consumedResources.isError()) { |
| 2164 | LOG(WARNING) |
| 2165 | << "Could not approve operation " << operation.uuid() |
| 2166 | << " since its consumed resources could not be determined:" |
| 2167 | << consumedResources.error(); |
| 2168 | |
| 2169 | return false; |
| 2170 | } |
| 2171 | |
| 2172 | foreach (const Resource& resource, consumedResources.get()) { |
| 2173 | if (!approvers->approved<VIEW_ROLE>(resource)) { |
| 2174 | return false; |
| 2175 | } |
| 2176 | } |
| 2177 | |
| 2178 | return true; |
| 2179 | }; |
| 2180 | |
| 2181 | mesos::master::Response response; |
| 2182 | response.set_type(mesos::master::Response::GET_OPERATIONS); |
| 2183 | |
| 2184 | mesos::master::Response::GetOperations* operations = |
| 2185 | response.mutable_get_operations(); |
| 2186 | |
| 2187 | foreachvalue (const Slave* slave, master->slaves.registered) { |
| 2188 | foreachvalue (const Operation* operation, slave->operations) { |
| 2189 | if (approved(*operation)) { |
| 2190 | operations->add_operations()->CopyFrom(*operation); |
| 2191 | } |
| 2192 | } |
| 2193 | |
| 2194 | foreachvalue ( |
| 2195 | const Slave::ResourceProvider& resourceProvider, |
| 2196 | slave->resourceProviders) { |
| 2197 | foreachvalue (const Operation* operation, resourceProvider.operations) { |
| 2198 | if (approved(*operation)) { |
| 2199 | operations->add_operations()->CopyFrom(*operation); |
| 2200 | } |
| 2201 | } |
| 2202 | } |
| 2203 | } |
| 2204 | |
| 2205 | return pair<Response, Option<Master::ReadOnlyHandler::PostProcessing>>( |
| 2206 | OK(serialize(outputContentType, evolve(response)), |
| 2207 | stringify(outputContentType)), |
| 2208 | None()); |