| 160 | |
| 161 | |
| 162 | Try<hashmap<string, Config::Auth>> parseAuthConfig( |
| 163 | const JSON::Object& _config) |
| 164 | { |
| 165 | // This function handles both old and new docker config format, |
| 166 | // e.g., '~/.docker/config.json' or '~/.dockercfg'. |
| 167 | Result<JSON::Object> auths = _config.find<JSON::Object>("auths"); |
| 168 | if (auths.isError()) { |
| 169 | return Error("Failed to find 'auths' in docker config file: " + |
| 170 | auths.error()); |
| 171 | } |
| 172 | |
| 173 | const JSON::Object& config = auths.isSome() |
| 174 | ? auths.get() |
| 175 | : _config; |
| 176 | |
| 177 | hashmap<string, Config::Auth> result; |
| 178 | |
| 179 | foreachpair (const string& key, const JSON::Value& value, config.values) { |
| 180 | if (!value.is<JSON::Object>()) { |
| 181 | return Error("Invalid JSON object '" + stringify(value) + "'"); |
| 182 | } |
| 183 | |
| 184 | Try<Config::Auth> auth = |
| 185 | protobuf::parse<Config::Auth>(value.as<JSON::Object>()); |
| 186 | |
| 187 | if (auth.isError()) { |
| 188 | return Error("Protobuf parse failed: " + auth.error()); |
| 189 | } |
| 190 | |
| 191 | // Assuming no duplicate registry url in docker config file, |
| 192 | // if there exists, overwrite it. |
| 193 | result[key] = auth.get(); |
| 194 | } |
| 195 | |
| 196 | return result; |
| 197 | } |
| 198 | |
| 199 | |
| 200 | Try<hashmap<string, Config::Auth>> parseAuthConfig(const string& s) |