You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by vi...@apache.org on 2016/06/30 20:23:34 UTC
[2/2] mesos git commit: Added support for VIEW_FLAGS authorization
action in HTTP API.
Added support for VIEW_FLAGS authorization action in HTTP API.
Adds an intermediate function `Master::http::_flags()` which performs
authorization and it is called by both the endpoint `/flags` handler
and the HTTP API v1 call `getFlags()` handler.
Review: https://reviews.apache.org/r/49394/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/b6b617a0
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/b6b617a0
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/b6b617a0
Branch: refs/heads/master
Commit: b6b617a01bfc0821da830a57f5a9fb3725fddeb4
Parents: f35f606
Author: Alexander Rojas <al...@mesosphere.io>
Authored: Thu Jun 30 13:20:49 2016 -0700
Committer: Vinod Kone <vi...@gmail.com>
Committed: Thu Jun 30 13:22:50 2016 -0700
----------------------------------------------------------------------
src/master/http.cpp | 79 +++++++++++++++++++++++++++++++++++++++-------
src/master/master.hpp | 7 +++-
2 files changed, 74 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/b6b617a0/src/master/http.cpp
----------------------------------------------------------------------
diff --git a/src/master/http.cpp b/src/master/http.cpp
index 759e051..d5f4e77 100644
--- a/src/master/http.cpp
+++ b/src/master/http.cpp
@@ -45,6 +45,7 @@
#include <process/metrics/metrics.hpp>
#include <stout/base64.hpp>
+#include <stout/errorbase.hpp>
#include <stout/foreach.hpp>
#include <stout/hashmap.hpp>
#include <stout/hashset.hpp>
@@ -1450,6 +1451,26 @@ Future<Response> Master::Http::getFrameworks(
}
+class Master::Http::FlagsError : public Error
+{
+public:
+ enum Type
+ {
+ UNAUTHORIZED
+ };
+
+ // TODO(arojas): Provide a proper string representation of the enum.
+ explicit FlagsError(Type _type)
+ : Error(stringify(_type)), type(_type) {}
+
+ FlagsError(Type _type, const std::string& _message)
+ : Error(stringify(_type)), type(_type), message(_message) {}
+
+ const Type type;
+ const std::string message;
+};
+
+
string Master::Http::FLAGS_HELP()
{
return HELP(
@@ -1473,8 +1494,30 @@ Future<Response> Master::Http::flags(
return MethodNotAllowed({"GET"}, request.method);
}
+ Option<string> jsonp = request.url.query.get("jsonp");
+
+ return _flags(principal)
+ .then([jsonp](const Try<JSON::Object, FlagsError>& flags)
+ -> Future<Response> {
+ if (flags.isError()) {
+ switch (flags.error().type) {
+ case FlagsError::Type::UNAUTHORIZED:
+ return Forbidden();
+ }
+
+ return InternalServerError(flags.error().message);
+ }
+
+ return OK(flags.get(), jsonp);
+ });
+}
+
+
+Future<Try<JSON::Object, Master::Http::FlagsError>> Master::Http::_flags(
+ const Option<string>& principal) const
+{
if (master->authorizer.isNone()) {
- return OK(_flags(), request.url.query.get("jsonp"));
+ return __flags();
}
authorization::Request authRequest;
@@ -1487,17 +1530,17 @@ Future<Response> Master::Http::flags(
return master->authorizer.get()->authorized(authRequest)
.then(defer(
master->self(),
- [this, request](bool authorized) -> Future<Response> {
- if (authorized) {
- return OK(_flags(), request.url.query.get("jsonp"));
- } else {
- return Forbidden();
- }
- }));
+ [this](bool authorized) -> Future<Try<JSON::Object, FlagsError>> {
+ if (authorized) {
+ return __flags();
+ } else {
+ return FlagsError(FlagsError::Type::UNAUTHORIZED);
+ }
+ }));
}
-JSON::Object Master::Http::_flags() const
+JSON::Object Master::Http::__flags() const
{
JSON::Object object;
@@ -1523,9 +1566,23 @@ Future<Response> Master::Http::getFlags(
{
CHECK_EQ(mesos::master::Call::GET_FLAGS, call.type());
- return OK(serialize(contentType,
- evolve<v1::master::Response::GET_FLAGS>(_flags())),
+ return _flags(principal)
+ .then([contentType](const Try<JSON::Object, FlagsError>& flags)
+ -> Future<Response> {
+ if (flags.isError()) {
+ switch (flags.error().type) {
+ case FlagsError::Type::UNAUTHORIZED:
+ return Forbidden();
+ }
+
+ return InternalServerError(flags.error().message);
+ }
+
+ return OK(
+ serialize(contentType,
+ evolve<v1::master::Response::GET_FLAGS>(flags.get())),
stringify(contentType));
+ });
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/b6b617a0/src/master/master.hpp
----------------------------------------------------------------------
diff --git a/src/master/master.hpp b/src/master/master.hpp
index e2ab211..7388a3e 100644
--- a/src/master/master.hpp
+++ b/src/master/master.hpp
@@ -1301,7 +1301,12 @@ private:
static std::string WEIGHTS_HELP();
private:
- JSON::Object _flags() const;
+ JSON::Object __flags() const;
+
+ class FlagsError; // Forward declaration.
+
+ process::Future<Try<JSON::Object, FlagsError>> _flags(
+ const Option<std::string>& principal) const;
process::Future<std::vector<const Task*>> _tasks(
const size_t limit,