-
Notifications
You must be signed in to change notification settings - Fork 0
/
igor
executable file
·241 lines (211 loc) · 7.74 KB
/
igor
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#!/usr/bin/env python3
import click
import boto3
import sys
import time
import json
import d3b_cli_igor.common, d3b_cli_igor.log_ops.app_logs, d3b_cli_igor.app_ops.ecs_deployment, d3b_cli_igor.app_ops.ecr_actions, d3b_cli_igor.deploy_ops.deploy, d3b_cli_igor.deploy_ops.generate_config, d3b_cli_igor.utils.shortcuts, d3b_cli_igor.utils.diff, d3b_cli_igor.app_ops.ecs_get_info, d3b_cli_igor.app_ops.secrets, d3b_cli_igor.utils.generate_tf
logger = d3b_cli_igor.common.get_logger(
__name__, testing_mode=False, log_format="detailed"
)
def check_creds():
sts = boto3.client('sts')
try:
sts.get_caller_identity()
logger.info("Credentials are valid.")
except Exception as e:
logger.error("Credentials are NOT valid." + str(e))
sys.exit(1)
@click.group()
def igor_cli():
pass
@click.command(name="secrets")
@click.option(
"--app",
nargs=1,
required=True,
help="Enter Application Name",
)
@click.option("--environment", nargs=1, required=True, help="Specify Environment")
@click.option("--region", default="us-east-1", nargs=1, required=True)
@click.option("--account", nargs=1, required=True, help="Specify AWS Account")
def secrets(app, environment, account, region):
check_creds()
d3b_cli_igor.app_ops.secrets.get_secrets(app, environment, account, region)
@click.command(name="accounts")
def accounts():
print(json.dumps(d3b_cli_igor.common.get_account_info(), indent=4))
@click.command(name="get-logs")
@click.option(
"--app",
nargs=1,
required=True,
help="Enter Application Name",
)
@click.option(
"--environment", nargs=1, required=True, help="Specify AWS Account Number"
)
@click.option(
"--query",
nargs=1,
default="fields @timestamp, @message | sort @timestamp desc | limit 20",
required=False,
help="Enter Query",
)
@click.option(
"--hours",
nargs=1,
default=0.5,
required=False,
help="How far back in hours you want to go",
)
def get_logs(app, environment, query, hours):
d3b_cli_igor.log_ops.app_logs.get_app_logs(app, environment, query, hours)
@click.command(name="deploy")
@click.option("--account_name", nargs=1, required=True)
@click.option("--organization", nargs=1, required=True)
@click.option("--region", nargs=1, required=True)
@click.option("--environment", nargs=1, required=True)
@click.option("--config_file", nargs=1, default="Jenkinsfile", required=False)
@click.option("--mode", type=click.Choice(['plan', 'build', 'apply', 'destroy', 'generate']), nargs=1, default="apply", required=False)
@click.option("--debug", is_flag=True, required=False)
def deploy(account_name, organization, region, environment, config_file, mode, debug):
check_creds()
d3b_cli_igor.deploy_ops.deploy.deploy(
account_name, organization, region, environment, config_file, mode, debug
)
@click.command(name="shortcuts")
@click.option("--name", nargs=1, required=False)
@click.option("--browser_type", default="", nargs=1, required=False)
@click.option("--show", is_flag=True, required=False)
def shortcuts(name, browser_type, show):
d3b_cli_igor.utils.shortcuts.browser(name, browser_type, show)
@click.command(name="check-build")
def check_build():
d3b_cli_igor.utils.shortcuts.check_build()
@click.command(name="github-open")
def github_open():
d3b_cli_igor.utils.shortcuts.github_open()
@click.command(name="onboarding")
@click.option("--role", nargs=1, required=True)
@click.option("--install_os", default="mac", nargs=1, required=False)
def onboarding(role,install_os):
d3b_cli_igor.utils.shortcuts.onboarding(role,install_os)
@click.command(name="awslogin")
def awslogin():
d3b_cli_igor.utils.shortcuts.awslogin()
@click.command(name="dev-env-tunnel")
@click.option("--environment", nargs=1, required=True)
@click.option("--cidr_block", nargs=1, default="", required=False)
def dev_env_tunnel(environment,cidr_block):
check_creds()
d3b_cli_igor.utils.shortcuts.dev_env_tunnel(environment,cidr_block)
@click.command(name="tunnel-to-host")
@click.option("--instance_id", nargs=1, required=True)
@click.option("--port", nargs=1, default="", required=True)
@click.option("--local_port", nargs=1, default="", required=True)
@click.option("--host", nargs=1, default="", required=True)
def tunnel_to_host(instance_id,port,local_port,host):
check_creds()
d3b_cli_igor.utils.shortcuts.tunnel_to_host(instance_id,port,local_port,host)
@click.command(name="diff")
@click.option(
"--file1",
nargs=1,
required=True,
help="Enter File Path For File 1",
)
@click.option(
"--file2",
nargs=1,
required=True,
help="Enter File Path For File 2",
)
def diff(file1,file2):
d3b_cli_igor.utils.diff.diff_files(file1,file2)
@click.command(name="split-files")
@click.option(
"--file_to_split",
nargs=1,
required=True,
help="Enter File Path to the File",
)
@click.option(
"--num_of_lines",
nargs=1,
required=True,
help="Enter Enter Number of line for each split file",
)
def split_files(file_to_split,num_of_lines):
d3b_cli_igor.utils.diff.split_files(file_to_split,num_of_lines)
@click.command(name="restart")
@click.option(
"--app",
nargs=1,
required=True,
help="Enter Application Name",
)
@click.option("--environment", nargs=1, required=True, help="Specify Environment")
@click.option("--account", nargs=1, required=True, help="Specify AWS Account")
def restart(app, environment, account):
check_creds()
d3b_cli_igor.app_ops.ecs_deployment.restart(app, environment, account)
@click.option(
"--repos",
nargs=1,
required=False,
help="Enter Repository Name to Cleanup(comma separated)",
)
@click.command(name="ecr_cleanup")
def ecr_cleanup(repos):
check_creds()
d3b_cli_igor.app_ops.ecr_actions.ecr_cleanup(repos.split(','))
@click.command(name="get-info")
@click.option(
"--app",
nargs=1,
required=True,
help="Enter Application Name",
)
@click.option("--environment", nargs=1, required=True, help="Specify Environment")
@click.option("--region", default="us-east-1", nargs=1, required=True)
@click.option("--account", nargs=1, required=True, help="Specify AWS Account")
def get_info(app, environment, account, region):
check_creds()
d3b_cli_igor.app_ops.ecs_get_info.get_info(app, environment, account, region)
@click.command(name="generate-tf-module-files")
@click.option('--project',nargs=1,required=True)
@click.option('--region',nargs=1,required=True)
@click.option('--account_name',nargs=1,required=True)
@click.option('--environment',nargs=1,required=True)
@click.option('--module',nargs=1,required=True)
def generate_tf_module_files(project,region,account_name,environment,module):
d3b_cli_igor.deploy_ops.generate_config.generate_tf_module_files(project,region,account_name, environment,module)
@click.command(name="generate")
@click.option('--project',nargs=1,required=True)
@click.option('--region',nargs=1,required=True)
@click.option('--account',nargs=1,required=True)
@click.option('--environment',nargs=1,required=True)
@click.option('--template',nargs=1,required=True)
def generate(project,region,account,environment,template):
d3b_cli_igor.utils.generate_tf.generate(project,region,account, environment,template)
igor_cli.add_command(get_logs)
igor_cli.add_command(accounts)
igor_cli.add_command(ecr_cleanup)
igor_cli.add_command(restart)
igor_cli.add_command(get_info)
igor_cli.add_command(secrets)
igor_cli.add_command(deploy)
igor_cli.add_command(generate_tf_module_files)
igor_cli.add_command(generate)
igor_cli.add_command(shortcuts)
igor_cli.add_command(check_build)
igor_cli.add_command(github_open)
igor_cli.add_command(onboarding)
igor_cli.add_command(awslogin)
igor_cli.add_command(dev_env_tunnel)
igor_cli.add_command(tunnel_to_host)
igor_cli.add_command(diff)
igor_cli.add_command(split_files)
if __name__ == "__main__":
igor_cli()