This is an automated email from the ASF dual-hosted git repository. asekretenko pushed a commit to branch 1.8.x in repository https://gitbox.apache.org/repos/asf/mesos.git
commit 21a89ffa3b448c86547a1882c55e1bb954b068f7 Author: Andrei Sekretenko <[email protected]> AuthorDate: Thu Jan 30 12:39:31 2020 +0100 Factored out common code for building URIs on a registry host. This is a prerequisite for adding fallback authorization server URI generation (see MESOS-10092) in the next patches, which will need one more URI extractor similar to `getManifestUri()`/`getBlobUri()`. Review: https://reviews.apache.org/r/72077 --- src/uri/fetchers/docker.cpp | 61 +++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/src/uri/fetchers/docker.cpp b/src/uri/fetchers/docker.cpp index 0ca980c..5fb0e93 100644 --- a/src/uri/fetchers/docker.cpp +++ b/src/uri/fetchers/docker.cpp @@ -438,6 +438,35 @@ static http::Headers getAuthHeaderBearer( return headers; } + +static URI constructRegistryUri(const URI& imageUri, string&& path) +{ + const string scheme = imageUri.has_fragment() ? imageUri.fragment() : "https"; + return uri::construct( + scheme, + std::move(path), + imageUri.host(), + (imageUri.has_port() ? Option<int>(imageUri.port()) : None())); +} + + +static URI getManifestUri(const URI& imageUri) +{ + return constructRegistryUri( + imageUri, + strings::join( + "/", "/v2", imageUri.path(), "manifests", imageUri.query())); +} + + +static URI getBlobUri(const URI& imageUri) +{ + return constructRegistryUri( + imageUri, + strings::join("/", "/v2", imageUri.path(), "blobs", imageUri.query())); +} + + //------------------------------------------------------------------- // DockerFetcherPlugin implementation. //------------------------------------------------------------------- @@ -510,9 +539,6 @@ private: const http::Headers& basicAuthHeaders, const http::Response& response); - URI getManifestUri(const URI& uri); - URI getBlobUri(const URI& uri); - // This is a lookup table for credentials in docker config file, // keyed by registry URL. // For example, "https://index.docker.io/v1/" -> spec::Config::Auth @@ -1130,34 +1156,5 @@ Future<http::Headers> DockerFetcherPluginProcess::getAuthHeader( } -URI DockerFetcherPluginProcess::getManifestUri(const URI& uri) -{ - string scheme = "https"; - if (uri.has_fragment()) { - scheme = uri.fragment(); - } - - return uri::construct( - scheme, - strings::join("/", "/v2", uri.path(), "manifests", uri.query()), - uri.host(), - (uri.has_port() ? Option<int>(uri.port()) : None())); -} - - -URI DockerFetcherPluginProcess::getBlobUri(const URI& uri) -{ - string scheme = "https"; - if (uri.has_fragment()) { - scheme = uri.fragment(); - } - - return uri::construct( - scheme, - strings::join("/", "/v2", uri.path(), "blobs", uri.query()), - uri.host(), - (uri.has_port() ? Option<int>(uri.port()) : None())); -} - } // namespace uri { } // namespace mesos {
