MCPcopy Create free account
hub / github.com/apache/mesos / __fetch

Method __fetch

src/uri/fetchers/docker.cpp:834–948  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

832
833
834Future<Nothing> DockerFetcherPluginProcess::__fetch(
835 const URI& uri,
836 const string& directory,
837 const http::Headers& authHeaders,
838 const http::Response& response)
839{
840 if (response.code != http::Status::OK) {
841 return Failure(
842 "Unexpected HTTP response '" + response.status + "' "
843 "when trying to get the manifest");
844 }
845
846 CHECK_EQ(response.type, http::Response::BODY);
847
848 Option<string> contentType = response.headers.get("Content-Type");
849 if (contentType.isNone()) {
850 return Failure("No Content-Type present");
851 }
852
853 // NOTE: Docker supports the following five media types.
854 //
855 // V2 schema 1 manifest:
856 // 1. application/vnd.docker.distribution.manifest.v1+json
857 // 2. application/vnd.docker.distribution.manifest.v1+prettyjws
858 // 3. application/json
859 //
860 // For more details, see:
861 // https://docs.docker.com/registry/spec/manifest-v2-1/
862 //
863 // V2 schema 2 manifest:
864 // 1. application/vnd.docker.distribution.manifest.v2+json
865 // 2. application/vnd.docker.distribution.manifest.list.v2+json
866 // (manifest list is not supported yet)
867 //
868 // For more details, see:
869 // https://docs.docker.com/registry/spec/manifest-v2-2/
870 bool isV2Schema1 =
871 strings::startsWith(
872 contentType.get(),
873 "application/vnd.docker.distribution.manifest.v1") ||
874 strings::startsWith(
875 contentType.get(),
876 "application/json");
877
878 // TODO(gilbert): Support manifest list (fat manifest) in V2 Schema2.
879 bool isV2Schema2 =
880 contentType.get() == "application/vnd.docker.distribution.manifest.v2+json";
881
882 if (isV2Schema1) {
883 // Parse V2 schema 1 image manifest.
884 Try<spec::v2::ImageManifest> manifest = spec::v2::parse(response.body);
885 if (manifest.isError()) {
886 return Failure(
887 "Failed to parse the V2 Schema 1 image manifest: " +
888 manifest.error());
889 }
890
891 // Save manifest to 'directory'.

Callers

nothing calls this directly

Calls 12

FailureClass · 0.85
startsWithFunction · 0.85
NothingClass · 0.85
insertMethod · 0.80
errorMethod · 0.65
parseFunction · 0.50
writeFunction · 0.50
joinFunction · 0.50
getMethod · 0.45
isNoneMethod · 0.45
isErrorMethod · 0.45
schemeMethod · 0.45

Tested by

no test coverage detected