Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Add first version of CLI #90

Merged
merged 22 commits into from
Jan 8, 2020
Merged

[FEATURE] Add first version of CLI #90

merged 22 commits into from
Jan 8, 2020

Conversation

oscarbc96
Copy link
Contributor

@oscarbc96 oscarbc96 commented Jan 2, 2020

Add first version of a CLI

Examples

Help output

$ cfripper --help
Usage: cfripper [OPTIONS] [TEMPLATES]...

  Analyse AWS Cloudformation templates passed by parameter.

Options:
  --version                       Show the version and exit.
  --resolve / --no-resolve        Resolves cloudformation intrinsic functions
                                  [default: False]
  --resolve-parameters FILENAME   JSON/YML file containing key-value pairs
                                  used for resolving CloudFormation files with
                                  templated parameters. For example, {"abc":
                                  "ABC"} will change all occurrences of
                                  {"Ref": "abc"} in the CloudFormation file to
                                  "ABC".
  --format [json|txt]             Output format  [default: txt]
  --output-folder DIRECTORY       If not present, result will be sent to
                                  stdout
  --logging [CRITICAL|FATAL|ERROR|WARN|WARNING|INFO|DEBUG|NOTSET]
                                  Logging level  [default: INFO]
  --help                          Show this message and exit.

Normal execution

$ cfripper /tmp/root.yaml /tmp/root_bypass.json --format txt
Analysing /tmp/root.yaml...
Not adding CrossAccountTrustRule failure in rootRole because no AWS Account ID was found in the config.
Valid: False
IAMRolesOverprivilegedRule: Role 'rootRole' contains an insecure permission '*' in policy 'root'
FullWildcardPrincipalRule: rootRole should not allow wildcards in principals (principal: '*')

Analysing /tmp/root_bypass.json...
Valid: True

Using resolve flag

$ cfripper /tmp/root.yaml /tmp/root_bypass.json --format txt --resolve
Analysing /tmp/root.yaml...
Not adding CrossAccountTrustRule failure in rootRole because no AWS Account ID was found in the config.
Valid: False
IAMRolesOverprivilegedRule: Role 'rootRole' contains an insecure permission '*' in policy 'root'
FullWildcardPrincipalRule: rootRole should not allow wildcards in principals (principal: '*')

Analysing /tmp/root_bypass.json...
Not adding CrossAccountTrustRule failure in rootRole because no AWS Account ID was found in the config.
Valid: False
IAMRolesOverprivilegedRule: Role 'rootRole' contains an insecure permission '*' in policy 'root'

Using json format and output-folder argument

$ cfripper /tmp/root.yaml /tmp/root_bypass.json --format json --resolve --output-folder /tmp
Analysing /tmp/root.yaml...
Not adding CrossAccountTrustRule failure in rootRole because no AWS Account ID was found in the config.
Result saved in /tmp/root.yaml.cfripper.results.json
Analysing /tmp/root_bypass.json...
Not adding CrossAccountTrustRule failure in rootRole because no AWS Account ID was found in the config.
Result saved in /tmp/root_bypass.json.cfripper.results.json

setup.py Outdated Show resolved Hide resolved
setup.py Outdated Show resolved Hide resolved
setup.py Outdated Show resolved Hide resolved
cfripper/cli.py Outdated Show resolved Hide resolved
cfripper/cli.py Outdated Show resolved Hide resolved
cfripper/cli.py Outdated Show resolved Hide resolved
cfripper/cli.py Outdated Show resolved Hide resolved
@jsoucheiron
Copy link
Member

I'm not completely sure about including click by default, this will increase the payload size if it's deployed as a lambda, we might want to make it optional. How big is click?

Copy link
Contributor

@ocrawford555 ocrawford555 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a couple of comments to review, but other than those this looks good to me, and a good addition to CFRipper! :)

cfripper/cli.py Outdated Show resolved Hide resolved
cfripper/cli.py Outdated Show resolved Hide resolved
cfripper/cli.py Outdated Show resolved Hide resolved
@jsoucheiron jsoucheiron mentioned this pull request Jan 2, 2020
setup.py Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
cfripper/cli.py Outdated Show resolved Hide resolved
mkdocs.yml Outdated Show resolved Hide resolved
cfripper/cli.py Show resolved Hide resolved
cfripper/cli.py Outdated Show resolved Hide resolved
@oscarbc96 oscarbc96 requested a review from jsoucheiron January 7, 2020 10:44
cfripper/cli.py Outdated


def save_to_file(file: Path, result: str) -> None:
file.write_text(result)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file is a keyword

cfripper/cli.py Outdated
process_template(template=template, resolve_parameters=resolve_parameters, **kwargs)

except Exception as e:
logging.exception(e)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a useful text here. The exception itself is logged regardless

@oscarbc96 oscarbc96 requested a review from jsoucheiron January 7, 2020 11:46
@oscarbc96 oscarbc96 merged commit dc6771f into master Jan 8, 2020
@oscarbc96 oscarbc96 deleted the add_cli branch January 8, 2020 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants