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 2017/03/06 20:40:43 UTC

[07/14] mesos git commit: Updated 'Files' handlers to use the 'Principal' type.

Updated 'Files' handlers to use the 'Principal' type.

This patch updates the HTTP endpoint handlers in the
Mesos `Files` process to accept the `Principal` type
instead of an `Option<string>& principal`.

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


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

Branch: refs/heads/master
Commit: a7a84a87ff4fef8e3062b72bf795fa9540ab5325
Parents: dc20257
Author: Greg Mann <gr...@mesosphere.io>
Authored: Mon Mar 6 12:39:25 2017 -0800
Committer: Vinod Kone <vi...@gmail.com>
Committed: Mon Mar 6 12:39:25 2017 -0800

----------------------------------------------------------------------
 src/files/files.cpp | 46 +++++++++++++++++++++++++---------------------
 src/files/files.hpp |  8 ++++----
 2 files changed, 29 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/a7a84a87/src/files/files.cpp
----------------------------------------------------------------------
diff --git a/src/files/files.cpp b/src/files/files.cpp
index 8327f80..f066146 100644
--- a/src/files/files.cpp
+++ b/src/files/files.cpp
@@ -83,6 +83,8 @@ using process::Process;
 using process::TLDR;
 using process::wait; // Necessary on some OS's to disambiguate.
 
+using process::http::authentication::Principal;
+
 using std::list;
 using std::map;
 using std::string;
@@ -102,20 +104,20 @@ public:
   Future<Nothing> attach(
       const string& path,
       const string& name,
-      const Option<lambda::function<Future<bool>(const Option<string>&)>>&
-          authorized);
+      const Option<lambda::function<Future<bool>(
+          const Option<Principal>&)>>& authorized);
 
   void detach(const string& name);
 
   Future<Try<list<FileInfo>, FilesError>> browse(
       const string& path,
-      const Option<string>& principal);
+      const Option<Principal>& principal);
 
   Future<Try<tuple<size_t, string>, FilesError>> read(
       const size_t offset,
       const Option<size_t>& length,
       const string& path,
-      const Option<string>& principal);
+      const Option<Principal>& principal);
 
 protected:
   virtual void initialize();
@@ -128,7 +130,9 @@ private:
   // out of the chroot.
   Result<string> resolve(const string& path);
 
-  Future<bool> authorize(string requestedPath, const Option<string>& principal);
+  Future<bool> authorize(
+      string requestedPath,
+      const Option<Principal>& principal);
 
   // HTTP endpoints.
 
@@ -139,7 +143,7 @@ private:
   // in the path (see `FileInfo` model override for the format).
   Future<http::Response> _browse(
       const http::Request& request,
-      const Option<string>& principal);
+      const Option<Principal>& principal);
 
   // Continuation of `read()`.
   Future<Try<tuple<size_t, string>, FilesError>> _read(
@@ -151,21 +155,21 @@ private:
   // See the jquery pailer for the expected behavior.
   Future<http::Response> __read(
       const http::Request& request,
-      const Option<string>& principal);
+      const Option<Principal>& principal);
 
   // Returns the raw file contents for a given path.
   // Requests have the following parameters:
   //   path: The directory to browse. Required.
   Future<http::Response> download(
       const http::Request& request,
-      const Option<string>& principal);
+      const Option<Principal>& principal);
 
   Future<http::Response> _download(const string& path);
 
   // Returns the internal virtual path mapping.
   Future<http::Response> debug(
       const http::Request& request,
-      const Option<string>& principal);
+      const Option<Principal>& principal);
 
   const static string BROWSE_HELP;
   const static string READ_HELP;
@@ -177,7 +181,7 @@ private:
   // Set of authorization functions. They will be called whenever
   // access to the path used as key is requested, and will pass
   // as parameter the principal returned by the HTTP authenticator.
-  hashmap<string, lambda::function<Future<bool>(const Option<string>&)>>
+  hashmap<string, lambda::function<Future<bool>(const Option<Principal>&)>>
       authorizations;
 
   // The authentication realm, if any, into which this process'
