| Conditions | 51 |
| Total Lines | 365 |
| Code Lines | 308 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 2652 |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like ssg.build_profile.XCCDFBenchmark.show_profile_stats() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | from __future__ import absolute_import |
||
| 406 | def show_profile_stats(self, profile, options): |
||
| 407 | """Displays statistics for specific profile""" |
||
| 408 | |||
| 409 | profile_stats = self.get_profile_stats(profile) |
||
| 410 | rules_count = profile_stats['rules_count'] |
||
| 411 | impl_ovals_count = len(profile_stats['implemented_ovals']) |
||
| 412 | impl_sces_count = len(profile_stats['implemented_sces']) |
||
| 413 | impl_checks_count = len(profile_stats['implemented_checks']) |
||
| 414 | impl_bash_fixes_count = len(profile_stats['implemented_bash_fixes']) |
||
| 415 | impl_ansible_fixes_count = len(profile_stats['implemented_ansible_fixes']) |
||
| 416 | impl_ignition_fixes_count = len(profile_stats['implemented_ignition_fixes']) |
||
| 417 | impl_kubernetes_fixes_count = len(profile_stats['implemented_kubernetes_fixes']) |
||
| 418 | impl_puppet_fixes_count = len(profile_stats['implemented_puppet_fixes']) |
||
| 419 | impl_anaconda_fixes_count = len(profile_stats['implemented_anaconda_fixes']) |
||
| 420 | impl_fixes_count = len(profile_stats['implemented_fixes']) |
||
| 421 | missing_stig_ids_count = len(profile_stats['missing_stig_ids']) |
||
| 422 | missing_cis_refs_count = len(profile_stats['missing_cis_refs']) |
||
| 423 | missing_hipaa_refs_count = len(profile_stats['missing_hipaa_refs']) |
||
| 424 | missing_anssi_refs_count = len(profile_stats['missing_anssi_refs']) |
||
| 425 | missing_ospp_refs_count = len(profile_stats['missing_ospp_refs']) |
||
| 426 | missing_cui_refs_count = len(profile_stats['missing_cui_refs']) |
||
| 427 | impl_cces_count = len(profile_stats['assigned_cces']) |
||
| 428 | |||
| 429 | if options.format == "plain": |
||
| 430 | if not options.skip_overall_stats: |
||
| 431 | print("\nProfile %s:" % profile) |
||
| 432 | print("* rules: %d" % rules_count) |
||
| 433 | print("* checks (OVAL): %d\t[%d%% complete]" % |
||
| 434 | (impl_ovals_count, |
||
| 435 | profile_stats['implemented_ovals_pct'])) |
||
| 436 | print("* checks (SCE): %d\t[%d%% complete]" % |
||
| 437 | (impl_sces_count, |
||
| 438 | profile_stats['implemented_sces_pct'])) |
||
| 439 | print("* checks (any): %d\t[%d%% complete]" % |
||
| 440 | (impl_checks_count, |
||
| 441 | profile_stats['implemented_checks_pct'])) |
||
| 442 | |||
| 443 | print("* fixes (bash): %d\t[%d%% complete]" % |
||
| 444 | (impl_bash_fixes_count, |
||
| 445 | profile_stats['implemented_bash_fixes_pct'])) |
||
| 446 | print("* fixes (ansible): %d\t[%d%% complete]" % |
||
| 447 | (impl_ansible_fixes_count, |
||
| 448 | profile_stats['implemented_ansible_fixes_pct'])) |
||
| 449 | print("* fixes (ignition): %d\t[%d%% complete]" % |
||
| 450 | (impl_ignition_fixes_count, |
||
| 451 | profile_stats['implemented_ignition_fixes_pct'])) |
||
| 452 | print("* fixes (kubernetes): %d\t[%d%% complete]" % |
||
| 453 | (impl_kubernetes_fixes_count, |
||
| 454 | profile_stats['implemented_kubernetes_fixes_pct'])) |
||
| 455 | print("* fixes (puppet): %d\t[%d%% complete]" % |
||
| 456 | (impl_puppet_fixes_count, |
||
| 457 | profile_stats['implemented_puppet_fixes_pct'])) |
||
| 458 | print("* fixes (anaconda): %d\t[%d%% complete]" % |
||
| 459 | (impl_anaconda_fixes_count, |
||
| 460 | profile_stats['implemented_anaconda_fixes_pct'])) |
||
| 461 | print("* fixes (any): %d\t[%d%% complete]" % |
||
| 462 | (impl_fixes_count, |
||
| 463 | profile_stats['implemented_fixes_pct'])) |
||
| 464 | |||
| 465 | print("* CCEs: %d\t[%d%% complete]" % |
||
| 466 | (impl_cces_count, |
||
| 467 | profile_stats['assigned_cces_pct'])) |
||
| 468 | |||
| 469 | if options.implemented_ovals and \ |
||
| 470 | profile_stats['implemented_ovals']: |
||
| 471 | print("** Rules of '%s' " % profile + |
||
| 472 | "profile having OVAL check: %d of %d [%d%% complete]" % |
||
| 473 | (impl_ovals_count, rules_count, |
||
| 474 | profile_stats['implemented_ovals_pct'])) |
||
| 475 | self.console_print(profile_stats['implemented_ovals'], |
||
| 476 | console_width) |
||
| 477 | |||
| 478 | if options.implemented_sces and \ |
||
| 479 | profile_stats['implemented_sces']: |
||
| 480 | print("** Rules of '%s' " % profile + |
||
| 481 | "profile having SCE check: %d of %d [%d%% complete]" % |
||
| 482 | (impl_sces_count, rules_count, |
||
| 483 | profile_stats['implemented_sces_pct'])) |
||
| 484 | self.console_print(profile_stats['implemented_sces'], |
||
| 485 | console_width) |
||
| 486 | |||
| 487 | if options.implemented_fixes: |
||
| 488 | if profile_stats['implemented_bash_fixes']: |
||
| 489 | print("*** Rules of '%s' profile having " |
||
| 490 | "a bash fix script: %d of %d [%d%% complete]" |
||
| 491 | % (profile, impl_bash_fixes_count, rules_count, |
||
| 492 | profile_stats['implemented_bash_fixes_pct'])) |
||
| 493 | self.console_print(profile_stats['implemented_bash_fixes'], |
||
| 494 | console_width) |
||
| 495 | |||
| 496 | if profile_stats['implemented_ansible_fixes']: |
||
| 497 | print("*** Rules of '%s' profile having " |
||
| 498 | "a ansible fix script: %d of %d [%d%% complete]" |
||
| 499 | % (profile, impl_ansible_fixes_count, rules_count, |
||
| 500 | profile_stats['implemented_ansible_fixes_pct'])) |
||
| 501 | self.console_print( |
||
| 502 | profile_stats['implemented_ansible_fixes'], |
||
| 503 | console_width) |
||
| 504 | |||
| 505 | if profile_stats['implemented_ignition_fixes']: |
||
| 506 | print("*** Rules of '%s' profile having " |
||
| 507 | "a ignition fix script: %d of %d [%d%% complete]" |
||
| 508 | % (profile, impl_ignition_fixes_count, rules_count, |
||
| 509 | profile_stats['implemented_ignition_fixes_pct'])) |
||
| 510 | self.console_print( |
||
| 511 | profile_stats['implemented_ignition_fixes'], |
||
| 512 | console_width) |
||
| 513 | |||
| 514 | if profile_stats['implemented_kubernetes_fixes']: |
||
| 515 | print("*** Rules of '%s' profile having " |
||
| 516 | "a kubernetes fix script: %d of %d [%d%% complete]" |
||
| 517 | % (profile, impl_kubernetes_fixes_count, rules_count, |
||
| 518 | profile_stats['implemented_kubernetes_fixes_pct'])) |
||
| 519 | self.console_print( |
||
| 520 | profile_stats['implemented_kubernetes_fixes'], |
||
| 521 | console_width) |
||
| 522 | |||
| 523 | if profile_stats['implemented_puppet_fixes']: |
||
| 524 | print("*** Rules of '%s' profile having " |
||
| 525 | "a puppet fix script: %d of %d [%d%% complete]" |
||
| 526 | % (profile, impl_puppet_fixes_count, rules_count, |
||
| 527 | profile_stats['implemented_puppet_fixes_pct'])) |
||
| 528 | self.console_print( |
||
| 529 | profile_stats['implemented_puppet_fixes'], |
||
| 530 | console_width) |
||
| 531 | |||
| 532 | if profile_stats['implemented_anaconda_fixes']: |
||
| 533 | print("*** Rules of '%s' profile having " |
||
| 534 | "a anaconda fix script: %d of %d [%d%% complete]" |
||
| 535 | % (profile, impl_anaconda_fixes_count, rules_count, |
||
| 536 | profile_stats['implemented_anaconda_fixes_pct'])) |
||
| 537 | self.console_print( |
||
| 538 | profile_stats['implemented_anaconda_fixes'], |
||
| 539 | console_width) |
||
| 540 | |||
| 541 | if options.assigned_cces and \ |
||
| 542 | profile_stats['assigned_cces']: |
||
| 543 | print("*** Rules of '%s' " % profile + |
||
| 544 | "profile having CCE assigned: %d of %d [%d%% complete]" % |
||
| 545 | (impl_cces_count, rules_count, |
||
| 546 | profile_stats['assigned_cces_pct'])) |
||
| 547 | self.console_print(profile_stats['assigned_cces'], |
||
| 548 | console_width) |
||
| 549 | |||
| 550 | if options.missing_ovals and profile_stats['missing_ovals']: |
||
| 551 | print("*** Rules of '%s' " % profile + "profile missing " + |
||
| 552 | "OVAL: %d of %d [%d%% complete]" % |
||
| 553 | (rules_count - impl_ovals_count, rules_count, |
||
| 554 | profile_stats['implemented_ovals_pct'])) |
||
| 555 | self.console_print(profile_stats['missing_ovals'], |
||
| 556 | console_width) |
||
| 557 | |||
| 558 | if options.missing_sces and profile_stats['missing_sces']: |
||
| 559 | print("*** Rules of '%s' " % profile + "profile missing " + |
||
| 560 | "SCE: %d of %d [%d%% complete]" % |
||
| 561 | (rules_count - impl_sces_count, rules_count, |
||
| 562 | profile_stats['implemented_sces_pct'])) |
||
| 563 | self.console_print(profile_stats['missing_sces'], |
||
| 564 | console_width) |
||
| 565 | |||
| 566 | if options.missing_fixes: |
||
| 567 | if profile_stats['missing_bash_fixes']: |
||
| 568 | print("*** rules of '%s' profile missing " |
||
| 569 | "a bash fix script: %d of %d [%d%% complete]" |
||
| 570 | % (profile, rules_count - impl_bash_fixes_count, |
||
| 571 | rules_count, |
||
| 572 | profile_stats['implemented_bash_fixes_pct'])) |
||
| 573 | self.console_print(profile_stats['missing_bash_fixes'], |
||
| 574 | console_width) |
||
| 575 | |||
| 576 | if profile_stats['missing_ansible_fixes']: |
||
| 577 | print("*** rules of '%s' profile missing " |
||
| 578 | "a ansible fix script: %d of %d [%d%% complete]" |
||
| 579 | % (profile, rules_count - impl_ansible_fixes_count, |
||
| 580 | rules_count, |
||
| 581 | profile_stats['implemented_ansible_fixes_pct'])) |
||
| 582 | self.console_print(profile_stats['missing_ansible_fixes'], |
||
| 583 | console_width) |
||
| 584 | |||
| 585 | if profile_stats['missing_ignition_fixes']: |
||
| 586 | print("*** rules of '%s' profile missing " |
||
| 587 | "a ignition fix script: %d of %d [%d%% complete]" |
||
| 588 | % (profile, rules_count - impl_ignition_fixes_count, |
||
| 589 | rules_count, |
||
| 590 | profile_stats['implemented_ignition_fixes_pct'])) |
||
| 591 | self.console_print(profile_stats['missing_ignition_fixes'], |
||
| 592 | console_width) |
||
| 593 | |||
| 594 | if profile_stats['missing_kubernetes_fixes']: |
||
| 595 | print("*** rules of '%s' profile missing " |
||
| 596 | "a kubernetes fix script: %d of %d [%d%% complete]" |
||
| 597 | % (profile, rules_count - impl_kubernetes_fixes_count, |
||
| 598 | rules_count, |
||
| 599 | profile_stats['implemented_kubernetes_fixes_pct'])) |
||
| 600 | self.console_print(profile_stats['missing_kubernetes_fixes'], |
||
| 601 | console_width) |
||
| 602 | |||
| 603 | if profile_stats['missing_puppet_fixes']: |
||
| 604 | print("*** rules of '%s' profile missing " |
||
| 605 | "a puppet fix script: %d of %d [%d%% complete]" |
||
| 606 | % (profile, rules_count - impl_puppet_fixes_count, |
||
| 607 | rules_count, |
||
| 608 | profile_stats['implemented_puppet_fixes_pct'])) |
||
| 609 | self.console_print(profile_stats['missing_puppet_fixes'], |
||
| 610 | console_width) |
||
| 611 | |||
| 612 | if profile_stats['missing_anaconda_fixes']: |
||
| 613 | print("*** rules of '%s' profile missing " |
||
| 614 | "a anaconda fix script: %d of %d [%d%% complete]" |
||
| 615 | % (profile, rules_count - impl_anaconda_fixes_count, |
||
| 616 | rules_count, |
||
| 617 | profile_stats['implemented_anaconda_fixes_pct'])) |
||
| 618 | self.console_print(profile_stats['missing_anaconda_fixes'], |
||
| 619 | console_width) |
||
| 620 | |||
| 621 | if options.missing_stig_ids and profile_stats['missing_stig_ids']: |
||
| 622 | print("*** rules of '%s' profile missing " |
||
| 623 | "STIG IDs: %d of %d have them [%d%% missing]" |
||
| 624 | % (profile, rules_count - missing_stig_ids_count, |
||
| 625 | rules_count, |
||
| 626 | (100.0 * missing_stig_ids_count / rules_count))) |
||
| 627 | self.console_print(profile_stats['missing_stig_ids'], |
||
| 628 | console_width) |
||
| 629 | |||
| 630 | if options.missing_cis_refs and profile_stats['missing_cis_refs']: |
||
| 631 | print("*** rules of '%s' profile missing " |
||
| 632 | "CIS Refs: %d of %d have them [%d%% missing]" |
||
| 633 | % (profile, rules_count - missing_cis_refs_count, |
||
| 634 | rules_count, |
||
| 635 | (100.0 * missing_cis_refs_count / rules_count))) |
||
| 636 | self.console_print(profile_stats['missing_cis_refs'], |
||
| 637 | console_width) |
||
| 638 | |||
| 639 | if options.missing_hipaa_refs and profile_stats['missing_hipaa_refs']: |
||
| 640 | print("*** rules of '%s' profile missing " |
||
| 641 | "HIPAA Refs: %d of %d have them [%d%% missing]" |
||
| 642 | % (profile, rules_count - missing_hipaa_refs_count, |
||
| 643 | rules_count, |
||
| 644 | (100.0 * missing_hipaa_refs_count / rules_count))) |
||
| 645 | self.console_print(profile_stats['missing_hipaa_refs'], |
||
| 646 | console_width) |
||
| 647 | |||
| 648 | if options.missing_anssi_refs and profile_stats['missing_anssi_refs']: |
||
| 649 | print("*** rules of '%s' profile missing " |
||
| 650 | "ANSSI Refs: %d of %d have them [%d%% missing]" |
||
| 651 | % (profile, rules_count - missing_anssi_refs_count, |
||
| 652 | rules_count, |
||
| 653 | (100.0 * missing_anssi_refs_count / rules_count))) |
||
| 654 | self.console_print(profile_stats['missing_anssi_refs'], |
||
| 655 | console_width) |
||
| 656 | |||
| 657 | if options.missing_ospp_refs and profile_stats['missing_ospp_refs']: |
||
| 658 | print("*** rules of '%s' profile missing " |
||
| 659 | "OSPP Refs: %d of %d have them [%d%% missing]" |
||
| 660 | % (profile, rules_count - missing_ospp_refs_count, |
||
| 661 | rules_count, |
||
| 662 | (100.0 * missing_ospp_refs_count / rules_count))) |
||
| 663 | self.console_print(profile_stats['missing_ospp_refs'], |
||
| 664 | console_width) |
||
| 665 | |||
| 666 | if options.missing_cui_refs and profile_stats['missing_cui_refs']: |
||
| 667 | print("*** rules of '%s' profile missing " |
||
| 668 | "CUI Refs: %d of %d have them [%d%% missing]" |
||
| 669 | % (profile, rules_count - missing_cui_refs_count, |
||
| 670 | rules_count, |
||
| 671 | (100.0 * missing_cui_refs_count / rules_count))) |
||
| 672 | self.console_print(profile_stats['missing_cui_refs'], |
||
| 673 | console_width) |
||
| 674 | |||
| 675 | if options.missing_cces and profile_stats['missing_cces']: |
||
| 676 | print("***Rules of '%s' " % profile + "profile missing " + |
||
| 677 | "CCE identifier: %d of %d [%d%% complete]" % |
||
| 678 | (rules_count - impl_cces_count, rules_count, |
||
| 679 | profile_stats['assigned_cces_pct'])) |
||
| 680 | self.console_print(profile_stats['missing_cces'], |
||
| 681 | console_width) |
||
| 682 | |||
| 683 | if options.ansible_parity: |
||
| 684 | print("*** rules of '%s' profile with bash fix that implement " |
||
| 685 | "ansible fix scripts: %d out of %d [%d%% complete]" |
||
| 686 | % (profile, impl_bash_fixes_count - len(profile_stats['ansible_parity']), |
||
| 687 | impl_bash_fixes_count, |
||
| 688 | profile_stats['ansible_parity_pct'])) |
||
| 689 | self.console_print(profile_stats['ansible_parity'], |
||
| 690 | console_width) |
||
| 691 | |||
| 692 | elif options.format == "html": |
||
| 693 | del profile_stats['implemented_ovals'] |
||
| 694 | del profile_stats['implemented_sces'] |
||
| 695 | del profile_stats['implemented_bash_fixes'] |
||
| 696 | del profile_stats['implemented_ansible_fixes'] |
||
| 697 | del profile_stats['implemented_ignition_fixes'] |
||
| 698 | del profile_stats['implemented_kubernetes_fixes'] |
||
| 699 | del profile_stats['implemented_puppet_fixes'] |
||
| 700 | del profile_stats['implemented_anaconda_fixes'] |
||
| 701 | del profile_stats['assigned_cces'] |
||
| 702 | |||
| 703 | profile_stats['missing_stig_ids_count'] = missing_stig_ids_count |
||
| 704 | profile_stats['missing_cis_refs_count'] = missing_cis_refs_count |
||
| 705 | profile_stats['missing_hipaa_refs_count'] = missing_hipaa_refs_count |
||
| 706 | profile_stats['missing_anssi_refs_count'] = missing_anssi_refs_count |
||
| 707 | profile_stats['missing_ospp_refs_count'] = missing_ospp_refs_count |
||
| 708 | profile_stats['missing_cui_refs_count'] = missing_cui_refs_count |
||
| 709 | profile_stats['missing_ovals_count'] = len(profile_stats['missing_ovals']) |
||
| 710 | profile_stats['missing_sces_count'] = len(profile_stats['missing_sces']) |
||
| 711 | profile_stats['missing_bash_fixes_count'] = len(profile_stats['missing_bash_fixes']) |
||
| 712 | profile_stats['missing_ansible_fixes_count'] = len(profile_stats['missing_ansible_fixes']) |
||
| 713 | profile_stats['missing_ignition_fixes_count'] = len(profile_stats['missing_ignition_fixes']) |
||
| 714 | profile_stats['missing_kubernetes_fixes_count'] = \ |
||
| 715 | len(profile_stats['missing_kubernetes_fixes']) |
||
| 716 | profile_stats['missing_puppet_fixes_count'] = len(profile_stats['missing_puppet_fixes']) |
||
| 717 | profile_stats['missing_anaconda_fixes_count'] = len(profile_stats['missing_anaconda_fixes']) |
||
| 718 | profile_stats['missing_cces_count'] = len(profile_stats['missing_cces']) |
||
| 719 | |||
| 720 | del profile_stats['implemented_ovals_pct'] |
||
| 721 | del profile_stats['implemented_sces_pct'] |
||
| 722 | del profile_stats['implemented_bash_fixes_pct'] |
||
| 723 | del profile_stats['implemented_ansible_fixes_pct'] |
||
| 724 | del profile_stats['implemented_ignition_fixes_pct'] |
||
| 725 | del profile_stats['implemented_kubernetes_fixes_pct'] |
||
| 726 | del profile_stats['implemented_puppet_fixes_pct'] |
||
| 727 | del profile_stats['implemented_anaconda_fixes_pct'] |
||
| 728 | del profile_stats['assigned_cces_pct'] |
||
| 729 | del profile_stats['ssg_version'] |
||
| 730 | del profile_stats['ansible_parity_pct'] |
||
| 731 | |||
| 732 | return profile_stats |
||
| 733 | else: |
||
| 734 | # First delete the not requested information |
||
| 735 | if not options.missing_ovals: |
||
| 736 | del profile_stats['missing_ovals'] |
||
| 737 | if not options.missing_sces: |
||
| 738 | del profile_stats['missing_sces'] |
||
| 739 | if not options.missing_fixes: |
||
| 740 | del profile_stats['missing_bash_fixes'] |
||
| 741 | del profile_stats['missing_ansible_fixes'] |
||
| 742 | del profile_stats['missing_ignition_fixes'] |
||
| 743 | del profile_stats['missing_kubernetes_fixes'] |
||
| 744 | del profile_stats['missing_puppet_fixes'] |
||
| 745 | del profile_stats['missing_anaconda_fixes'] |
||
| 746 | del profile_stats['missing_stig_ids'] |
||
| 747 | del profile_stats['missing_cis_refs'] |
||
| 748 | del profile_stats['missing_hipaa_refs'] |
||
| 749 | del profile_stats['missing_anssi_refs'] |
||
| 750 | del profile_stats['missing_ospp_refs'] |
||
| 751 | del profile_stats['missing_cui_refs'] |
||
| 752 | if not options.missing_cces: |
||
| 753 | del profile_stats['missing_cces'] |
||
| 754 | if not options.implemented_ovals: |
||
| 755 | del profile_stats['implemented_ovals'] |
||
| 756 | if not options.implemented_sces: |
||
| 757 | del profile_stats['implemented_sces'] |
||
| 758 | if not options.implemented_fixes: |
||
| 759 | del profile_stats['implemented_bash_fixes'] |
||
| 760 | del profile_stats['implemented_ansible_fixes'] |
||
| 761 | del profile_stats['implemented_ignition_fixes'] |
||
| 762 | del profile_stats['implemented_kubernetes_fixes'] |
||
| 763 | del profile_stats['implemented_puppet_fixes'] |
||
| 764 | del profile_stats['implemented_anaconda_fixes'] |
||
| 765 | if not options.assigned_cces: |
||
| 766 | del profile_stats['assigned_cces'] |
||
| 767 | |||
| 768 | del profile_stats['rules'] |
||
| 769 | |||
| 770 | return profile_stats |
||
| 771 | |||
| 785 |