コード例 #1
0
 def test_parse_filters_two_complex_values_tag_filter(self):
     filters = parse_filters(["Name=tags.costCenter;Value=20000:'20000:1'"])
     assert_that(filters).is_length(2)
     assert_that(filters).contains(
         ResourceTag(key="costCenter", value="20000"))
     assert_that(filters).contains(
         ResourceTag(key="costCenter", value="20000:1"))
コード例 #2
0
def main():
    # Entry point for the CLI.
    # Load commands
    parser = generate_parser()
    if len(sys.argv) <= 1:
        parser.print_help()
        return

    args = parser.parse_args()

    if args.language is None or args.language not in AVAILABLE_LANGUAGES:
        language = "en_US"
    else:
        language = args.language

    # Diagram check
    if "diagram" not in args:
        diagram = False
    else:
        diagram = args.diagram

    # defining default language to show messages
    defaultlanguage = gettext.translation("messages",
                                          localedir=dirname(__file__) +
                                          "/locales",
                                          languages=[language])
    defaultlanguage.install()
    _ = defaultlanguage.gettext

    # diagram version check
    check_diagram_version(diagram)

    # filters check
    filters: List[Filterable] = []
    if "filters" in args:
        if args.filters is not None:
            filters = parse_filters(args.filters)

    if args.command.startswith("aws"):
        command = aws_main(args)
    else:
        raise NotImplementedError("Unknown command")

    if "services" in args and args.services is not None:
        services = args.services.split(",")
    else:
        services = []

    command.run(diagram, args.verbose, services, filters)
コード例 #3
0
def main():
    # Entry point for the CLI.
    # Load commands
    parser = generate_parser()
    if len(sys.argv) <= 1:
        parser.print_help()
        return

    args = parser.parse_args()

    # Check if verbose mode is enabled
    if args.verbose:
        aws_verbose()

    if args.language is None or args.language not in AVAILABLE_LANGUAGES:
        language = "en_US"
    else:
        language = args.language

    # Diagram check
    if "diagram" not in args:
        diagram = False
    else:
        diagram = args.diagram

    # defining default language to show messages
    defaultlanguage = gettext.translation("messages",
                                          localedir=dirname(__file__) +
                                          "/locales",
                                          languages=[language])
    defaultlanguage.install()
    _ = defaultlanguage.gettext

    # diagram version check
    check_diagram_version(diagram)

    # filters check
    filters: List[Filterable] = []
    if "filters" in args:
        if args.filters is not None:
            filters = parse_filters(args.filters)

    # aws profile check
    if "region_name" not in args:
        session = generate_session(profile_name=args.profile_name,
                                   region_name=None)
    else:
        session = generate_session(profile_name=args.profile_name,
                                   region_name=args.region_name)

    session.get_credentials()
    region_name = session.region_name

    if "region_name" not in args:
        region_names = [DEFAULT_REGION]
    else:

        # checking region configuration
        check_region_profile(arg_region_name=args.region_name,
                             profile_region_name=region_name)

        # assuming region parameter precedes region configuration
        if args.region_name is not None:
            region_name = args.region_name

        # get regions
        region_names = check_region(
            region_parameter=args.region_name,
            region_name=region_name,
            session=session,
        )

    if "threshold" in args:
        if args.threshold is not None:
            if args.threshold.isdigit() is False:
                exit_critical(_("Threshold must be between 0 and 100"))
            else:
                if int(args.threshold) < 0 or int(args.threshold) > 100:
                    exit_critical(_("Threshold must be between 0 and 100"))

    if args.command == "aws-vpc":
        command = Vpc(
            vpc_id=args.vpc_id,
            region_names=region_names,
            session=session,
        )
    elif args.command == "aws-policy":
        command = Policy(
            region_names=region_names,
            session=session,
        )
    elif args.command == "aws-iot":
        command = Iot(
            thing_name=args.thing_name,
            region_names=region_names,
            session=session,
        )
    elif args.command == "aws-all":
        command = All(region_names=region_names, session=session)
    elif args.command == "aws-limit":
        command = Limit(
            region_names=region_names,
            session=session,
            threshold=args.threshold,
        )
    else:
        raise NotImplementedError("Unknown command")
    if "services" in args and args.services is not None:
        services = args.services.split(",")
    else:
        services = []
    command.run(diagram, args.verbose, services, filters)
コード例 #4
0
 def test_parse_filters_simple_tag_filter(self):
     filters = parse_filters(["Name=tags.costCenter;Value=20000"])
     assert_that(filters).is_length(1)
     assert_that(filters).contains(
         ResourceTag(key="costCenter", value="20000"))
コード例 #5
0
 def test_parse_filters_invalid_tag_value_filter(self):
     filters = parse_filters(["Name=tags.costCenter;vvv20000"])
     assert_that(filters).is_length(0)
コード例 #6
0
 def test_parse_filters_invalid_tag_name_filter(self):
     filters = parse_filters(["nn=tags.costCenter;Value=20000"])
     assert_that(filters).is_length(0)
コード例 #7
0
 def test_parse_filters_wrong_filter(self):
     filters = parse_filters(["Name=wrong;Value=value"])
     assert_that(filters).is_length(0)
コード例 #8
0
 def test_parse_filters_type_filter(self):
     filters = parse_filters(["Name=type;Value=aws_lambda_function"])
     assert_that(filters).is_length(1)
     assert_that(filters).contains(ResourceType(type="aws_lambda_function"))
コード例 #9
0
 def test_parse_filters_two_values_tag_filter(self):
     filters = parse_filters(["Name=tags.costCenter;Value=20000:20001"])
     assert_that(filters).is_length(2)
     assert_that(filters).contains(Filterable(key="costCenter", value="20000"))
     assert_that(filters).contains(Filterable(key="costCenter", value="20001"))