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/04/15 23:00:03 UTC

[7/9] mesos git commit: Added basic authentication scheme to the scheduler library.

Added basic authentication scheme to the scheduler library.

This change adds basic scheme AuthN support to the library.
It would be good to add support for additional schemes in the
future.

Review: https://reviews.apache.org/r/46116/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/e7f03a20
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/e7f03a20
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/e7f03a20

Branch: refs/heads/master
Commit: e7f03a201a39ddb9d6de7fd0a85f32d1d8cbb464
Parents: a080650
Author: Anand Mazumdar <ma...@gmail.com>
Authored: Fri Apr 15 15:59:33 2016 -0500
Committer: Vinod Kone <vi...@gmail.com>
Committed: Fri Apr 15 15:59:33 2016 -0500

----------------------------------------------------------------------
 include/mesos/v1/scheduler.hpp |  6 +++++-
 src/scheduler/scheduler.cpp    | 24 ++++++++++++++++++++++--
 2 files changed, 27 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/e7f03a20/include/mesos/v1/scheduler.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/v1/scheduler.hpp b/include/mesos/v1/scheduler.hpp
index 6603075..18e7a95 100644
--- a/include/mesos/v1/scheduler.hpp
+++ b/include/mesos/v1/scheduler.hpp
@@ -54,11 +54,14 @@ class MesosProcess; // Forward declaration.
 class Mesos
 {
 public:
+  // The credential will be used for authenticating with the master. Currently,
+  // only HTTP basic authentication is supported.
   Mesos(const std::string& master,
         ContentType contentType,
         const std::function<void()>& connected,
         const std::function<void()>& disconnected,
-        const std::function<void(const std::queue<Event>&)>& received);
+        const std::function<void(const std::queue<Event>&)>& received,
+        const Option<Credential>& credential);
 
   // Delete copy constructor.
   Mesos(const Mesos& other) = delete;
@@ -101,6 +104,7 @@ protected:
       const std::function<void()>& connected,
       const std::function<void()>& disconnected,
       const std::function<void(const std::queue<Event>&)>& received,
+      const Option<Credential>& credential,
       const Option<std::shared_ptr<mesos::master::detector::MasterDetector>>&
         detector);
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/e7f03a20/src/scheduler/scheduler.cpp
----------------------------------------------------------------------
diff --git a/src/scheduler/scheduler.cpp b/src/scheduler/scheduler.cpp
index f9d54f9..c75e02c 100644
--- a/src/scheduler/scheduler.cpp
+++ b/src/scheduler/scheduler.cpp
@@ -130,11 +130,13 @@ public:
       const lambda::function<void()>& connected,
       const lambda::function<void()>& disconnected,
       const lambda::function<void(const queue<Event>&)>& received,
+      const Option<Credential>& _credential,
       const Option<shared_ptr<MasterDetector>>& _detector)
     : ProcessBase(ID::generate("scheduler")),
       state(DISCONNECTED),
       contentType(_contentType),
       callbacks {connected, disconnected, received},
+      credential(_credential),
       local(false)
   {
     GOOGLE_PROTOBUF_VERIFY_VERSION;
@@ -245,6 +247,14 @@ public:
     request.headers = {{"Accept", stringify(contentType)},
                        {"Content-Type", stringify(contentType)}};
 
+    // TODO(anand): Add support for other authentication schemes.
+
+    if (credential.isSome()) {
+      request.headers["Authorization"] =
+        "Basic " +
+        base64::encode(credential->principal() + ":" + credential->secret());
+    }
+
     CHECK_SOME(connections);
 
     Future<Response> response;
@@ -719,6 +729,7 @@ private:
   Option<SubscribedResponse> subscribed;
   ContentType contentType;
   Callbacks callbacks;
+  const Option<Credential> credential;
   Mutex mutex; // Used to serialize the callback invocations.
   bool local; // Whether or not we launched a local cluster.
   shared_ptr<MasterDetector> detector;
@@ -737,6 +748,7 @@ Mesos::Mesos(
     const lambda::function<void()>& connected,
     const lambda::function<void()>& disconnected,
     const lambda::function<void(const queue<Event>&)>& received,
+    const Option<Credential>& credential,
     const Option<shared_ptr<MasterDetector>>& detector)
 {
   process = new MesosProcess(
@@ -745,6 +757,7 @@ Mesos::Mesos(
       connected,
       disconnected,
       received,
+      credential,
       detector);
 
   spawn(process);
@@ -756,8 +769,15 @@ Mesos::Mesos(
     ContentType contentType,
     const lambda::function<void()>& connected,
     const lambda::function<void()>& disconnected,
-    const lambda::function<void(const queue<Event>&)>& received)
-  : Mesos(master, contentType, connected, disconnected, received, None()) {}
+    const lambda::function<void(const queue<Event>&)>& received,
+    const Option<Credential>& credential)
+  : Mesos(master,
+          contentType,
+          connected,
+          disconnected,
+          received,
+          credential,
+          None()) {}
 
 
 Mesos::~Mesos()