| Conditions | 51 |
| Total Lines | 367 |
| Code Lines | 310 |
| 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 |
||
| 419 | def show_profile_stats(self, profile, options): |
||
| 420 | """Displays statistics for specific profile""" |
||
| 421 | |||
| 422 | profile_stats = self.get_profile_stats(profile) |
||
| 423 | rules_count = profile_stats['rules_count'] |
||
| 424 | impl_ovals_count = len(profile_stats['implemented_ovals']) |
||
| 425 | impl_sces_count = len(profile_stats['implemented_sces']) |
||
| 426 | impl_checks_count = len(profile_stats['implemented_checks']) |
||
| 427 | impl_bash_fixes_count = len(profile_stats['implemented_bash_fixes']) |
||
| 428 | impl_ansible_fixes_count = len(profile_stats['implemented_ansible_fixes']) |
||
| 429 | impl_ignition_fixes_count = len(profile_stats['implemented_ignition_fixes']) |
||
| 430 | impl_kubernetes_fixes_count = len(profile_stats['implemented_kubernetes_fixes']) |
||
| 431 | impl_puppet_fixes_count = len(profile_stats['implemented_puppet_fixes']) |
||
| 432 | impl_anaconda_fixes_count = len(profile_stats['implemented_anaconda_fixes']) |
||
| 433 | impl_fixes_count = len(profile_stats['implemented_fixes']) |
||
| 434 | missing_stig_ids_count = len(profile_stats['missing_stig_ids']) |
||
| 435 | missing_cis_refs_count = len(profile_stats['missing_cis_refs']) |
||
| 436 | missing_hipaa_refs_count = len(profile_stats['missing_hipaa_refs']) |
||
| 437 | missing_anssi_refs_count = len(profile_stats['missing_anssi_refs']) |
||
| 438 | missing_ospp_refs_count = len(profile_stats['missing_ospp_refs']) |
||
| 439 | missing_cui_refs_count = len(profile_stats['missing_cui_refs']) |
||
| 440 | impl_cces_count = len(profile_stats['assigned_cces']) |
||
| 441 | |||
| 442 | if options.format == "plain": |
||
| 443 | if not options.skip_overall_stats: |
||
| 444 | print("\nProfile %s:" % profile.replace(OSCAP_PROFILE, "")) |
||
| 445 | print("* rules: %d" % rules_count) |
||
| 446 | print("* checks (OVAL): %d\t[%d%% complete]" % |
||
| 447 | (impl_ovals_count, |
||
| 448 | profile_stats['implemented_ovals_pct'])) |
||
| 449 | print("* checks (SCE): %d\t[%d%% complete]" % |
||
| 450 | (impl_sces_count, |
||
| 451 | profile_stats['implemented_sces_pct'])) |
||
| 452 | print("* checks (any): %d\t[%d%% complete]" % |
||
| 453 | (impl_checks_count, |
||
| 454 | profile_stats['implemented_checks_pct'])) |
||
| 455 | |||
| 456 | print("* fixes (bash): %d\t[%d%% complete]" % |
||
| 457 | (impl_bash_fixes_count, |
||
| 458 | profile_stats['implemented_bash_fixes_pct'])) |
||
| 459 | print("* fixes (ansible): %d\t[%d%% complete]" % |
||
| 460 | (impl_ansible_fixes_count, |
||
| 461 | profile_stats['implemented_ansible_fixes_pct'])) |
||
| 462 | print("* fixes (ignition): %d\t[%d%% complete]" % |
||
| 463 | (impl_ignition_fixes_count, |
||
| 464 | profile_stats['implemented_ignition_fixes_pct'])) |
||
| 465 | print("* fixes (kubernetes): %d\t[%d%% complete]" % |
||
| 466 | (impl_kubernetes_fixes_count, |
||
| 467 | profile_stats['implemented_kubernetes_fixes_pct'])) |
||
| 468 | print("* fixes (puppet): %d\t[%d%% complete]" % |
||
| 469 | (impl_puppet_fixes_count, |
||
| 470 | profile_stats['implemented_puppet_fixes_pct'])) |
||
| 471 | print("* fixes (anaconda): %d\t[%d%% complete]" % |
||
| 472 | (impl_anaconda_fixes_count, |
||
| 473 | profile_stats['implemented_anaconda_fixes_pct'])) |
||
| 474 | print("* fixes (any): %d\t[%d%% complete]" % |
||
| 475 | (impl_fixes_count, |
||
| 476 | profile_stats['implemented_fixes_pct'])) |
||
| 477 | |||
| 478 | print("* CCEs: %d\t[%d%% complete]" % |
||
| 479 | (impl_cces_count, |
||
| 480 | profile_stats['assigned_cces_pct'])) |
||
| 481 | |||
| 482 | if options.implemented_ovals and \ |
||
| 483 | profile_stats['implemented_ovals']: |
||
| 484 | print("** Rules of '%s' " % profile + |
||
| 485 | "profile having OVAL check: %d of %d [%d%% complete]" % |
||
| 486 | (impl_ovals_count, rules_count, |
||
| 487 | profile_stats['implemented_ovals_pct'])) |
||
| 488 | self.console_print(profile_stats['implemented_ovals'], |
||
| 489 | console_width) |
||
| 490 | |||
| 491 | if options.implemented_sces and \ |
||
| 492 | profile_stats['implemented_sces']: |
||
| 493 | print("** Rules of '%s' " % profile + |
||
| 494 | "profile having SCE check: %d of %d [%d%% complete]" % |
||
| 495 | (impl_sces_count, rules_count, |
||
| 496 | profile_stats['implemented_sces_pct'])) |
||
| 497 | self.console_print(profile_stats['implemented_sces'], |
||
| 498 | console_width) |
||
| 499 | |||
| 500 | if options.implemented_fixes: |
||
| 501 | if profile_stats['implemented_bash_fixes']: |
||
| 502 | print("*** Rules of '%s' profile having " |
||
| 503 | "a bash fix script: %d of %d [%d%% complete]" |
||
| 504 | % (profile, impl_bash_fixes_count, rules_count, |
||
| 505 | profile_stats['implemented_bash_fixes_pct'])) |
||
| 506 | self.console_print(profile_stats['implemented_bash_fixes'], |
||
| 507 | console_width) |
||
| 508 | |||
| 509 | if profile_stats['implemented_ansible_fixes']: |
||
| 510 | print("*** Rules of '%s' profile having " |
||
| 511 | "a ansible fix script: %d of %d [%d%% complete]" |
||
| 512 | % (profile, impl_ansible_fixes_count, rules_count, |
||
| 513 | profile_stats['implemented_ansible_fixes_pct'])) |
||
| 514 | self.console_print( |
||
| 515 | profile_stats['implemented_ansible_fixes'], |
||
| 516 | console_width) |
||
| 517 | |||
| 518 | if profile_stats['implemented_ignition_fixes']: |
||
| 519 | print("*** Rules of '%s' profile having " |
||
| 520 | "a ignition fix script: %d of %d [%d%% complete]" |
||
| 521 | % (profile, impl_ignition_fixes_count, rules_count, |
||
| 522 | profile_stats['implemented_ignition_fixes_pct'])) |
||
| 523 | self.console_print( |
||
| 524 | profile_stats['implemented_ignition_fixes'], |
||
| 525 | console_width) |
||
| 526 | |||
| 527 | if profile_stats['implemented_kubernetes_fixes']: |
||
| 528 | print("*** Rules of '%s' profile having " |
||
| 529 | "a kubernetes fix script: %d of %d [%d%% complete]" |
||
| 530 | % (profile, impl_kubernetes_fixes_count, rules_count, |
||
| 531 | profile_stats['implemented_kubernetes_fixes_pct'])) |
||
| 532 | self.console_print( |
||
| 533 | profile_stats['implemented_kubernetes_fixes'], |
||
| 534 | console_width) |
||
| 535 | |||
| 536 | if profile_stats['implemented_puppet_fixes']: |
||
| 537 | print("*** Rules of '%s' profile having " |
||
| 538 | "a puppet fix script: %d of %d [%d%% complete]" |
||
| 539 | % (profile, impl_puppet_fixes_count, rules_count, |
||
| 540 | profile_stats['implemented_puppet_fixes_pct'])) |
||
| 541 | self.console_print( |
||
| 542 | profile_stats['implemented_puppet_fixes'], |
||
| 543 | console_width) |
||
| 544 | |||
| 545 | if profile_stats['implemented_anaconda_fixes']: |
||
| 546 | print("*** Rules of '%s' profile having " |
||
| 547 | "a anaconda fix script: %d of %d [%d%% complete]" |
||
| 548 | % (profile, impl_anaconda_fixes_count, rules_count, |
||
| 549 | profile_stats['implemented_anaconda_fixes_pct'])) |
||
| 550 | self.console_print( |
||
| 551 | profile_stats['implemented_anaconda_fixes'], |
||
| 552 | console_width) |
||
| 553 | |||
| 554 | if options.assigned_cces and \ |
||
| 555 | profile_stats['assigned_cces']: |
||
| 556 | print("*** Rules of '%s' " % profile + |
||
| 557 | "profile having CCE assigned: %d of %d [%d%% complete]" % |
||
| 558 | (impl_cces_count, rules_count, |
||
| 559 | profile_stats['assigned_cces_pct'])) |
||
| 560 | self.console_print(profile_stats['assigned_cces'], |
||
| 561 | console_width) |
||
| 562 | |||
| 563 | if options.missing_ovals and profile_stats['missing_ovals']: |
||
| 564 | print("*** Rules of '%s' " % profile + "profile missing " + |
||
| 565 | "OVAL: %d of %d [%d%% complete]" % |
||
| 566 | (rules_count - impl_ovals_count, rules_count, |
||
| 567 | profile_stats['implemented_ovals_pct'])) |
||
| 568 | self.console_print(profile_stats['missing_ovals'], |
||
| 569 | console_width) |
||
| 570 | |||
| 571 | if options.missing_sces and profile_stats['missing_sces']: |
||
| 572 | print("*** Rules of '%s' " % profile + "profile missing " + |
||
| 573 | "SCE: %d of %d [%d%% complete]" % |
||
| 574 | (rules_count - impl_sces_count, rules_count, |
||
| 575 | profile_stats['implemented_sces_pct'])) |
||
| 576 | self.console_print(profile_stats['missing_sces'], |
||
| 577 | console_width) |
||
| 578 | |||
| 579 | if options.missing_fixes: |
||
| 580 | if profile_stats['missing_bash_fixes']: |
||
| 581 | print("*** rules of '%s' profile missing " |
||
| 582 | "a bash fix script: %d of %d [%d%% complete]" |
||
| 583 | % (profile, rules_count - impl_bash_fixes_count, |
||
| 584 | rules_count, |
||
| 585 | profile_stats['implemented_bash_fixes_pct'])) |
||
| 586 | self.console_print(profile_stats['missing_bash_fixes'], |
||
| 587 | console_width) |
||
| 588 | |||
| 589 | if profile_stats['missing_ansible_fixes']: |
||
| 590 | print("*** rules of '%s' profile missing " |
||
| 591 | "a ansible fix script: %d of %d [%d%% complete]" |
||
| 592 | % (profile, rules_count - impl_ansible_fixes_count, |
||
| 593 | rules_count, |
||
| 594 | profile_stats['implemented_ansible_fixes_pct'])) |
||
| 595 | self.console_print(profile_stats['missing_ansible_fixes'], |
||
| 596 | console_width) |
||
| 597 | |||
| 598 | if profile_stats['missing_ignition_fixes']: |
||
| 599 | print("*** rules of '%s' profile missing " |
||
| 600 | "a ignition fix script: %d of %d [%d%% complete]" |
||
| 601 | % (profile, rules_count - impl_ignition_fixes_count, |
||
| 602 | rules_count, |
||
| 603 | profile_stats['implemented_ignition_fixes_pct'])) |
||
| 604 | self.console_print(profile_stats['missing_ignition_fixes'], |
||
| 605 | console_width) |
||
| 606 | |||
| 607 | if profile_stats['missing_kubernetes_fixes']: |
||
| 608 | print("*** rules of '%s' profile missing " |
||
| 609 | "a kubernetes fix script: %d of %d [%d%% complete]" |
||
| 610 | % (profile, rules_count - impl_kubernetes_fixes_count, |
||
| 611 | rules_count, |
||
| 612 | profile_stats['implemented_kubernetes_fixes_pct'])) |
||
| 613 | self.console_print(profile_stats['missing_kubernetes_fixes'], |
||
| 614 | console_width) |
||
| 615 | |||
| 616 | if profile_stats['missing_puppet_fixes']: |
||
| 617 | print("*** rules of '%s' profile missing " |
||
| 618 | "a puppet fix script: %d of %d [%d%% complete]" |
||
| 619 | % (profile, rules_count - impl_puppet_fixes_count, |
||
| 620 | rules_count, |
||
| 621 | profile_stats['implemented_puppet_fixes_pct'])) |
||
| 622 | self.console_print(profile_stats['missing_puppet_fixes'], |
||
| 623 | console_width) |
||
| 624 | |||
| 625 | if profile_stats['missing_anaconda_fixes']: |
||
| 626 | print("*** rules of '%s' profile missing " |
||
| 627 | "a anaconda fix script: %d of %d [%d%% complete]" |
||
| 628 | % (profile, rules_count - impl_anaconda_fixes_count, |
||
| 629 | rules_count, |
||
| 630 | profile_stats['implemented_anaconda_fixes_pct'])) |
||
| 631 | self.console_print(profile_stats['missing_anaconda_fixes'], |
||
| 632 | console_width) |
||
| 633 | |||
| 634 | if options.missing_stig_ids and profile_stats['missing_stig_ids']: |
||
| 635 | print("*** rules of '%s' profile missing " |
||
| 636 | "STIG IDs: %d of %d have them [%d%% missing]" |
||
| 637 | % (profile, rules_count - missing_stig_ids_count, |
||
| 638 | rules_count, |
||
| 639 | (100.0 * missing_stig_ids_count / rules_count))) |
||
| 640 | self.console_print(profile_stats['missing_stig_ids'], |
||
| 641 | console_width) |
||
| 642 | |||
| 643 | if options.missing_cis_refs and profile_stats['missing_cis_refs']: |
||
| 644 | print("*** rules of '%s' profile missing " |
||
| 645 | "CIS Refs: %d of %d have them [%d%% missing]" |
||
| 646 | % (profile, rules_count - missing_cis_refs_count, |
||
| 647 | rules_count, |
||
| 648 | (100.0 * missing_cis_refs_count / rules_count))) |
||
| 649 | self.console_print(profile_stats['missing_cis_refs'], |
||
| 650 | console_width) |
||
| 651 | |||
| 652 | if options.missing_hipaa_refs and profile_stats['missing_hipaa_refs']: |
||
| 653 | print("*** rules of '%s' profile missing " |
||
| 654 | "HIPAA Refs: %d of %d have them [%d%% missing]" |
||
| 655 | % (profile, rules_count - missing_hipaa_refs_count, |
||
| 656 | rules_count, |
||
| 657 | (100.0 * missing_hipaa_refs_count / rules_count))) |
||
| 658 | self.console_print(profile_stats['missing_hipaa_refs'], |
||
| 659 | console_width) |
||
| 660 | |||
| 661 | if options.missing_anssi_refs and profile_stats['missing_anssi_refs']: |
||
| 662 | print("*** rules of '%s' profile missing " |
||
| 663 | "ANSSI Refs: %d of %d have them [%d%% missing]" |
||
| 664 | % (profile, rules_count - missing_anssi_refs_count, |
||
| 665 | rules_count, |
||
| 666 | (100.0 * missing_anssi_refs_count / rules_count))) |
||
| 667 | self.console_print(profile_stats['missing_anssi_refs'], |
||
| 668 | console_width) |
||
| 669 | |||
| 670 | if options.missing_ospp_refs and profile_stats['missing_ospp_refs']: |
||
| 671 | print("*** rules of '%s' profile missing " |
||
| 672 | "OSPP Refs: %d of %d have them [%d%% missing]" |
||
| 673 | % (profile, rules_count - missing_ospp_refs_count, |
||
| 674 | rules_count, |
||
| 675 | (100.0 * missing_ospp_refs_count / rules_count))) |
||
| 676 | self.console_print(profile_stats['missing_ospp_refs'], |
||
| 677 | console_width) |
||
| 678 | |||
| 679 | if options.missing_cui_refs and profile_stats['missing_cui_refs']: |
||
| 680 | print("*** rules of '%s' profile missing " |
||
| 681 | "CUI Refs: %d of %d have them [%d%% missing]" |
||
| 682 | % (profile, rules_count - missing_cui_refs_count, |
||
| 683 | rules_count, |
||
| 684 | (100.0 * missing_cui_refs_count / rules_count))) |
||
| 685 | self.console_print(profile_stats['missing_cui_refs'], |
||
| 686 | console_width) |
||
| 687 | |||
| 688 | if options.missing_cces and profile_stats['missing_cces']: |
||
| 689 | print("***Rules of '%s' " % profile + "profile missing " + |
||
| 690 | "CCE identifier: %d of %d [%d%% complete]" % |
||
| 691 | (rules_count - impl_cces_count, rules_count, |
||
| 692 | profile_stats['assigned_cces_pct'])) |
||
| 693 | self.console_print(profile_stats['missing_cces'], |
||
| 694 | console_width) |
||
| 695 | |||
| 696 | if options.ansible_parity: |
||
| 697 | print("*** rules of '%s' profile with bash fix that implement " |
||
| 698 | "ansible fix scripts: %d out of %d [%d%% complete]" |
||
| 699 | % (profile, impl_bash_fixes_count - len(profile_stats['ansible_parity']), |
||
| 700 | impl_bash_fixes_count, |
||
| 701 | profile_stats['ansible_parity_pct'])) |
||
| 702 | self.console_print(profile_stats['ansible_parity'], |
||
| 703 | console_width) |
||
| 704 | |||
| 705 | elif options.format == "html": |
||
| 706 | del profile_stats['implemented_ovals'] |
||
| 707 | del profile_stats['implemented_sces'] |
||
| 708 | del profile_stats['implemented_bash_fixes'] |
||
| 709 | del profile_stats['implemented_ansible_fixes'] |
||
| 710 | del profile_stats['implemented_ignition_fixes'] |
||
| 711 | del profile_stats['implemented_kubernetes_fixes'] |
||
| 712 | del profile_stats['implemented_puppet_fixes'] |
||
| 713 | del profile_stats['implemented_anaconda_fixes'] |
||
| 714 | del profile_stats['assigned_cces'] |
||
| 715 | |||
| 716 | profile_stats['missing_stig_ids_count'] = missing_stig_ids_count |
||
| 717 | profile_stats['missing_cis_refs_count'] = missing_cis_refs_count |
||
| 718 | profile_stats['missing_hipaa_refs_count'] = missing_hipaa_refs_count |
||
| 719 | profile_stats['missing_anssi_refs_count'] = missing_anssi_refs_count |
||
| 720 | profile_stats['missing_ospp_refs_count'] = missing_ospp_refs_count |
||
| 721 | profile_stats['missing_cui_refs_count'] = missing_cui_refs_count |
||
| 722 | profile_stats['missing_ovals_count'] = len(profile_stats['missing_ovals']) |
||
| 723 | profile_stats['missing_sces_count'] = len(profile_stats['missing_sces']) |
||
| 724 | profile_stats['missing_bash_fixes_count'] = len(profile_stats['missing_bash_fixes']) |
||
| 725 | profile_stats['missing_ansible_fixes_count'] = len(profile_stats['missing_ansible_fixes']) |
||
| 726 | profile_stats['missing_ignition_fixes_count'] = len(profile_stats['missing_ignition_fixes']) |
||
| 727 | profile_stats['missing_kubernetes_fixes_count'] = \ |
||
| 728 | len(profile_stats['missing_kubernetes_fixes']) |
||
| 729 | profile_stats['missing_puppet_fixes_count'] = len(profile_stats['missing_puppet_fixes']) |
||
| 730 | profile_stats['missing_anaconda_fixes_count'] = len(profile_stats['missing_anaconda_fixes']) |
||
| 731 | profile_stats['missing_cces_count'] = len(profile_stats['missing_cces']) |
||
| 732 | |||
| 733 | del profile_stats['implemented_ovals_pct'] |
||
| 734 | del profile_stats['implemented_sces_pct'] |
||
| 735 | del profile_stats['implemented_bash_fixes_pct'] |
||
| 736 | del profile_stats['implemented_ansible_fixes_pct'] |
||
| 737 | del profile_stats['implemented_ignition_fixes_pct'] |
||
| 738 | del profile_stats['implemented_kubernetes_fixes_pct'] |
||
| 739 | del profile_stats['implemented_puppet_fixes_pct'] |
||
| 740 | del profile_stats['implemented_anaconda_fixes_pct'] |
||
| 741 | del profile_stats['assigned_cces_pct'] |
||
| 742 | del profile_stats['ssg_version'] |
||
| 743 | del profile_stats['ansible_parity_pct'] |
||
| 744 | del profile_stats['implemented_checks_pct'] |
||
| 745 | del profile_stats['implemented_fixes_pct'] |
||
| 746 | |||
| 747 | return profile_stats |
||
| 748 | else: |
||
| 749 | # First delete the not requested information |
||
| 750 | if not options.missing_ovals: |
||
| 751 | del profile_stats['missing_ovals'] |
||
| 752 | if not options.missing_sces: |
||
| 753 | del profile_stats['missing_sces'] |
||
| 754 | if not options.missing_fixes: |
||
| 755 | del profile_stats['missing_bash_fixes'] |
||
| 756 | del profile_stats['missing_ansible_fixes'] |
||
| 757 | del profile_stats['missing_ignition_fixes'] |
||
| 758 | del profile_stats['missing_kubernetes_fixes'] |
||
| 759 | del profile_stats['missing_puppet_fixes'] |
||
| 760 | del profile_stats['missing_anaconda_fixes'] |
||
| 761 | del profile_stats['missing_stig_ids'] |
||
| 762 | del profile_stats['missing_cis_refs'] |
||
| 763 | del profile_stats['missing_hipaa_refs'] |
||
| 764 | del profile_stats['missing_anssi_refs'] |
||
| 765 | del profile_stats['missing_ospp_refs'] |
||
| 766 | del profile_stats['missing_cui_refs'] |
||
| 767 | if not options.missing_cces: |
||
| 768 | del profile_stats['missing_cces'] |
||
| 769 | if not options.implemented_ovals: |
||
| 770 | del profile_stats['implemented_ovals'] |
||
| 771 | if not options.implemented_sces: |
||
| 772 | del profile_stats['implemented_sces'] |
||
| 773 | if not options.implemented_fixes: |
||
| 774 | del profile_stats['implemented_bash_fixes'] |
||
| 775 | del profile_stats['implemented_ansible_fixes'] |
||
| 776 | del profile_stats['implemented_ignition_fixes'] |
||
| 777 | del profile_stats['implemented_kubernetes_fixes'] |
||
| 778 | del profile_stats['implemented_puppet_fixes'] |
||
| 779 | del profile_stats['implemented_anaconda_fixes'] |
||
| 780 | if not options.assigned_cces: |
||
| 781 | del profile_stats['assigned_cces'] |
||
| 782 | |||
| 783 | del profile_stats['rules'] |
||
| 784 | |||
| 785 | return profile_stats |
||
| 786 | |||
| 809 |