22from __future__ import print_function
33
44import argparse
5+ import logging
56import os
7+ import sys
68
79from states import *
810
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+
920
1021def configure_endpoints (args ):
1122 # configure() returns a DiffBase class (whose constructor may be wrapped in `partial` to pre-configure it)
1223 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 )
1426
1527
1628def init (args ):
@@ -39,18 +51,12 @@ def apply(args):
3951def plan (args ):
4052 """Print a representation of the changes that would be applied to SSM Parameter Store if applied (per config in args)"""
4153 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 ())))
4855
4956
5057if __name__ == "__main__" :
5158 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' )
5460 parser .add_argument ('--engine' , '-e' , help = 'diff engine to use when interacting with SSM' , action = 'store' , dest = 'engine' , default = 'DiffResolver' )
5561 parser .add_argument ('--profile' , help = 'AWS profile name' , action = 'store' , dest = 'profile' )
5662 subparsers = parser .add_subparsers (dest = 'func' , help = 'commands' )
@@ -70,12 +76,29 @@ if __name__ == "__main__":
7076 parser_apply .set_defaults (func = apply )
7177
7278 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+
81104 args .func (args )
0 commit comments