|
| 1 | +import click |
| 2 | +import sys |
| 3 | +from veracode.application import Application |
| 4 | +from veracode.sandbox import Sandbox |
| 5 | + |
| 6 | +@click.group() |
| 7 | +def app(): |
| 8 | + pass |
| 9 | + |
| 10 | + |
| 11 | +@app.command() |
| 12 | +def list(): |
| 13 | + for app in Application.list(): |
| 14 | + click.echo(app) |
| 15 | + |
| 16 | + |
| 17 | +@app.command() |
| 18 | +@click.option('--name', '-n', required=True) |
| 19 | +@click.option('--criticality', '-c', required=True, type=click.Choice( |
| 20 | + [ 'Very High', 'High', 'Medium', 'Low', 'Very Low' ])) |
| 21 | + |
| 22 | +@click.option('--sandbox', '-s') |
| 23 | +def create(name, criticality, sandbox=None): |
| 24 | + app = Application() |
| 25 | + app.name = name |
| 26 | + app.business_criticality = criticality |
| 27 | + app = app.save() |
| 28 | + if sandbox: |
| 29 | + sbx = Sandbox() |
| 30 | + sbx.name = sandbox |
| 31 | + app.sandbox = sbx |
| 32 | + |
| 33 | + |
| 34 | +@app.command() |
| 35 | +@click.option('--name', '-n', required=True, |
| 36 | + help='Name of application to update') |
| 37 | +@click.confirmation_option('--force', '-f', |
| 38 | + help='Suppress prompt before removal.', |
| 39 | + prompt='Are you sure you want to delete this application') |
| 40 | +def delete(name): |
| 41 | + app = Application(name) |
| 42 | + return app.delete() |
| 43 | + |
| 44 | + |
| 45 | +@app.command() |
| 46 | +@click.option('--name', '-n', required=True, |
| 47 | + help='Name of application to update.') |
| 48 | +@click.option('--rename', '-r', |
| 49 | + help='New name for the application.') |
| 50 | +@click.option('--criticality', '-c', type=click.Choice( |
| 51 | + [ 'Very High', 'High', 'Medium', 'Low', 'Very Low' ], |
| 52 | + case_sensitive=True), # update app to snake case so we can go -i |
| 53 | + help='New criticality for the application.') |
| 54 | + |
| 55 | +def update(name, rename=None, criticality=None): |
| 56 | + # this isn't the right way to do this, google more |
| 57 | + if not (rename or criticality): |
| 58 | + with click.Context(update) as ctx: |
| 59 | + click.echo(update.get_help(ctx)) |
| 60 | + sys.exit(('\nError: You must supply either "--rename / -r" ' |
| 61 | + 'or "--criticality / -c"')) |
| 62 | + app = Application(name) |
| 63 | + app.name = rename |
| 64 | + app.business_criticality = '{}'.format(criticality) |
| 65 | + app.save() |
| 66 | + |
| 67 | + |
| 68 | +@app.command() |
| 69 | +def scan(): |
| 70 | + click.echo('scan') |
| 71 | + |
0 commit comments