@@ -32,11 +32,47 @@ def after_config_update(*_)
32
32
# @param stack_name [String]
33
33
# @return [Smash]
34
34
def load_file_for ( stack_name )
35
- root_path = config . fetch ( :sfn_parameters , :directory , 'infrastructure' )
36
35
isolation_name = config . fetch ( :sfn_parameters , :destination ,
37
36
ENV . fetch ( 'SFN_PARAMETERS_DESTINATION' , 'default' )
38
37
)
39
- paths = Dir . glob ( File . join ( root_path , "#{ isolation_name } {#{ VALID_EXTENSIONS . join ( ',' ) } }" ) ) . map ( &:to_s )
38
+ unpack_file ( parameters_directory , isolation_name )
39
+ end
40
+
41
+ # Detect and expand defined definitions
42
+ #
43
+ # @param config [Smash] current configuration
44
+ # @return [Smash] expanded config
45
+ def expand_config_file ( config )
46
+ new_config = config . to_smash
47
+ definitions = config . fetch ( :definitions , [ ] )
48
+ if ( definitions . is_a? ( Array ) )
49
+ definitions . each do |def_name |
50
+ definition = load_definition ( def_name )
51
+ new_config . deep_merge! ( definition )
52
+ end
53
+ end
54
+ new_config . keys . each do |key , value |
55
+ if ( value . is_a? ( Hash ) )
56
+ new_config [ key ] = expand_config_file ( value )
57
+ end
58
+ end
59
+ new_config
60
+ end
61
+
62
+ # Define parameters directory for infrastructure based files
63
+ #
64
+ # @return [String]
65
+ def parameters_directory
66
+ config . fetch ( :sfn_parameters , :directory , 'infrastructure' )
67
+ end
68
+
69
+ # Read and unpack file
70
+ #
71
+ # @param directory [String] directory path
72
+ # @param name [String] file name without extension
73
+ # @return [Smash]
74
+ def unpack_file ( directory , name )
75
+ paths = Dir . glob ( File . join ( directory , "#{ name } {#{ VALID_EXTENSIONS . join ( ',' ) } }" ) ) . map ( &:to_s )
40
76
if ( paths . size > 1 )
41
77
raise ArgumentError . new "Multiple parameter file matches encountered! (#{ paths . join ( ', ' ) } )"
42
78
elsif ( paths . empty? )
@@ -46,6 +82,14 @@ def load_file_for(stack_name)
46
82
end
47
83
end
48
84
85
+ # Load defintion file of given name
86
+ #
87
+ # @param name [String] name of definition
88
+ # @return [Smash] definition contents
89
+ def load_definition ( name )
90
+ unpack_file ( File . join ( parameters_directory , 'definitions' ) , name )
91
+ end
92
+
49
93
# Process the given hash and set configuration values
50
94
#
51
95
# @param hash [Hash]
0 commit comments