-
Notifications
You must be signed in to change notification settings - Fork 333
/
manage.py
executable file
·151 lines (118 loc) · 4.28 KB
/
manage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#! /usr/bin/env python
"""
Copyright 2017-present Airbnb, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
---------------------------------------------------------------------------
This script builds StreamAlert AWS infrastructure, is responsible for
deploying to AWS Lambda, and publishing production versions.
To run terraform by hand, change to the terraform directory and run:
terraform <cmd>
"""
from argparse import ArgumentParser, FileType, RawDescriptionHelpFormatter
import sys
from streamalert import __version__ as version
from streamalert_cli.config import DEFAULT_CONFIG_PATH
from streamalert_cli.runner import cli_runner, StreamAlertCLICommandRepository
from streamalert_cli.utils import (
DirectoryType,
generate_subparser,
UniqueSortedFileListAppendAction,
)
def build_parser():
"""Build the argument parser."""
# Map of top-level commands and their setup functions/description
# New top-level commands should be added to this dictionary
commands = StreamAlertCLICommandRepository.command_parsers()
description_template = """
StreamAlert v{}
Configure, test, build, and deploy StreamAlert
Available Commands:
{}
For additional help with any command above, try:
{} [command] --help
"""
parser = ArgumentParser(
formatter_class=RawDescriptionHelpFormatter,
prog=__file__
)
parser.add_argument(
'-v',
'--version',
action='version',
version=version
)
parser.add_argument(
'-d',
'--debug',
help='enable debugging logger output for all of the StreamAlert loggers',
action='store_true'
)
parser.add_argument(
'-c',
'--config-dir',
default=DEFAULT_CONFIG_PATH,
help='Path to directory containing configuration files',
type=DirectoryType()
)
parser.add_argument(
'-t',
'--terraform-file',
dest='terraform_files',
help=(
'Path to one or more additional Terraform configuration '
'files to include in this deployment'
),
action=UniqueSortedFileListAppendAction,
type=FileType('r'),
default=[]
)
parser.add_argument(
'-b',
'--build-directory',
help=(
'Path to directory to use for building StreamAlert and its infrastructure. '
'If no path is provided, a temporary directory will be used.'
),
type=str
)
# Dynamically generate subparsers, and create a 'commands' block for the prog description
command_block = []
subparsers = parser.add_subparsers(dest='command', required=True)
command_col_size = max([len(command) for command in commands]) + 10
for command in sorted(commands):
setup_subparser_func, description = commands[command]
subparser = generate_subparser(subparsers, command, description=description)
# If there are additional arguments to set for this command, call its setup function
if setup_subparser_func:
setup_subparser_func(subparser)
command_block.append(
'\t{command: <{pad}}{description}'.format(
command=command,
pad=command_col_size,
description=description
)
)
# Update the description on the top level parser
parser.description = description_template.format(
version,
'\n'.join(command_block),
__file__
)
parser.epilog = 'Issues? Please report here: https://github.com/airbnb/streamalert/issues'
return parser
def main():
"""Entry point for the CLI."""
parser = build_parser()
options = parser.parse_args()
# Exit with the result, which will be False if an error occurs, or True otherwise
return not cli_runner(options)
if __name__ == "__main__":
sys.exit(main())