forked from b-b3rn4rd/awscli-console-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
console.py
68 lines (50 loc) · 1.89 KB
/
console.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
import logging
import subprocess
import os
import sys
import site
from awscli.customizations.commands import BasicCommand
def awscli_initialize(cli):
cli.register('building-command-table.main', inject_commands)
def inject_commands(command_table, session, **kwargs):
command_table['console'] = Console(session)
class Console(BasicCommand):
NAME = 'console'
DESCRIPTION = 'Authenticate to AWS console'
SYNOPSIS = 'aws console [--profile=Name] [--timeout=Timeout] [--output-only=true|false]'
ARG_TABLE = [
{
'name': 'timeout',
'default': '',
'help_text': 'Console session timeout in seconds, only for IAM user credentials'
},
{
'name': 'output-only',
'cli_type_name': 'boolean',
'default': False,
'help_text': 'Print the console url instead of opening it in the browser'
},
]
UPDATE = False
def _run_main(self, args, parsed_globals):
"""Run the command and report success."""
logging.basicConfig(level=logging.INFO)
for handler in logging.root.handlers:
handler.addFilter(logging.Filter(__name__))
self._call(args, parsed_globals)
return 0
def _call(self, options, parsed_globals):
"""Run the command."""
cmd = []
bin = os.path.join(site.USER_BASE, 'bin', 'awscli-console-plugin')
if not os.path.isfile(bin):
bin = os.path.join(sys.prefix, 'bin', 'awscli-console-plugin')
cmd.append(bin)
if parsed_globals.profile:
cmd.append('--profile={}'.format(parsed_globals.profile))
if options.output_only:
cmd.append('--output')
if options.timeout:
cmd.append('--timeout={}'.format(options.timeout))
res = subprocess.run(cmd, stdout=subprocess.PIPE, universal_newlines=True)
print(res.stdout)