* @brief a helper function which loads the entry-point to region from files. * @param args classname + filename in ' : ' format. * @return true if successful, false otherwise. */
| 82 | * @return true if successful, false otherwise. |
| 83 | */ |
| 84 | static bool |
| 85 | loadRegionMap(StringMap &m, const String &filename) |
| 86 | { |
| 87 | static const char *EXPECTED_FORMAT = "<s3-entry-point>:<s3-region>"; |
| 88 | |
| 89 | String path(makeConfigPath(filename)); |
| 90 | |
| 91 | std::ifstream ifstr; |
| 92 | String line; |
| 93 | |
| 94 | ifstr.open(path.c_str()); |
| 95 | if (!ifstr) { |
| 96 | TSError("[%s] failed to load s3-region map from '%s'", PLUGIN_NAME, path.c_str()); |
| 97 | return false; |
| 98 | } |
| 99 | |
| 100 | Dbg(dbg_ctl, "loading region mapping from '%s'", path.c_str()); |
| 101 | |
| 102 | m[""] = ""; /* set a default just in case if the user does not specify it */ |
| 103 | |
| 104 | while (std::getline(ifstr, line)) { |
| 105 | String::size_type pos; |
| 106 | |
| 107 | // Allow #-prefixed comments. |
| 108 | pos = line.find_first_of('#'); |
| 109 | if (pos != String::npos) { |
| 110 | line.resize(pos); |
| 111 | } |
| 112 | |
| 113 | if (line.empty()) { |
| 114 | continue; |
| 115 | } |
| 116 | |
| 117 | std::size_t d = line.find(':'); |
| 118 | if (String::npos == d) { |
| 119 | TSError("[%s] failed to parse region map string '%s', expected format: '%s'", PLUGIN_NAME, line.c_str(), EXPECTED_FORMAT); |
| 120 | return false; |
| 121 | } |
| 122 | |
| 123 | String entrypoint(trimWhiteSpaces(String(line, 0, d))); |
| 124 | String region(trimWhiteSpaces(String(line, d + 1, String::npos))); |
| 125 | |
| 126 | if (region.empty()) { |
| 127 | Dbg(dbg_ctl, "<s3-region> in '%s' cannot be empty (skipped), expected format: '%s'", line.c_str(), EXPECTED_FORMAT); |
| 128 | continue; |
| 129 | } |
| 130 | |
| 131 | if (entrypoint.empty()) { |
| 132 | Dbg(dbg_ctl, "added default region %s", region.c_str()); |
| 133 | } else { |
| 134 | Dbg(dbg_ctl, "added entry-point:%s, region:%s", entrypoint.c_str(), region.c_str()); |
| 135 | } |
| 136 | |
| 137 | m[entrypoint] = region; |
| 138 | } |
| 139 | |
| 140 | if (m.at("").empty()) { |
| 141 | Dbg(dbg_ctl, "default region was not defined"); |
no test coverage detected