| 166 | hashmap<string, CSIPluginInfo> pluginConfigs; |
| 167 | |
| 168 | foreach (const string& entry, entries.get()) { |
| 169 | const string path = path::join(pluginConfigDir, entry); |
| 170 | |
| 171 | // Ignore directory entries. |
| 172 | if (os::stat::isdir(path)) { |
| 173 | continue; |
| 174 | } |
| 175 | |
| 176 | Try<string> read = os::read(path); |
| 177 | if (read.isError()) { |
| 178 | // In case of an error we log and skip to the next entry. |
| 179 | LOG(ERROR) << "Failed to read CSI plugin configuration file '" |
| 180 | << path << "': " << read.error(); |
| 181 | |
| 182 | continue; |
| 183 | } |
| 184 | |
| 185 | Try<JSON::Object> json = JSON::parse<JSON::Object>(read.get()); |
| 186 | if (json.isError()) { |
| 187 | return Error("JSON parse of '" + path + "' failed: " + json.error()); |
| 188 | } |
| 189 | |
| 190 | Try<CSIPluginInfo> parse = ::protobuf::parse<CSIPluginInfo>(json.get()); |
| 191 | if (parse.isError()) { |
| 192 | return Error("Protobuf parse of '" + path + "' failed: " + parse.error()); |
| 193 | } |
| 194 | |
| 195 | const CSIPluginInfo& csiPluginConfig = parse.get(); |
| 196 | const string& type = csiPluginConfig.type(); |
| 197 | |
| 198 | if (pluginConfigs.contains(type)) { |
| 199 | LOG(ERROR) << "Multiple configurations for a CSI plugin are not allowed. " |
| 200 | << "Skipping configuration file '" << path << "' since CSI " |
| 201 | << "plugin '" << type << "' already exists"; |
| 202 | continue; |
| 203 | } |
| 204 | |
| 205 | if (name.isNone() || name.get() == type) { |
| 206 | pluginConfigs[type] = csiPluginConfig; |
| 207 | |
| 208 | if (name.isSome()) { |
| 209 | break; |
| 210 | } |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | if (pluginConfigs.empty()) { |
| 215 | return Error( |
nothing calls this directly
no test coverage detected