@@ -271,7 +275,7 @@ void FilesProcess::initialize()
 Future<Nothing> FilesProcess::attach(
     const string& path,
     const string& name,
-    const Option<lambda::function<Future<bool>(const Option<string>&)>>&
+    const Option<lambda::function<Future<bool>(const Option<Principal>&)>>&
         authorized)
 {
   Result<string> result = os::realpath(path);
@@ -337,7 +341,7 @@ const string FilesProcess::BROWSE_HELP = HELP(
 
 Future<bool> FilesProcess::authorize(
     string requestedPath,
-    const Option<string>& principal)
+    const Option<Principal>& principal)
 {
   // The path may contain a trailing forward slash. Since we store the
   // authorization callbacks without the trailing slash, we must remove it here,
@@ -363,7 +367,7 @@ Future<bool> FilesProcess::authorize(
 
 Future<http::Response> FilesProcess::_browse(
     const http::Request& request,
-    const Option<string>& principal)
+    const Option<Principal>& principal)
 {
   Option<string> path = request.url.query.get("path");
 
@@ -409,7 +413,7 @@ Future<http::Response> FilesProcess::_browse(
 
 Future<Try<list<FileInfo>, FilesError>> FilesProcess::browse(
     const string& path,
-    const Option<string>& principal)
+    const Option<Principal>& principal)
 {
   return authorize(path, principal)
     .then(defer(self(),
@@ -484,7 +488,7 @@ const string FilesProcess::READ_HELP = HELP(
 
 Future<http::Response> FilesProcess::__read(
     const http::Request& request,
-    const Option<string>& principal)
+    const Option<Principal>& principal)
 {
   Option<string> path = request.url.query.get("path");
 
@@ -584,7 +588,7 @@ Future<Try<tuple<size_t, string>, FilesError>> FilesProcess::read(
     const size_t offset,
     const Option<size_t>& length,
     const string& path,
-    const Option<string>& principal)
+    const Option<Principal>& principal)
 {
   return authorize(path, principal)
     .then(defer(self(),
@@ -719,7 +723,7 @@ const string FilesProcess::DOWNLOAD_HELP = HELP(
 
 Future<http::Response> FilesProcess::download(
     const http::Request& request,
-    const Option<string>& principal)
+    const Option<Principal>& principal)
 {
   Option<string> path = request.url.query.get("path");
 
@@ -790,7 +794,7 @@ const string FilesProcess::DEBUG_HELP = HELP(
 
 Future<http::Response> FilesProcess::debug(
     const http::Request& request,
-    const Option<string>&  principal )
+    const Option<Principal>& principal)
 {
   JSON::Object object;
   foreachpair (const string& name, const string& path, paths) {
@@ -902,7 +906,7 @@ Files::~Files()
 Future<Nothing> Files::attach(
     const string& path,
     const string& name,
-    const Option<lambda::function<Future<bool>(const Option<string>&)>>&
+    const Option<lambda::function<Future<bool>(const Option<Principal>&)>>&
         authorized)
 {
   return dispatch(process, &FilesProcess::attach, path, name, authorized);
@@ -917,7 +921,7 @@ void Files::detach(const string& name)
 
 Future<Try<list<FileInfo>, FilesError>> Files::browse(
     const string& path,
-    const Option<string>& principal)
+    const Option<Principal>& principal)
 {
   return dispatch(process, &FilesProcess::browse, path, principal);
 }
@@ -927,7 +931,7 @@ Future<Try<tuple<size_t, string>, FilesError>> Files::read(
     const size_t offset,
     const Option<size_t>& length,
     const string& path,
-    const Option<string>& principal)
+    const Option<Principal>& principal)
 {
   return dispatch(process,
                   &FilesProcess::read,

http://git-wip-us.apache.org/repos/asf/mesos/blob/a7a84a87/src/files/files.hpp
----------------------------------------------------------------------
diff --git a/src/files/files.hpp b/src/files/files.hpp
index 8cffc26..1e123fa 100644
--- a/src/files/files.hpp
+++ b/src/files/files.hpp
@@ -82,8 +82,8 @@ public:
   process::Future<Nothing> attach(
       const std::string& path,
       const std::string& name,
-      const Option<lambda::function<
-          process::Future<bool>(const Option<std::string>&)>>&
+      const Option<lambda::function<process::Future<bool>(
+          const Option<process::http::authentication::Principal>&)>>&
               authorized = None());
 
   // Removes the specified name.
@@ -92,14 +92,14 @@ public:
   // Returns a file listing for a directory similar to `ls -l`.
   process::Future<Try<std::list<FileInfo>, FilesError>> browse(
       const std::string& path,
-      const Option<std::string>& principal);
+      const Option<process::http::authentication::Principal>& principal);
 
   // Returns the size and data of file.
   process::Future<Try<std::tuple<size_t, std::string>, FilesError>> read(
       const size_t offset,
       const Option<size_t>& length,
       const std::string& path,
-      const Option<std::string>& principal);
+      const Option<process::http::authentication::Principal>& principal);
 
 private:
   FilesProcess* process;