2
2
from __future__ import print_function
3
3
4
4
import argparse
5
+ import logging
5
6
import os
7
+ import sys
6
8
7
9
from states import *
8
10
11
+ root = logging .getLogger ()
12
+ root .setLevel (logging .INFO )
13
+
14
+ handler = logging .StreamHandler (sys .stdout )
15
+ handler .setLevel (logging .INFO )
16
+ formatter = logging .Formatter ('%(name)s - %(message)s' )
17
+ handler .setFormatter (formatter )
18
+ root .addHandler (handler )
19
+
9
20
10
21
def configure_endpoints (args ):
11
22
# configure() returns a DiffBase class (whose constructor may be wrapped in `partial` to pre-configure it)
12
23
diff_class = DiffBase .get_plugin (args .engine ).configure (args )
13
- return storage .ParameterStore (args .profile , diff_class , paths = args .path ), storage .YAMLFile (args .filename , paths = args .path )
24
+ return storage .ParameterStore (args .profile , diff_class , paths = args .paths , no_secure = args .no_secure ), \
25
+ storage .YAMLFile (args .filename , paths = args .paths , no_secure = args .no_secure , root_path = args .yaml_root )
14
26
15
27
16
28
def init (args ):
@@ -39,18 +51,12 @@ def apply(args):
39
51
def plan (args ):
40
52
"""Print a representation of the changes that would be applied to SSM Parameter Store if applied (per config in args)"""
41
53
remote , local = configure_endpoints (args )
42
- diff = remote .dry_run (local .get ())
43
-
44
- if diff .differ :
45
- print (DiffBase .describe_diff (diff .plan ))
46
- else :
47
- print ("Remote state is up to date." )
54
+ print (DiffBase .describe_diff (remote .dry_run (local .get ())))
48
55
49
56
50
57
if __name__ == "__main__" :
51
58
parser = argparse .ArgumentParser ()
52
- parser .add_argument ('-f' , help = 'local state yml file' , action = 'store' , dest = 'filename' , default = 'parameters.yml' )
53
- parser .add_argument ('--path' , '-p' , action = 'append' , help = 'filter SSM path' )
59
+ parser .add_argument ('-f' , help = 'local state yml file' , action = 'store' , dest = 'filename' )
54
60
parser .add_argument ('--engine' , '-e' , help = 'diff engine to use when interacting with SSM' , action = 'store' , dest = 'engine' , default = 'DiffResolver' )
55
61
parser .add_argument ('--profile' , help = 'AWS profile name' , action = 'store' , dest = 'profile' )
56
62
subparsers = parser .add_subparsers (dest = 'func' , help = 'commands' )
@@ -70,12 +76,29 @@ if __name__ == "__main__":
70
76
parser_apply .set_defaults (func = apply )
71
77
72
78
args = parser .parse_args ()
73
- args .path = args .path if args .path else ['/' ]
74
-
75
- if args .filename == 'parameters.yml' :
76
- if not args .profile :
77
- if 'AWS_PROFILE' in os .environ :
78
- args .filename = os .environ ['AWS_PROFILE' ] + '.yml'
79
- else :
80
- args .filename = args .profile + '.yml'
79
+
80
+ args .no_secure = os .environ .get ('SSM_NO_SECURE' , 'false' ).lower () in ['true' , '1' ]
81
+ args .yaml_root = os .environ .get ('SSM_YAML_ROOT' , '/' )
82
+ args .paths = os .environ .get ('SSM_PATHS' , None )
83
+ if args .paths is not None :
84
+ args .paths = args .paths .split (';:' )
85
+ else :
86
+ # this defaults to '/'
87
+ args .paths = args .yaml_root
88
+
89
+ # root filename
90
+ if args .filename is not None :
91
+ filename = args .filename
92
+ elif args .profile :
93
+ filename = args .profile
94
+ elif 'AWS_PROFILE' in os .environ :
95
+ filename = os .environ ['AWS_PROFILE' ]
96
+ else :
97
+ filename = 'parameters'
98
+
99
+ # remove extension (will be restored by storage classes)
100
+ if filename [- 4 :] == '.yml' :
101
+ filename = filename [:- 4 ]
102
+ args .filename = filename
103
+
81
104
args .func (args )
0 commit comments