Skip to content
This repository has been archived by the owner on May 26, 2021. It is now read-only.

Commit

Permalink
Merge pull request #2 from kazhala/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
kazhala committed Aug 15, 2020
2 parents 56e424b + f41f2d7 commit a0d225b
Show file tree
Hide file tree
Showing 34 changed files with 1,978 additions and 816 deletions.
17 changes: 10 additions & 7 deletions fzfaws/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
Typical usage example:
fzfaws <command> --options
"""

import argparse
import os
from pathlib import Path
Expand All @@ -15,6 +14,7 @@

from fzfaws.cloudformation.main import cloudformation
from fzfaws.ec2.main import ec2
from fzfaws.lambdaf.main import lambdaf
from fzfaws.s3.main import s3
from fzfaws.utils import FileLoader, get_default_args
from fzfaws.utils.exceptions import InvalidFileType, NoSelectionMade
Expand Down Expand Up @@ -45,6 +45,7 @@ def main() -> None:
subparsers.add_parser("cloudformation")
subparsers.add_parser("ec2")
subparsers.add_parser("s3")
subparsers.add_parser("lambda")

if len(sys.argv) < 2:
parser.print_help()
Expand All @@ -65,12 +66,14 @@ def main() -> None:

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)
actions = {
"cloudformation": cloudformation,
"ec2": ec2,
"s3": s3,
"lambda": lambdaf,
}

actions[args.subparser_name](argument_list)

except InvalidFileType:
print("Selected file is not a valid file type")
Expand Down
15 changes: 9 additions & 6 deletions fzfaws/cloudformation/changeset_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
import json
from typing import Any, Dict, Union

from PyInquirer import prompt

from fzfaws.cloudformation import Cloudformation
from fzfaws.cloudformation.helper import get_stack_name
from fzfaws.cloudformation.update_stack import update_stack
from fzfaws.utils import Pyfzf, get_confirmation
from fzfaws.utils.exceptions import NoNameEntered
from fzfaws.utils import Pyfzf, get_confirmation, prompt_style


def describe_changes(cloudformation: Cloudformation, changeset_name: str) -> None:
Expand Down Expand Up @@ -123,10 +125,11 @@ def changeset_stack(
)

else:
changeset_name = input("Enter name of this changeset: ")
if not changeset_name:
raise NoNameEntered("No changeset name specified")
changeset_description = input("Description: ")
changeset_name = get_stack_name(message="ChangeSetName")
questions = [{"type": "input", "message": "Description", "name": "answer"}]
result = prompt(questions, style=prompt_style)
changeset_description = result.get("answer", "")

# since is almost same operation as update stack
# let update_stack handle it, but return update details instead of execute
cloudformation_args = update_stack(
Expand Down
40 changes: 28 additions & 12 deletions fzfaws/cloudformation/cloudformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@
import re
import sys
from typing import Any, Callable, Dict, Generator, List, Tuple, Union
from PyInquirer import prompt

from fzfaws.utils import BaseSession, Pyfzf, Spinner, get_confirmation
from fzfaws.utils.util import search_dict_in_list
from fzfaws.utils import prompt_style
from fzfaws.utils import (
BaseSession,
Pyfzf,
Spinner,
get_confirmation,
search_dict_in_list,
)


class Cloudformation(BaseSession):
Expand Down Expand Up @@ -160,17 +167,26 @@ def _get_capabilities(self, message: str = "") -> List[str]:
:return: selected capabilities to acknowledge
:rtype: List[str]
"""
fzf = Pyfzf()
fzf.append_fzf("CAPABILITY_IAM\n")
fzf.append_fzf("CAPABILITY_NAMED_IAM\n")
fzf.append_fzf("CAPABILITY_AUTO_EXPAND")
message += "\nPlease select the capabilities to acknowledge and proceed"
message += "\nMore information: https://docs.aws.amazon.com/AWSCloudFormation/latest/APIReference/API_CreateStack.html"
return list(
fzf.execute_fzf(
empty_allow=True, print_col=1, multi_select=True, header=message
)
print(message)
print(
"More information: https://docs.aws.amazon.com/AWSCloudFormation/latest/APIReference/API_CreateStack.html"
)
questions = [
{
"type": "checkbox",
"name": "answer",
"message": "Select the capabilities to acknowledge and proceed",
"choices": [
{"name": "CAPABILITY_IAM"},
{"name": "CAPABILITY_NAMED_IAM"},
{"name": "CAPABILITY_AUTO_EXPAND"},
],
}
]
result = prompt(questions, style=prompt_style)
if not result:
raise KeyboardInterrupt
return result.get("answer", [])

def _get_stack_generator(
self, response: List[Dict[str, Any]]
Expand Down
11 changes: 4 additions & 7 deletions fzfaws/cloudformation/create_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
from typing import Any, Dict, Optional, Union


from fzfaws.cloudformation import Cloudformation
from fzfaws.cloudformation.helper.cloudformationargs import CloudformationArgs
from fzfaws.cloudformation.helper.file_validation import (
Expand All @@ -13,7 +14,7 @@
from fzfaws.cloudformation.validate_stack import validate_stack
from fzfaws.s3 import S3
from fzfaws.utils import FileLoader, Pyfzf
from fzfaws.utils.exceptions import NoNameEntered
from fzfaws.cloudformation.helper import get_stack_name


def create_stack(
Expand Down Expand Up @@ -106,9 +107,7 @@ def construct_local_creation_args(
no_print=True,
)

stack_name: str = input("StackName: ")
if not stack_name:
raise NoNameEntered("No stack name specified")
stack_name = get_stack_name()

fileloader = FileLoader(path=local_path)
file_data: Dict[str, Any] = {}
Expand Down Expand Up @@ -185,9 +184,7 @@ def construct_s3_creation_args(
elif is_json(s3.path_list[0]):
file_type = "json"

stack_name: str = input("StackName: ")
if not stack_name:
raise NoNameEntered("No stack name specified")
stack_name = get_stack_name()

file_data: dict = s3.get_object_data(file_type)
if "Parameters" in file_data:
Expand Down
18 changes: 18 additions & 0 deletions fzfaws/cloudformation/helper/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from fzfaws.utils import StackNameValidator, prompt_style
from PyInquirer import prompt


def get_stack_name(message="StackName") -> str:
"""Get user to input the stack name."""
questions = [
{
"type": "input",
"name": "answer",
"message": message,
"validate": StackNameValidator,
}
]
result = prompt(questions, style=prompt_style)
if not result:
raise KeyboardInterrupt
return result.get("answer", "")
Loading

0 comments on commit a0d225b

Please sign in to comment.