You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by gi...@apache.org on 2017/05/24 17:05:46 UTC
[08/10] mesos git commit: Added support for docker spec helper
'parseAuthConfig()'.
Added support for docker spec helper 'parseAuthConfig()'.
Review: https://reviews.apache.org/r/59017
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/4932045b
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/4932045b
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/4932045b
Branch: refs/heads/master
Commit: 4932045ba723debb2573eda76160d9abaadd7534
Parents: efbd436
Author: Gilbert Song <so...@gmail.com>
Authored: Wed May 3 17:40:20 2017 -0700
Committer: Gilbert Song <so...@gmail.com>
Committed: Thu May 25 01:04:30 2017 +0800
----------------------------------------------------------------------
include/mesos/docker/spec.hpp | 7 ++-
src/docker/spec.cpp | 11 ++++
src/tests/containerizer/docker_spec_tests.cpp | 70 ++++++++++------------
3 files changed, 50 insertions(+), 38 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/4932045b/include/mesos/docker/spec.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/docker/spec.hpp b/include/mesos/docker/spec.hpp
index 5ae6345..2879414 100644
--- a/include/mesos/docker/spec.hpp
+++ b/include/mesos/docker/spec.hpp
@@ -73,11 +73,16 @@ std::string getRegistryHost(const std::string& registry);
// Returns the hashmap<registry_URL, spec::DockerConfigAuth> by
-// parsing the docker config file.
+// parsing the docker config file from a JSON object.
Try<hashmap<std::string, Config::Auth>> parseAuthConfig(
const JSON::Object& _config);
+// Returns the hashmap<registry_URL, spec::DockerConfigAuth> by
+// parsing the docker config file from a string.
+Try<hashmap<std::string, Config::Auth>> parseAuthConfig(const std::string& s);
+
+
// Find the host from a docker config auth url.
std::string parseAuthUrl(const std::string& _url);
http://git-wip-us.apache.org/repos/asf/mesos/blob/4932045b/src/docker/spec.cpp
----------------------------------------------------------------------
diff --git a/src/docker/spec.cpp b/src/docker/spec.cpp
index 6b5588e..538cf18 100644
--- a/src/docker/spec.cpp
+++ b/src/docker/spec.cpp
@@ -197,6 +197,17 @@ Try<hashmap<string, Config::Auth>> parseAuthConfig(
}
+Try<hashmap<string, Config::Auth>> parseAuthConfig(const string& s)
+{
+ Try<JSON::Object> json = JSON::parse<JSON::Object>(s);
+ if (json.isError()) {
+ return Error("JSON parse failed: " + json.error());
+ }
+
+ return parseAuthConfig(json.get());
+}
+
+
string parseAuthUrl(const string& _url)
{
string url = _url;
http://git-wip-us.apache.org/repos/asf/mesos/blob/4932045b/src/tests/containerizer/docker_spec_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/docker_spec_tests.cpp b/src/tests/containerizer/docker_spec_tests.cpp
index d812592..5fde49a 100644
--- a/src/tests/containerizer/docker_spec_tests.cpp
+++ b/src/tests/containerizer/docker_spec_tests.cpp
@@ -199,28 +199,26 @@ TEST_F(DockerSpecTest, GetRegistrySpec)
// for new docker config file format (e.g., ~/.docker/config.json).
TEST_F(DockerSpecTest, ParseDockerConfig)
{
- Try<JSON::Object> config = JSON::parse<JSON::Object>(
- R"~(
- {
- "auths": {
- "https://index.docker.io/v1/": {
- "auth": "bWVzb3M6dGVzdA==",
- "email": "user@example.com"
- },
- "localhost:5000": {
- "auth": "dW5pZmllZDpjb250YWluZXJpemVy",
- "email": "user@example.com"
- }
+ string config =
+ R"~(
+ {
+ "auths": {
+ "https://index.docker.io/v1/": {
+ "auth": "bWVzb3M6dGVzdA==",
+ "email": "user@example.com"
},
- "HttpHeaders": {
- "User-Agent": "Docker-Client/1.10.2 (linux)"
+ "localhost:5000": {
+ "auth": "dW5pZmllZDpjb250YWluZXJpemVy",
+ "email": "user@example.com"
}
- })~");
-
- ASSERT_SOME(config);
+ },
+ "HttpHeaders": {
+ "User-Agent": "Docker-Client/1.10.2 (linux)"
+ }
+ })~";
Try<hashmap<string, spec::Config::Auth>> map =
- spec::parseAuthConfig(config.get());
+ spec::parseAuthConfig(config);
EXPECT_EQ("bWVzb3M6dGVzdA==",
map.get()["https://index.docker.io/v1/"].auth());
@@ -237,27 +235,25 @@ TEST_F(DockerSpecTest, ParseDockerConfig)
// for old docker config file format (e.g., ~/.dockercfg).
TEST_F(DockerSpecTest, ParseDockercfg)
{
- Try<JSON::Object> dockercfg = JSON::parse<JSON::Object>(
- R"~(
- {
- "quay.io": {
- "auth": "cXVheTp0ZXN0",
- "email": "user@example.com"
- },
- "https://index.docker.io/v1/": {
- "auth": "cHJpdmF0ZTpyZWdpc3RyeQ==",
- "email": "user@example.com"
- },
- "https://192.168.0.1:5050": {
- "auth": "aXA6YWRkcmVzcw==",
- "email": "user@example.com"
- }
- })~");
-
- ASSERT_SOME(dockercfg);
+ string dockercfg =
+ R"~(
+ {
+ "quay.io": {
+ "auth": "cXVheTp0ZXN0",
+ "email": "user@example.com"
+ },
+ "https://index.docker.io/v1/": {
+ "auth": "cHJpdmF0ZTpyZWdpc3RyeQ==",
+ "email": "user@example.com"
+ },
+ "https://192.168.0.1:5050": {
+ "auth": "aXA6YWRkcmVzcw==",
+ "email": "user@example.com"
+ }
+ })~";
Try<hashmap<string, spec::Config::Auth>> map =
- spec::parseAuthConfig(dockercfg.get());
+ spec::parseAuthConfig(dockercfg);
EXPECT_EQ("cXVheTp0ZXN0", map.get()["quay.io"].auth());
EXPECT_EQ("user@example.com", map.get()["quay.io"].email());