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

Method getAuthHeader

src/uri/fetchers/docker.cpp:1216–1253  ·  view source on GitHub ↗

If a '401 Unauthorized' response is received and the auth-scheme is 'Bearer', we expect a header 'Www-Authenticate' containing the auth server information. We extract the auth server information from the auth-param, and then contacts the auth server to get the token. The token will then be placed in the subsequent HTTP requests as a header. See details here: https://docs.docker.com/registry/spec/

Source from the content-addressed store, hash-verified

1214// See details here:
1215// https://docs.docker.com/registry/spec/auth/token/
1216Future<http::Headers> DockerFetcherPluginProcess::getAuthHeader(
1217 const string& repository,
1218 const URI& uri,
1219 const http::Headers& basicAuthHeaders,
1220 const http::Response& response)
1221{
1222 const auto stallTimeout = this->stallTimeout;
1223
1224 return getAuthServiceUri(repository, uri, response, basicAuthHeaders)
1225 .then([basicAuthHeaders, stallTimeout](const string& authServiceUri) {
1226 return curl(authServiceUri, basicAuthHeaders, stallTimeout)
1227 .then([authServiceUri](const http::Response& response)
1228 -> Future<http::Headers> {
1229 if (response.code != http::Status::OK) {
1230 return Failure(
1231 "Unexpected HTTP response '" + response.status + "' "
1232 "when trying to GET '" + authServiceUri + "'");
1233 }
1234
1235 CHECK_EQ(response.type, http::Response::BODY);
1236
1237 Try<JSON::Object> object = JSON::parse<JSON::Object>(response.body);
1238 if (object.isError()) {
1239 return Failure("Parsing the JSON object failed: " + object.error());
1240 }
1241
1242 Result<JSON::String> token = object->find<JSON::String>("token");
1243 if (token.isError()) {
1244 return Failure(
1245 "Finding token in JSON object failed: " + token.error());
1246 } else if (token.isNone()) {
1247 return Failure("Failed to find token in JSON object");
1248 }
1249
1250 return getAuthHeaderBearer(token->value);
1251 });
1252 });
1253}
1254
1255
1256} // namespace uri {

Callers

nothing calls this directly

Calls 7

curlFunction · 0.85
FailureClass · 0.85
getAuthHeaderBearerFunction · 0.85
errorMethod · 0.65
thenMethod · 0.45
isErrorMethod · 0.45
isNoneMethod · 0.45

Tested by

no test coverage detected