Exemplo n.º 1
0
def main():
    # Argument parsing
    parser = argparse.ArgumentParser(description='Download files from GitHub \
    issues.')
    parser.add_argument("-a",
                        "--authcode",
                        dest="authcode",
                        help="Enter your two-factor auth code.  Required for \
                        use if two-factor authentication is enabled across \
                        GitHub.")
    parser.add_argument("--debug",
                        dest="debug",
                        action="store_true",
                        help="Enable debug logging")
    args = parser.parse_args()
    # Basic logging that matches logrus format
    fmt_string = "%(levelname)s %(message)-20s"
    fmtr = LogrusFormatter(colorize=True, fmt=fmt_string)
    logger = logging.getLogger(name=None)
    if not args.debug:
        logger.setLevel(logging.INFO)
    else:
        logger.setLevel(logging.DEBUG)
    hdlr = logging.StreamHandler(sys.stdout)
    hdlr.setFormatter(fmtr)
    logger.addHandler(hdlr)
Exemplo n.º 2
0
def main():
    urllib3.disable_warnings()

    # argument parsing
    parser = argparse.ArgumentParser(description='Override/hide vulnerabilities for a given component in the form component@componentVersion')
    parser.add_argument("--debug",
                        dest="debug",
                        action="store_true",
                        help="Enable debug logging")
    parser.add_argument("--no-image-check",
                        dest="no_image_check",
                        action="store_true",
                        help="Disable automatic image checking and pulling \
                        for the RethinkCLI image.")
    parser.add_argument("--list",
                        dest="list",
                        action="store_true",
                        help="List only the vulnerabilities to override.")
    parser.add_argument("--override",
                        dest="override",
                        action="store_true",
                        help="Override the vulnerabilities via API")
    parser.add_argument("-c", "--component", type=str, required=True, 
                        dest="vul_to_override",
                        help="Name and version of the vulnerability to override")  

    parser.add_argument("-u", "--username", type=str, required=True, 
                        dest="username",
                        help="Username to access DTR node")  

    parser.add_argument("-p", "--password", type=str, required=True, 
                        dest="password",
                        help="Pasword to access DTR node")  

    parser.add_argument("-n", "--node", type=str, required=True, 
                        dest="host",
                        help="DTR host to send API requests")  

    args = parser.parse_args()
    # basic logging that matches logrus format
    fmt_string = "%(levelname)s %(message)-20s"
    fmtr = LogrusFormatter(colorize=True, fmt=fmt_string)
    logger = logging.getLogger(name=None)
    if not args.debug:
        logger.setLevel(logging.INFO)
    else:
        logger.setLevel(logging.DEBUG)
    hdlr = logging.StreamHandler(sys.stdout)
    hdlr.setFormatter(fmtr)
    logger.addHandler(hdlr)
    # Check for a rethinkcli image
    if not args.no_image_check:
        check_for_rethinkcli()
    
    overrideVulnerabilities(args.vul_to_override, args.host, args.username, args.password, args.list, args.override)

    sys.exit(0)
Exemplo n.º 3
0
    def test_format(self, mock_format):
        formatter = LogrusFormatter()
        # Mocking logging.Formatter.format

        def format_effect(formatter, record):
            return formatter._fmt % record.__dict__
        mock_format.side_effect = format_effect
        # Mocking LogRecord
        mock_record = mock.Mock(spec='logging.LogRecord')

        # LogRecord attributes
        str_attrs = ["asctime", "filename", "funcName", "levelno", "module",
                     "message", "name", "pathname", "processName", "threadName"]
        float_attrs = ["lineno", "msecs", "process", "relativeCreated",
                       "thread"]
        # Test string attributes without color
        for att in str_attrs:
            mock_record.reset_mock()
            mock_record.created = int(time.time())
            mock_record.levelname = "INFO"
            formatter._fmt = "%({0})s".format(att)
            setattr(mock_record, att, "test")
            self.assertEqual(formatter.format(
                record=mock_record), "{0}=test".format(att))
            mock_format.assert_called_with(formatter, mock_record)
        # Test float attributes without color
        for att in float_attrs:
            mock_record.reset_mock()
            mock_record.created = int(time.time())
            mock_record.levelname = "INFO"
            formatter._fmt = "%({0})s".format(att)
            setattr(mock_record, att, 1.1)
            self.assertEqual(formatter.format(
                record=mock_record), "{0}=1.1".format(att))
            mock_format.assert_called_with(formatter, mock_record)
        # Test colors
        color_formatter = LogrusFormatter(True)
        levels = ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']
        for lvl in levels:
            mock_record.reset_mock()
            mock_record.created = int(time.time())
            mock_record.levelname = lvl
            mock_record.message = "test"
            log = color_formatter.format(record=mock_record)
            self.assertEqual(
                "\033[{0}mmessage\033[0m=test\033[0m".format(30 + COLORS[lvl]),
                log)
