__init__.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:aws-security-test 作者: mikhailadvani 项目源码 文件源码
def main():
    artifacts_dir = "artifacts"
    suite = unittest.TestSuite()

    parser = argparse.ArgumentParser()
    parser.add_argument("-c", "--config", type=str, required=True, help="Selects the config file")
    parser.add_argument("-p", "--profile", type=str, help="Specifies the boto profile to choose from  ~/.aws/config")
    parser.add_argument("--report", default='html', help="Prints test execution on the console rather than generating a HTML report", choices=['text', 'html'])
    args = parser.parse_args()

    if args.profile :
        boto3.setup_default_session(profile_name=args.profile)

    testConfig = yaml.load(open(args.config, 'r'))

    for testCategory, tests in testConfig.iteritems():
        for test, enabled in tests.iteritems():
            if enabled:
                suite.addTest(eval(testCategory+"Audit")(test))
    runner = ''

    if args.report == 'text':
        runner = unittest.TextTestRunner(verbosity=2)
    elif args.report == 'html':
        reportFile = open("test_results.html", "w")
        runner = HTMLTestRunner.HTMLTestRunner(
            stream=reportFile,
            title='aws-security-test - Report',
            verbosity=2
        )
    else:
        print 'Invalid report type'
        exit(1)

    if not os.path.exists(artifacts_dir):
        os.makedirs(artifacts_dir)

    testExecution = runner.run(suite)
    return len(testExecution.failures) + len(testExecution.errors)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号