You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ji...@apache.org on 2016/06/13 16:07:30 UTC

[2/9] mesos git commit: Implemented parsing a docker config to a hashmap.

Implemented parsing a docker config to a hashmap.

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


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

Branch: refs/heads/master
Commit: 518ec5b9d928570695076ca69d90b7f6aec563de
Parents: 2c1f414
Author: Gilbert Song <so...@gmail.com>
Authored: Mon Jun 13 09:06:39 2016 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Mon Jun 13 09:06:39 2016 -0700

----------------------------------------------------------------------
 include/mesos/docker/spec.hpp |  8 ++++++++
 src/docker/spec.cpp           | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/518ec5b9/include/mesos/docker/spec.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/docker/spec.hpp b/include/mesos/docker/spec.hpp
index b37c773..854b9ef 100644
--- a/include/mesos/docker/spec.hpp
+++ b/include/mesos/docker/spec.hpp
@@ -76,6 +76,14 @@ Try<std::string> getRegistryScheme(const std::string& registry);
 std::string getRegistryHost(const std::string& registry);
 
 
+/**
+ * Returns the hashmap<registry_URL, spec::DockerConfigAuth> by
+ * parsing the docker config file.
+ */
+Try<hashmap<std::string, Config::Auth>> parseConfig(
+    const JSON::Object& _config);
+
+
 namespace v1 {
 
 /**

http://git-wip-us.apache.org/repos/asf/mesos/blob/518ec5b9/src/docker/spec.cpp
----------------------------------------------------------------------
diff --git a/src/docker/spec.cpp b/src/docker/spec.cpp
index 7270d18..7bcbec5 100644
--- a/src/docker/spec.cpp
+++ b/src/docker/spec.cpp
@@ -145,6 +145,44 @@ string getRegistryHost(const string& registry)
 }
 
 
+Try<hashmap<string, Config::Auth>> parseConfig(
+    const JSON::Object& _config)
+{
+  // This function handles both old and new docker config format,
+  // e.g., '~/.docker/config.json' or '~/.dockercfg'.
+  Result<JSON::Object> auths = _config.find<JSON::Object>("auths");
+  if (auths.isError()) {
+    return Error("Failed to find 'auths' in docker config file: " +
+                 auths.error());
+  }
+
+  const JSON::Object& config = auths.isSome()
+    ? auths.get()
+    : _config;
+
+  hashmap<string, Config::Auth> result;
+
+  foreachpair (const string& key, const JSON::Value& value, config.values) {
+    if (!value.is<JSON::Object>()) {
+      return Error("Invalid JSON object '" + stringify(value) + "'");
+    }
+
+    Try<Config::Auth> auth =
+      protobuf::parse<Config::Auth>(value.as<JSON::Object>());
+
+    if (auth.isError()) {
+      return Error("Protobuf parse failed: " + auth.error());
+    }
+
+    // Assuming no duplicate registry url in docker config file,
+    // if there exists, overwrite it.
+    result[key] = auth.get();
+  }
+
+  return result;
+}
+
+
 namespace v1 {
 
 Option<Error> validate(const ImageManifest& manifest)