(self, params, **kwargs)
| 351 | return rotate_parser |
| 352 | |
| 353 | def execute(self, params, **kwargs): |
| 354 | print_result = kwargs['print'] if 'print' in kwargs else None |
| 355 | name = kwargs['name'] if 'name' in kwargs else None |
| 356 | match = kwargs['match'] if 'match' in kwargs else None |
| 357 | force = kwargs['force'] if 'force' in kwargs else None |
| 358 | if name: |
| 359 | record_uid = None |
| 360 | rotate_name = None |
| 361 | if name in params.record_cache: |
| 362 | record_uid = name |
| 363 | else: |
| 364 | RecordRotateCommand.find_endpoints(params) |
| 365 | nl = name.lower() |
| 366 | endpoints = [ |
| 367 | x for x in RecordRotateCommand.Endpoints if x.record_title.lower() == nl or x.name.lower() == nl |
| 368 | ] |
| 369 | if len(endpoints) > 0: |
| 370 | if len(endpoints) == 1: |
| 371 | record_uid = endpoints[0].record_uid |
| 372 | rotate_name = endpoints[0].name |
| 373 | else: |
| 374 | logging.error('There are more than one rotation records with name %s. Please use record UID.', name) |
| 375 | return |
| 376 | if record_uid: |
| 377 | rotate_password( |
| 378 | params, record_uid, rotate_name=rotate_name, plugin_name=kwargs.get('plugin'), |
| 379 | host=kwargs.get('host'), port=kwargs.get('port'), rules=kwargs.get('rules'), |
| 380 | length=kwargs.get('length'), new_password=kwargs.get('password') |
| 381 | ) |
| 382 | if print_result: |
| 383 | record = api.get_record(params, record_uid) |
| 384 | record.display() |
| 385 | else: |
| 386 | logging.error('Rotate {0}: not found'.format(name)) |
| 387 | elif match: |
| 388 | results = api.search_records(params, match) |
| 389 | for r in results: |
| 390 | if r.version not in (2, 3): |
| 391 | continue |
| 392 | if force or confirm(f'Rotate password for record {r.title}?'): |
| 393 | rotate_password( |
| 394 | params, r.record_uid, plugin_name=kwargs.get('plugin'), new_password=kwargs.get('password'), |
| 395 | host=kwargs.get('host'), port=kwargs.get('port'), rules=kwargs.get('rules') |
| 396 | ) |
| 397 | if print_result: |
| 398 | record = api.get_record(params, r.record_uid) |
| 399 | record.display() |
| 400 | else: |
| 401 | RecordRotateCommand.find_endpoints(params) |
| 402 | if RecordRotateCommand.Endpoints: |
| 403 | logging.info("Available records for password rotation") |
| 404 | logging.info('') |
| 405 | headers = ["#", 'Name', 'Type', 'Record UID', 'Record Title', 'Folder(s)'] |
| 406 | table = [] |
| 407 | for i in range(len(RecordRotateCommand.Endpoints)): |
| 408 | endpoint = RecordRotateCommand.Endpoints[i] |
| 409 | title = endpoint.record_title |
| 410 | folder = endpoint.paths[0] if len(endpoint.paths) > 0 else '/' |
no test coverage detected