Interpret parameters given in command line.
(string_list=None)
| 354 | |
| 355 | |
| 356 | def process_command_line(string_list=None): |
| 357 | """Interpret parameters given in command line.""" |
| 358 | |
| 359 | parser = parser_factory() |
| 360 | |
| 361 | args = parser.parse_args(args=string_list) |
| 362 | |
| 363 | if args.api_resource[0] not in constants.ALLOWS_FILTER: |
| 364 | if args.first_published or args.last_published: |
| 365 | parser.error( |
| 366 | 'Only {} based filter can have additional first_published or' |
| 367 | ' last_published filter'.format(constants.ALLOWS_FILTER)) |
| 368 | |
| 369 | if args.api_resource[0] not in constants.SUPPORTED_PLATFORMS_ALIAS: |
| 370 | if args.platformAlias: |
| 371 | parser.error( |
| 372 | 'Only {} based filter can have additional platformAlias filter' |
| 373 | .format(constants.SUPPORTED_PLATFORMS_ALIAS)) |
| 374 | |
| 375 | if args.api_resource[0] in constants.NON_ADVISORY_QUERY: |
| 376 | if args.count or args.fields: |
| 377 | parser.error( |
| 378 | '{} do not support fields or count options'.format(constants.NON_ADVISORY_QUERY)) |
| 379 | |
| 380 | if args.api_resource[0] == "OS": |
| 381 | if args.api_resource[1] not in constants.SUPPORTED_PLATFORMS_VERSION: |
| 382 | parser.error( |
| 383 | 'Only network operating system types for OS type query are: {}'.format(constants.SUPPORTED_PLATFORMS_VERSION)) |
| 384 | elif args.api_resource[0] == "platform": |
| 385 | if args.api_resource[1] not in constants.SUPPORTED_PLATFORMS_ALIAS: |
| 386 | parser.error( |
| 387 | 'Only network operating system types for platform type query are: {}'.format(constants.SUPPORTED_PLATFORMS_ALIAS)) |
| 388 | |
| 389 | if not args.json_config_path: |
| 390 | # Try next environment variables are set, then config.py, or fail: |
| 391 | keys_required = ('CLIENT_ID', 'CLIENT_SECRET') |
| 392 | env_config = {k: os.getenv(k, None) for k in keys_required} |
| 393 | |
| 394 | if all([v for v in env_config.values()]): # OK, take env values: |
| 395 | for key in keys_required: |
| 396 | setattr(config, key, env_config[key]) |
| 397 | elif all([getattr(config, k, None) for k in keys_required]): |
| 398 | pass # Fallback to the credentials in config.py (non-empty!) |
| 399 | else: |
| 400 | parser.error( |
| 401 | ' --conf <FILE> ? Missing configuration file (credentials)') |
| 402 | else: |
| 403 | if not os.path.isfile(args.json_config_path): |
| 404 | parser.error( |
| 405 | 'Configuration file not found at %s' % args.json_config_path) |
| 406 | else: |
| 407 | parsed_config = json.load(open(args.json_config_path)) |
| 408 | keys_required = ('CLIENT_ID', 'CLIENT_SECRET') |
| 409 | for key in keys_required: |
| 410 | setattr(config, key, parsed_config[key]) |
| 411 | keys_optional = ('REQUEST_TOKEN_URL', 'API_URL') |
| 412 | for key in keys_optional: |
| 413 | if key in parsed_config: |
nothing calls this directly
no test coverage detected