Apache Mesos
spec.hpp
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef __MESOS_DOCKER_SPEC_HPP__
18 #define __MESOS_DOCKER_SPEC_HPP__
19 
20 #include <iostream>
21 #include <string>
22 
23 #include <stout/error.hpp>
24 #include <stout/json.hpp>
25 #include <stout/option.hpp>
26 #include <stout/try.hpp>
27 
28 // ONLY USEFUL AFTER RUNNING PROTOC.
29 #include <mesos/docker/spec.pb.h>
30 
31 #include <mesos/docker/v1.hpp>
32 #include <mesos/docker/v2.hpp>
33 #include <mesos/docker/v2_2.hpp>
34 
35 namespace docker {
36 namespace spec {
37 
38 // The prefix of whiteout files in a docker image.
39 constexpr char WHITEOUT_PREFIX[] = ".wh.";
40 
41 
42 // The prefix of opaque whiteout files in a docker image.
43 constexpr char WHITEOUT_OPAQUE_PREFIX[] = ".wh..wh..opq";
44 
45 
46 // Parse the docker image reference. Docker expects the image
47 // reference to be in the following format:
48 // [REGISTRY_HOST[:REGISTRY_PORT]/]REPOSITORY[:TAG|@TYPE:DIGEST]
49 //
50 // This format is inherently ambiguous when dealing with repository
51 // names that include forward slashes. To disambiguate, the docker
52 // code looks for '.', or ':', or 'localhost' to decide if the first
53 // component is a registry or a repository name. For more detail,
54 // drill into the implementation of docker pull.
55 //
56 // See docker implementation:
57 // https://github.com/docker/distribution/blob/master/reference/reference.go
58 Try<ImageReference> parseImageReference(const std::string& s);
59 
60 
61 std::ostream& operator<<(std::ostream& stream, const ImageReference& reference);
62 
63 
64 // Returns the port of a docker registry.
65 Result<int> getRegistryPort(const std::string& registry);
66 
67 
68 // Returns the scheme of a docker registry.
69 Try<std::string> getRegistryScheme(const std::string& registry);
70 
71 
72 // Returns the host of a docker registry.
73 std::string getRegistryHost(const std::string& registry);
74 
75 
76 // Returns the hashmap<registry_URL, spec::DockerConfigAuth> by
77 // parsing the docker config file from a JSON object.
79  const JSON::Object& _config);
80 
81 
82 // Returns the hashmap<registry_URL, spec::DockerConfigAuth> by
83 // parsing the docker config file from a string.
85 
86 
87 // Find the host from a docker config auth url.
88 std::string parseAuthUrl(const std::string& _url);
89 
90 
91 namespace v1 {
92 
93 // Validates if the specified docker v1 image manifest conforms to the
94 // Docker v1 spec. Returns the error if the validation fails.
95 Option<Error> validate(const ImageManifest& manifest);
96 
97 
98 // Returns the docker v1 image manifest from the given JSON object.
100 
101 
102 // Returns the docker v1 image manifest from the given string.
103 Try<ImageManifest> parse(const std::string& s);
104 
105 } // namespace v1 {
106 
107 
108 namespace v2 {
109 
110 // Validates if the specified v2 image manifest conforms to the Docker
111 // v2 spec. Returns the error if the validation fails.
112 Option<Error> validate(const ImageManifest& manifest);
113 
114 
115 // Returns the docker v2 image manifest from the given JSON object.
117 
118 
119 // Returns the docker v2 image manifest from the given string.
120 Try<ImageManifest> parse(const std::string& s);
121 
122 } // namespace v2 {
123 
124 
125 namespace v2_2 {
126 
127 // Validates if the specified docker v2 s2 image manifest conforms to the
128 // Docker v2 s2 spec. Returns the error if the validation fails.
129 Option<Error> validate(const ImageManifest& manifest);
130 
131 
132 // Returns the docker v2 s2 image manifest from the given JSON object.
134 
135 
136 // Returns the docker v2 s2 image manifest from the given string.
137 Try<ImageManifest> parse(const std::string& s);
138 
139 } // namespace v2_2 {
140 } // namespace spec {
141 } // namespace docker {
142 
143 #endif // __MESOS_DOCKER_SPEC_HPP__
std::string getRegistryHost(const std::string &registry)
std::string parseAuthUrl(const std::string &_url)
Try< ImageReference > parseImageReference(const std::string &s)
constexpr char WHITEOUT_PREFIX[]
Definition: spec.hpp:39
Definition: check.hpp:33
Try< hashmap< std::string, Config::Auth > > parseAuthConfig(const JSON::Object &_config)
std::ostream & operator<<(std::ostream &stream, const ImageReference &reference)
Option< Error > validate(const ImageManifest &manifest)
constexpr char WHITEOUT_OPAQUE_PREFIX[]
Definition: spec.hpp:43
URI manifest(const std::string &repository, const std::string &reference, const std::string &registry, const Option< std::string > &scheme=None(), const Option< int > &port=None())
Definition: docker.hpp:47
Result< int > getRegistryPort(const std::string &registry)
Definition: check.hpp:30
Definition: json.hpp:158
void json(JSON::ObjectWriter *writer, const asV1Protobuf &protobuf)
Try< std::string > getRegistryScheme(const std::string &registry)
Try< ImageManifest > parse(const JSON::Object &json)
Definition: spec.hpp:35