Exemplo n.º 4
0
def main():
    # Argument parsing
    parser = argparse.ArgumentParser(description='Comments on lotsa stuff \
    at the same time.')
    parser.add_argument("-g",
                        "--github-repo",
                        dest="github_repo",
                        required=True,
                        help="The docker/repository within GitHub, for \
                        example 'docker/escalation'")
    parser.add_argument("-j",
                        "--jira-repo",
                        dest="jira_repo",
                        required=True,
                        help="The Jira repository name to link the GitHub \
                        issues comments to, for example 'FIELD'")
    parser.add_argument("-c",
                        "--issue-count",
                        dest="issue_count",
                        help="Set the number of issues in the given Jira \
                        repository. If none is given a value of 1000 will \
                        be used.")
    parser.add_argument("--debug",
                        dest="debug",
                        action="store_true",
                        help="Enable debug logging")
    args = parser.parse_args()
    # Basic logging that matches logrus format
    fmt_string = "%(levelname)s %(message)-20s"
    fmtr = LogrusFormatter(colorize=True, fmt=fmt_string)
    logger = logging.getLogger(name=None)
    if not args.debug:
        logger.setLevel(logging.INFO)
    else:
        logger.setLevel(logging.DEBUG)
    hdlr = logging.StreamHandler(sys.stdout)
    hdlr.setFormatter(fmtr)
    logger.addHandler(hdlr)
    # Validate given arguments
    gh_repo = args.github_repo.split("/")
    if not len(gh_repo[0]) > 0 and len(gh_repo[1]) > 0:
        logger.error(
            "Given GitHub repo: {0} is not a valid org/repository".format(
                gh_repo))
        sys.exit(1)
    if args.issue_count:
        max_range = int(args.issue_count)
    else:
        max_range = 1000
    generateComments(args.github_repo, args.jira_repo, max_range)
    sys.exit(0)
Exemplo n.º 5
0
def main():
    # argument parsing
    parser = argparse.ArgumentParser(description='Clean corrupted scanning \
    metadata from Docker Trusted Registry 2.5.  Not intended for use on other \
    DTR versions.')
    parser.add_argument("--debug",
                        dest="debug",
                        action="store_true",
                        help="Enable debug logging")
    parser.add_argument("--no-image-check",
                        dest="no_image_check",
                        action="store_true",
                        help="Disable automatic image checking and pulling \
                        for the RethinkCLI image.")
    args = parser.parse_args()
    # basic logging that matches logrus format
    fmt_string = "%(levelname)s %(message)-20s"
    fmtr = LogrusFormatter(colorize=True, fmt=fmt_string)
    logger = logging.getLogger(name=None)
    if not args.debug:
        logger.setLevel(logging.INFO)
    else:
        logger.setLevel(logging.DEBUG)
    hdlr = logging.StreamHandler(sys.stdout)
    hdlr.setFormatter(fmtr)
    logger.addHandler(hdlr)
    # Check for a rethinkcli image
    if not args.no_image_check:
        check_for_rethinkcli()
    # Run probe/clean functions
    probe()
    clean_result = clean()
    if clean_result is 1:
        logging.warn(
            "All potentially corrupted data has already been cleaned either manually or in a prior run of this tool, exiting"
        )
    if clean_result is 2:
        logging.warn(
            "Some potentially corrupted data had already been cleaned, but newly corrupted data was found and cleaned"
        )
    if clean_result is 0:
        logging.info("Complete")
    sys.exit(0)
Exemplo n.º 6
0
def logger_handler():
    # Use the package:  https://github.com/velp/logrus-formatter
    # Init formatter
    fmt_string = "%(levelname)s %(message)-20s %(filename)s %(lineno)s %(datetime)s"
    fmtr = LogrusFormatter(colorize=True, fmt=fmt_string)
    # Create logger
    logger = logging.getLogger('example')
    logger.setLevel(logging.DEBUG)
    # Add handler
    hdlr = logging.StreamHandler(sys.stdout)
    hdlr.setFormatter(fmtr)
    logger.addHandler(hdlr)
    # Example logging
    logger.debug("debug message")
    logger.info("info message")
    logger.warning("warning message")
    logger.error("error message")
    logger.critical("critical message")
    return logger
Exemplo n.º 7
0
 def test_init_formatter(self, mock_init):
     formatter = LogrusFormatter()
     self.assertTrue(mock_init.called)
     self.assertEqual(formatter.colorize, False)