Beispiel #1
0
    def test_ls_stack(self, mocked_ls):
        cloudformation(["ls"])
        mocked_ls.assert_called_with(False, False, False, False, False, False,
                                     False)

        cloudformation(["ls", "-R", "--resource"])
        mocked_ls.assert_called_with(False, True, True, False, False, False,
                                     False)
Beispiel #2
0
    def test_update_stack(self, mocked_update):
        cloudformation(["update"])
        mocked_update.assert_called_with(False, False, False, False, False,
                                         False, False, None, False)

        cloudformation(
            ["update", "-P", "root", "-R", "us-east-1", "-l", "-x", "-E"])
        mocked_update.assert_called_with("root", "us-east-1", True, True,
                                         False, False, True, None, False)
Beispiel #3
0
    def test_create_stack(self, mocked_create):
        cloudformation(["create"])
        mocked_create.assert_called_with(False, False, False, False, False,
                                         False, None, False)

        cloudformation([
            "create", "-P", "-R", "-l", "hello.yaml", "-b", "kazhala-lol/",
            "-w", "-v"
        ])
        mocked_create.assert_called_with(True, True, "hello.yaml", False, True,
                                         False, "kazhala-lol/", True)
Beispiel #4
0
    def test_validate_stack(self, mocked_validate):
        cloudformation(["validate"])
        mocked_validate.assert_called_with(
            False,
            False,
            False,
            False,
            None,
            False,
        )

        cloudformation(
            ["validate", "-P", "root", "-R", "us-east-1", "-r", "-l"])
        mocked_validate.assert_called_with(
            "root",
            "us-east-1",
            True,
            True,
            None,
            False,
        )

        cloudformation(["validate", "-b", "kazhala-lol/", "-v"])
        mocked_validate.assert_called_with(
            False,
            False,
            False,
            False,
            "kazhala-lol/",
            True,
        )
Beispiel #5
0
    def test_changeset_stack(self, mocked_change):
        cloudformation(["changeset"])
        mocked_change.assert_called_with(
            False,
            False,
            False,
            False,
            False,
            False,
            False,
            False,
            False,
            False,
            None,
            False,
        )

        cloudformation([
            "changeset",
            "-b",
            "kazhala-lol/hello.yaml",
            "-v",
            "111111",
            "-w",
            "-x",
            "-E",
        ])
        mocked_change.assert_called_with(
            False,
            False,
            True,
            False,
            False,
            True,
            False,
            False,
            False,
            True,
            "kazhala-lol/hello.yaml",
            "111111",
        )

        cloudformation(["changeset", "-i"])
        mocked_change.assert_called_with(
            False,
            False,
            False,
            False,
            False,
            False,
            True,
            False,
            False,
            False,
            None,
            False,
        )
Beispiel #6
0
    def test_drift_stack(self, mocked_drift):
        cloudformation(["drift"])
        mocked_drift.assert_called_with(False, False, False, False, False)

        cloudformation(["drift", "-i", "-s", "-w"])
        mocked_drift.assert_called_with(False, False, True, True, True)
Beispiel #7
0
    def test_delete_stack(self, mocked_delete):
        cloudformation(["delete"])
        mocked_delete.assert_called_with(False, False, False, False)

        cloudformation(["delete", "-P", "-w", "-i", "arn:111111"])
        mocked_delete.assert_called_with(True, False, True, "arn:111111")
Beispiel #8
0
def main() -> None:
    """Entry function of the fzf.aws module."""
    try:
        parser = argparse.ArgumentParser(
            description="An interactive aws cli experience powered by fzf.",
            prog="fzfaws",
        )
        parser.add_argument(
            "-v",
            "--version",
            action="store_true",
            default=False,
            help="display the current version",
        )
        parser.add_argument(
            "--copy-config",
            dest="copy_config",
            action="store_true",
            default=False,
            help=
            "copy the configuration file to $XDG_CONFIG_HOME/fzfaws/ or $HOME/.config/fzfaws/",
        )
        subparsers = parser.add_subparsers(dest="subparser_name")
        subparsers.add_parser("cloudformation")
        subparsers.add_parser("ec2")
        subparsers.add_parser("s3")

        if len(sys.argv) < 2:
            parser.print_help()
            sys.exit(1)

        args = parser.parse_args([sys.argv[1]])

        if args.copy_config:
            copy_config()
            sys.exit(0)
        elif args.version:
            version = pkg_resources.require("fzfaws")[0].version
            print("Current fzfaws version: %s" % version)
            sys.exit(0)

        fileloader = FileLoader()
        fileloader.load_config_file()

        argument_list = get_default_args(args.subparser_name, sys.argv[2:])

        if args.subparser_name == "cloudformation":
            cloudformation(argument_list)
        elif args.subparser_name == "ec2":
            ec2(argument_list)
        elif args.subparser_name == "s3":
            s3(argument_list)

    except InvalidFileType:
        print("Selected file is not a valid file type")
        sys.exit(1)
    except SystemExit:
        raise
    except (KeyboardInterrupt, SystemError):
        sys.exit(1)
    except NoSelectionMade:
        print("No selection was made or the result was empty")
        sys.exit(1)
    except (ClientError, Exception) as e:
        print(e)
        sys.exit(1)