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 2014/05/15 02:08:23 UTC
git commit: Fixed credentials::read() to properly stat the
credentials file.
Repository: mesos
Updated Branches:
refs/heads/master 187c7689d -> 6987a9e05
Fixed credentials::read() to properly stat the credentials file.
Review: https://reviews.apache.org/r/21445
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/6987a9e0
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/6987a9e0
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/6987a9e0
Branch: refs/heads/master
Commit: 6987a9e05993adfdca72aa883ed1940857a1868b
Parents: 187c768
Author: Vinod Kone <vi...@twitter.com>
Authored: Tue May 13 23:10:10 2014 -0700
Committer: Vinod Kone <vi...@twitter.com>
Committed: Wed May 14 17:07:59 2014 -0700
----------------------------------------------------------------------
src/credentials/credentials.hpp | 5 ++---
src/master/master.cpp | 4 +++-
src/slave/slave.cpp | 7 +++++--
src/tests/mesos.cpp | 24 +++++++++++++++++++++---
4 files changed, 31 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/6987a9e0/src/credentials/credentials.hpp
----------------------------------------------------------------------
diff --git a/src/credentials/credentials.hpp b/src/credentials/credentials.hpp
index de0e7e6..98b9088 100644
--- a/src/credentials/credentials.hpp
+++ b/src/credentials/credentials.hpp
@@ -32,10 +32,9 @@ namespace credentials {
inline Result<std::vector<Credential> > read(const std::string& path)
{
- LOG(INFO) << "Loading credentials for authentication";
+ LOG(INFO) << "Loading credentials for authentication from '" << path << "'";
- Try<std::string> read = os::read(
- strings::remove(path, "file://", strings::PREFIX));
+ Try<std::string> read = os::read(path);
if (read.isError()) {
return Error("Failed to read credentials file '" + path +
"': " + read.error());
http://git-wip-us.apache.org/repos/asf/mesos/blob/6987a9e0/src/master/master.cpp
----------------------------------------------------------------------
diff --git a/src/master/master.cpp b/src/master/master.cpp
index d97b377..63b6cdc 100644
--- a/src/master/master.cpp
+++ b/src/master/master.cpp
@@ -315,7 +315,9 @@ void Master::initialize()
// Load credentials.
if (flags.credentials.isSome()) {
- const string& path = flags.credentials.get();
+ const string& path =
+ strings::remove(flags.credentials.get(), "file://", strings::PREFIX);
+
Result<vector<Credential> > credentials = credentials::read(path);
if (credentials.isError()) {
EXIT(1) << credentials.error() << " (see --credentials flag)";
http://git-wip-us.apache.org/repos/asf/mesos/blob/6987a9e0/src/slave/slave.cpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.cpp b/src/slave/slave.cpp
index f8ed65b..4a8adf0 100644
--- a/src/slave/slave.cpp
+++ b/src/slave/slave.cpp
@@ -220,12 +220,15 @@ void Slave::initialize()
#endif // __linux__
if (flags.credential.isSome()) {
- const string& path = flags.credential.get();
+ const string& path =
+ strings::remove(flags.credential.get(), "file://", strings::PREFIX);
+
Result<vector<Credential> > credentials = credentials::read(path);
if (credentials.isError()) {
EXIT(1) << credentials.error() << " (see --credential flag)";
} else if (credentials.isNone()) {
- EXIT(1) << "Empty credential file " << path << " (see --credential flag)";
+ EXIT(1) << "Empty credential file '" << path
+ << "' (see --credential flag)";
} else if (credentials.get().size() != 1) {
EXIT(1) << "Not expecting multiple credentials (see --credential flag)";
} else {
http://git-wip-us.apache.org/repos/asf/mesos/blob/6987a9e0/src/tests/mesos.cpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.cpp b/src/tests/mesos.cpp
index 242d98a..7f59b72 100644
--- a/src/tests/mesos.cpp
+++ b/src/tests/mesos.cpp
@@ -78,14 +78,23 @@ master::Flags MesosTest::CreateMasterFlags()
flags.authenticate_slaves = true;
// Create a default credentials file.
- const string& path = path::join(os::getcwd(), "credentials");
+ const string& path = path::join(os::getcwd(), "credentials");
+
+ Try<int> fd = os::open(
+ path,
+ O_WRONLY | O_CREAT | O_TRUNC,
+ S_IRUSR | S_IWUSR | S_IRGRP);
+
+ CHECK_SOME(fd);
const string& credentials =
DEFAULT_CREDENTIAL.principal() + " " + DEFAULT_CREDENTIAL.secret();
- CHECK_SOME(os::write(path, credentials))
+ CHECK_SOME(os::write(fd.get(), credentials))
<< "Failed to write credentials to '" << path << "'";
+ CHECK_SOME(os::close(fd.get()));
+
flags.credentials = "file://" + path;
// Use the replicated log (without ZooKeeper) by default.
@@ -111,12 +120,21 @@ slave::Flags MesosTest::CreateSlaveFlags()
// Create a default credential file.
const string& path = path::join(directory.get(), "credential");
+ Try<int> fd = os::open(
+ path,
+ O_WRONLY | O_CREAT | O_TRUNC,
+ S_IRUSR | S_IWUSR | S_IRGRP);
+
+ CHECK_SOME(fd);
+
const string& credential =
DEFAULT_CREDENTIAL.principal() + " " + DEFAULT_CREDENTIAL.secret();
- CHECK_SOME(os::write(path, credential))
+ CHECK_SOME(os::write(fd.get(), credential))
<< "Failed to write slave credential to '" << path << "'";
+ CHECK_SOME(os::close(fd.get()));
+
flags.credential = "file://" + path;
// TODO(vinod): Consider making this true and fixing the tests.