Apache Mesos
files.hpp
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef __FILES_HPP__
18 #define __FILES_HPP__
19 
20 #include <string>
21 
23 
24 #include <process/future.hpp>
25 #include <process/http.hpp>
26 
27 #include <stout/format.hpp>
28 #include <stout/json.hpp>
29 #include <stout/nothing.hpp>
30 #include <stout/path.hpp>
31 
33 
34 #include "mesos/mesos.hpp"
35 
36 namespace mesos {
37 namespace internal {
38 
39 // Forward declarations.
40 class FilesProcess;
41 
42 
43 // Represents the various errors that can be returned by methods on the `Files`
44 // class via a `Try` that has failed.
45 class FilesError : public Error
46 {
47 public:
48  enum Type
49  {
50  INVALID, // Invalid argument.
51  NOT_FOUND, // Not found.
52  UNAUTHORIZED, // Not authorized to perform the operation.
53  UNKNOWN // Internal error/all other errors.
54  };
55 
57  : Error(stringify(_type)), type(_type) {}
58 
59  FilesError(Type _type, const std::string& _message)
60  : Error(stringify(_type)), type(_type), message(_message) {}
61 
63  std::string message;
64 };
65 
66 
67 // Provides an abstraction for browsing and reading files via HTTP
68 // endpoints. A path (file or directory) may be "attached" to a virtual path
69 // (similar to "mounting" a device) for subsequent browsing and
70 // reading of any files and directories it contains. The "mounting" of
71 // paths to virtual paths enables us to do a form of chrooting for better
72 // security and isolation of files.
73 class Files
74 {
75 public:
76  Files(const Option<std::string>& authenticationRealm = None(),
77  const Option<mesos::Authorizer*>& authorizer = None());
78  ~Files();
79 
80  // Returns the result of trying to attach the specified path
81  // (directory or file) at the specified virtual path.
83  const std::string& path,
84  const std::string& virtualPath,
85  const Option<lambda::function<process::Future<bool>(
87  authorized = None());
88 
89  // Removes the specified virtual path.
90  void detach(const std::string& virtualPath);
91 
92  // Returns a file listing for a directory similar to `ls -l`.
94  const std::string& path,
96 
97  // Returns the size and data of file.
99  const size_t offset,
100  const Option<size_t>& length,
101  const std::string& path,
103 
104 private:
105  FilesProcess* process;
106 };
107 
108 } // namespace internal {
109 } // namespace mesos {
110 
111 #endif // __FILES_HPP__
Definition: path.hpp:29
Definition: errorbase.hpp:36
Type
Definition: files.hpp:48
Definition: files.hpp:45
Definition: files.hpp:73
std::string message
Definition: files.hpp:63
Type type
Definition: files.hpp:62
Definition: agent.hpp:25
Try< Nothing > attach(const Netlink< struct rtnl_cls > &cls, const action::Redirect &redirect)
Definition: internal.hpp:100
Definition: files.hpp:53
Result< Process > process(pid_t pid)
Definition: freebsd.hpp:30
Definition: none.hpp:27
Definition: attributes.hpp:24
Result< Credentials > read(const Path &path)
Definition: credentials.hpp:35
FilesError(Type _type)
Definition: files.hpp:56
Definition: files.hpp:50
std::string stringify(int flags)
FilesError(Type _type, const std::string &_message)
Definition: files.hpp:59