41
41
#include " sql.hpp"
42
42
#include " generated_group_load.hpp"
43
43
#include " thresholds.hpp"
44
+ #include " print_cache.hpp"
44
45
45
46
namespace po = boost::program_options;
46
47
namespace filesystem = std::experimental::filesystem;
47
48
49
+ // TODO: Add the rest of the options names here
50
+ namespace options {
51
+ const char * CACHE_FILE = " cache-file" ;
52
+
53
+ const char * USER_BLACKLIST_FILE = " user-blacklist-file" ;
54
+ const char * USER_BLACKLIST_ATTRIBUTE = " user-blacklist-attribute" ;
55
+
56
+ const char * PRINT_CACHE = " print-cache" ;
57
+ const char * PRINT_CACHE_BY_ENDPOINT = " print-cache-by-endpoint" ;
58
+ const char * PRINT_CACHE_TYPE = " print-cache-type" ;
59
+ const char * PRINT_CACHE_WHERE = " print-cache-where" ;
60
+ }
61
+
48
62
void print_usage (const std::string& program_name,
49
63
const po::options_description& options) {
50
64
std::cout << " Usage: " << program_name << " [OPTIONS] <config-file>\n\n " ;
@@ -103,23 +117,6 @@ void write_status(const std::string& file,
103
117
of << " }" << std::endl;
104
118
}
105
119
106
- /* *
107
- * Splits a string with format "variable=value" into its parts.
108
- * Used on the command line for overriding config file variables.
109
- */
110
- void parse_override (const std::string& override_str,
111
- std::string& variable,
112
- std::string& value) {
113
- auto pos = override_str.find (' =' );
114
-
115
- if (pos == std::string::npos) {
116
- throw std::runtime_error (" Malformed variable override (" + override_str + " )" );
117
- }
118
-
119
- variable = override_str.substr (0 , pos);
120
- value = override_str.substr (pos+1 );
121
- }
122
-
123
120
/* *
124
121
* Modifies a set of objects so they will be considered different from what's in the data source,
125
122
* used by --force-update.
@@ -150,7 +147,7 @@ void make_dirty(std::shared_ptr<rendered_object_list> objects, const std::vector
150
147
* parameter will let the caller know if there was a cache file or not.
151
148
*/
152
149
std::shared_ptr<rendered_object_list> read_cache (const post_processing::plugins& ppp, bool *cache_file_existed) {
153
- auto cache_path = config_file::instance ().get_path (" cache-file " );
150
+ auto cache_path = config_file::instance ().get_path (options::CACHE_FILE );
154
151
155
152
if (cache_path.empty ()) {
156
153
return nullptr ;
@@ -187,30 +184,26 @@ std::shared_ptr<rendered_object_list> read_cache(const post_processing::plugins&
187
184
return rendered_cache;
188
185
}
189
186
190
- // TODO: Add the rest of the options names here
191
- namespace options {
192
- const char * USER_BLACKLIST_FILE = " user-blacklist-file" ;
193
- const char * USER_BLACKLIST_ATTRIBUTE = " user-blacklist-attribute" ;
194
- }
195
-
196
187
int main (int argc, char *argv[]) {
197
188
try {
198
189
po::options_description cmdline_options (" All options" );
199
190
po::options_description generic (" Options" );
200
191
po::options_description hidden (" Hidden options" );
201
192
202
193
generic.add_options ()
203
- (" help,h" , " produce help message" )
204
- (" version,v" , " displays version of this program" )
205
- (" rebuild-cache,r" , " ignores cache file contents and instead queries SCIM server for list of objects" )
206
- (" skip-load" , " don't read from data source, causes delete for all objects in cache" )
207
- (" skip-thresholds" , " don't verify thresholds" );
194
+ (" help,h" , " produce help message" )
195
+ (" version,v" , " displays version of this program" )
196
+ (" rebuild-cache,r" , " ignores cache file contents and instead queries SCIM server for list of objects" )
197
+ (" skip-load" , " don't read from data source, causes delete for all objects in cache" )
198
+ (" skip-thresholds" , " don't verify thresholds" )
199
+ (options::PRINT_CACHE, " prints contents of cache file (see --print-cache-type and --print-cache-where)" )
200
+ (options::PRINT_CACHE_BY_ENDPOINT, " uses the SCIM endpoints instead of EGIL types when printing the cache file" );
208
201
209
202
// Config file variables exposed as command line options
210
203
std::vector<config_file_option> common_vars =
211
204
{ { " cert" , " client certificate" , true },
212
205
{ " key" , " client private key" , true },
213
- { " cache-file " , " cache file" , true },
206
+ { options::CACHE_FILE, " cache file" , true },
214
207
{ " metadata-path" , " metadata file" , true },
215
208
{ " metadata-entity" , " entity in metadata to connect to" , false },
216
209
{ " metadata-server" ,
@@ -240,6 +233,10 @@ int main(int argc, char *argv[]) {
240
233
generic.add_options ()
241
234
(options::USER_BLACKLIST_FILE, po::value<std::string>(), " a file of users which shall be blocked from loading" )
242
235
(options::USER_BLACKLIST_ATTRIBUTE, po::value<std::string>(), " attribute (in the data source) to match against user blacklist file" );
236
+
237
+ generic.add_options ()
238
+ (options::PRINT_CACHE_TYPE, po::value<std::vector<std::string>>(), " only print given type(s)" )
239
+ (options::PRINT_CACHE_WHERE, po::value<std::vector<std::string>>(), " only print objects where attributes match given values" );
243
240
244
241
hidden.add_options ()
245
242
(" config-file" , po::value<std::vector<std::string>>(), " config file" );
@@ -273,7 +270,7 @@ int main(int argc, char *argv[]) {
273
270
std::cerr << e.what () << std::endl;
274
271
return EXIT_FAILURE;
275
272
}
276
-
273
+
277
274
config_file &config = config_file::instance ();
278
275
279
276
std::string config_file;
@@ -287,8 +284,6 @@ int main(int argc, char *argv[]) {
287
284
}
288
285
289
286
/* * Load configuration file */
290
- std::cout << " processing: " << config_file << std::endl;
291
-
292
287
time_t start_time = time (nullptr );
293
288
294
289
int err = 0 ;
@@ -324,6 +319,34 @@ int main(int argc, char *argv[]) {
324
319
}
325
320
}
326
321
322
+ if (vm.count (options::PRINT_CACHE)) {
323
+ bool by_endpoint = vm.count (options::PRINT_CACHE_BY_ENDPOINT);
324
+ auto cache_path = config_file::instance ().get_path (options::CACHE_FILE);
325
+
326
+ std::shared_ptr<rendered_object_list> cache;
327
+ try {
328
+ cache = rendered_cache_file::get_contents (cache_path);
329
+ }
330
+ catch (const rendered_cache_file::bad_format &) {
331
+ std::cerr << " Unrecognized cache file format" << std::endl;
332
+ return EXIT_FAILURE;
333
+ }
334
+ catch (const std::runtime_error &e) {
335
+ std::cerr << " Failed to read cache file: " << e.what () << std::endl;
336
+ return EXIT_FAILURE;
337
+ }
338
+
339
+ std::vector<std::string> types, where;
340
+ if (vm.count (options::PRINT_CACHE_TYPE)) {
341
+ types = vm[options::PRINT_CACHE_TYPE].as <std::vector<std::string>>();
342
+ }
343
+ if (vm.count (options::PRINT_CACHE_WHERE)) {
344
+ where = vm[options::PRINT_CACHE_WHERE].as <std::vector<std::string>>();
345
+ }
346
+ print_cache (cache, by_endpoint, types, where);
347
+ return EXIT_SUCCESS;
348
+ }
349
+
327
350
add_scim_vars_for_virtual_groups ();
328
351
329
352
if (config.get_bool (" scim-auth-WEAK" )) {
0 commit comments