Removed digest from Manifest struct in registry client.

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


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

Branch: refs/heads/master
Commit: b5cb9306b200ce2c1d861f3c48c8efb74bfbf2b9
Parents: df7dd72
Author: Jojy Varghese <[email protected]>
Authored: Thu Nov 5 21:12:14 2015 -0800
Committer: Timothy Chen <[email protected]>
Committed: Thu Nov 5 22:28:06 2015 -0800

----------------------------------------------------------------------
 .../provisioner/docker/registry_client.cpp      | 32 +++++++-------------
 .../provisioner/docker/registry_client.hpp      |  6 ++--
 2 files changed, 15 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/b5cb9306/src/slave/containerizer/mesos/provisioner/docker/registry_client.cpp
----------------------------------------------------------------------
diff --git 
a/src/slave/containerizer/mesos/provisioner/docker/registry_client.cpp 
b/src/slave/containerizer/mesos/provisioner/docker/registry_client.cpp
index a8497f9..19d7f16 100644
--- a/src/slave/containerizer/mesos/provisioner/docker/registry_client.cpp
+++ b/src/slave/containerizer/mesos/provisioner/docker/registry_client.cpp
@@ -104,8 +104,6 @@ private:
       const http::Response& httpResponse,
       const Option<http::Headers>& headers);
 
-  Try<Manifest> getManifestResponse(const http::Response& httpResponse);
-
   const http::URL registryServer_;
   Owned<TokenManager> tokenManager_;
   const Option<Credentials> credentials_;
@@ -464,34 +462,28 @@ Future<http::Response> RegistryClientProcess::doHttpGet(
 }
 
 
-Try<Manifest> RegistryClientProcess::getManifestResponse(
-    const http::Response& httpResponse)
+Try<Manifest> Manifest::create(const string& jsonString)
 {
-    if (!httpResponse.headers.contains("Docker-Content-Digest")) {
-      return Error("Docker-Content-Digest header missing in response");
-    }
-
-    Try<JSON::Object> responseJSON =
-      JSON::parse<JSON::Object>(httpResponse.body);
+    Try<JSON::Object> manifestJSON = JSON::parse<JSON::Object>(jsonString);
 
-    if (responseJSON.isError()) {
-      return Error(responseJSON.error());
+    if (manifestJSON.isError()) {
+      return Error(manifestJSON.error());
     }
 
-    Result<JSON::String> name = responseJSON.get().find<JSON::String>("name");
+    Result<JSON::String> name = manifestJSON.get().find<JSON::String>("name");
     if (name.isNone()) {
       return Error("Failed to find \"name\" in manifest response");
     }
 
     Result<JSON::Array> fsLayersJSON =
-      responseJSON.get().find<JSON::Array>("fsLayers");
+      manifestJSON.get().find<JSON::Array>("fsLayers");
 
     if (fsLayersJSON.isNone()) {
       return Error("Failed to find \"fsLayers\" in manifest response");
     }
 
     Result<JSON::Array> historyArray =
-      responseJSON.get().find<JSON::Array>("history");
+      manifestJSON.get().find<JSON::Array>("history");
 
     if (historyArray.isNone()) {
       return Error("Failed to find \"history\" in manifest response");
@@ -571,11 +563,7 @@ Try<Manifest> RegistryClientProcess::getManifestResponse(
           });
     }
 
-    return Manifest {
-      name.get().value,
-      httpResponse.headers.at("Docker-Content-Digest"),
-      fsLayers
-    };
+    return Manifest{name.get().value, fsLayers};
 }
 
 
@@ -589,8 +577,10 @@ Future<Manifest> RegistryClientProcess::getManifest(
   return doHttpGet(manifestURL, None(), true, None())
     .then(defer(self(), [this] (
         const http::Response& response) -> Future<Manifest> {
-      Try<Manifest> manifest = getManifestResponse(response);
+      // TODO(jojy): We dont use the digest that is returned in header.
+      // This is a good place to validate the manifest.
 
+      Try<Manifest> manifest = Manifest::create(response.body);
       if (manifest.isError()) {
         return Failure(
             "Failed to parse manifest response: " + manifest.error());

http://git-wip-us.apache.org/repos/asf/mesos/blob/b5cb9306/src/slave/containerizer/mesos/provisioner/docker/registry_client.hpp
----------------------------------------------------------------------
diff --git 
a/src/slave/containerizer/mesos/provisioner/docker/registry_client.hpp 
b/src/slave/containerizer/mesos/provisioner/docker/registry_client.hpp
index 9760ed8..bc487d3 100644
--- a/src/slave/containerizer/mesos/provisioner/docker/registry_client.hpp
+++ b/src/slave/containerizer/mesos/provisioner/docker/registry_client.hpp
@@ -58,12 +58,14 @@ struct FileSystemLayerInfo
 /**
  * Response for a "GET Manifest" request.
  *
- * Reference: https://docs.docker.com/registry/spec/api
+ * Reference:
+ * 
https://github.com/docker/distribution/blob/master/docs/spec/manifest-v2-1.md
  */
 struct Manifest
 {
+  static Try<Manifest> create(const std::string& jsonString);
+
   const std::string name;
-  const std::string digest;
   const std::vector<FileSystemLayerInfo> fsLayerInfos;
 };
 

Reply via email to