sfn-parameters 0.2.4 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: d0779acdcc6b50972d76987fa3f32c743fd1e54c
4
- data.tar.gz: 6c2a45b9c401f596f24768a4bc9f03898f12bbf0
2
+ SHA256:
3
+ metadata.gz: 6402872602c46b70bbb1ce840268256a6a8c7a1e097093478603e5926a907c48
4
+ data.tar.gz: e49e01025280eedd43e763a4f0069c4df68b468ebfb75a540a672917aa6befba
5
5
  SHA512:
6
- metadata.gz: c1361a2e0391db409481f56e83dbb4f36cb8ce5a8a8df94c7f0f219201667fbe702a4e3b225526dda4376dff46f0316f8a5c491a893bb4d0c9928fdb07fa5d30
7
- data.tar.gz: 09f3d7c096fd47224e4dbc07e4ae03f44984ed308e049c7a2e22b3dbef232bf7baa67c11c8431fb869437a7df324b5cdb0b6d9f9ced68bb72fac45adc5cf4c1d
6
+ metadata.gz: 885f6c47c742135a80f27f81d761def19675ecf12411b58f490fb627f2ee4378be903ef04c95ddb9e59ae2accc3283bc915ce98de0636c063d100526093d4675
7
+ data.tar.gz: 3b341192e654d45aeac09a8221096ece01b76db70e02e7ae342f0ebc5e4adaa9780341c835f713cfc6ac4023b68908487e1cd3a42283d5c52a0f75eee1f95178
@@ -1,3 +1,7 @@
1
+ # v0.2.6
2
+ * Support all valid format types in show subcommand (#14)
3
+ * Apply parameters for all commands (#17)
4
+
1
5
  # v0.2.4
2
6
  * Include `.json` extension on temp file (#8)
3
7
  * Add support for `mappings` (#9)
data/README.md CHANGED
@@ -174,7 +174,8 @@ library. This allows defining the file in a serialization format
174
174
  ### Encryption
175
175
 
176
176
  This callback also supports encrypting stack parameter information for storage. The callback
177
- adds a `parameters` command for handling encryption/decryption.
177
+ adds a `parameters` command for handling encryption/decryption. Encryption is currently only
178
+ supported when using JSON format parameter files.
178
179
 
179
180
  #### Configuration
180
181
 
@@ -235,6 +236,12 @@ $ sfn parameters lock my-test-stack
235
236
  $ sfn parameters unlock my-test-stack
236
237
  ~~~
237
238
 
239
+ ##### Show existing values (as JSON)
240
+
241
+ ~~~
242
+ $ sfn parameters show my-test-stack
243
+ ~~~
244
+
238
245
  _NOTE: Full paths can also be used when defining parameters file._
239
246
 
240
247
  # Info
@@ -1,10 +1,9 @@
1
- require 'sfn-parameters'
1
+ require "sfn-parameters"
2
2
 
3
3
  module Sfn
4
4
  class Command
5
5
  # Parameters command
6
6
  class Parameters < Command
7
-
8
7
  include SfnParameters::Utils
9
8
  include Sfn::CommandModule::Base
10
9
 
@@ -13,21 +12,21 @@ module Sfn
13
12
  :parameters => {},
14
13
  :compile_parameters => {},
15
14
  :apply_stacks => [],
16
- :stacks => {}
15
+ :stacks => {},
17
16
  )
18
17
 
19
18
  # Execute parameters action request
20
19
  def execute!
21
20
  action, item = arguments[0].to_s, arguments[1].to_s
22
21
  ui.info "Running parameters action #{ui.color(action.to_s, :bold)}"
23
- if(respond_to?("run_action_#{action}"))
22
+ if respond_to?("run_action_#{action}")
24
23
  send("run_action_#{action}", item)
25
24
  else
26
25
  allowed_actions = public_methods.grep(/^run_action/).sort.map do |item|
27
- item.to_s.sub('run_action_', '')
26
+ item.to_s.sub("run_action_", "")
28
27
  end
29
28
  raise ArgumentError.new "Unsupported action received `#{action}`. " \
30
- "Allowed: #{allowed_actions.join(', ')}"
29
+ "Allowed: #{allowed_actions.join(", ")}"
31
30
  end
32
31
  end
33
32
 
@@ -38,14 +37,14 @@ module Sfn
38
37
  item = validate_item(item)
39
38
  ui.print " Locking #{ui.color(item, :bold)}... "
40
39
  content = load_json(File.read(item)).to_smash
41
- if(content[:sfn_parameters_lock])
42
- ui.puts ui.color('no-op', :yellow)
40
+ if content[:sfn_parameters_lock]
41
+ ui.puts ui.color("no-op", :yellow)
43
42
  ui.warn "Item is already locked! (#{item})"
44
43
  else
45
44
  thing = lock_content(content)
46
45
  val = format_json(thing)
47
46
  File.write(item, val)
48
- ui.puts ui.color('locked', :blue)
47
+ ui.puts ui.color("locked", :blue)
49
48
  end
50
49
  end
51
50
 
@@ -56,13 +55,13 @@ module Sfn
56
55
  item = validate_item(item)
57
56
  ui.print " Unlocking #{ui.color(item, :bold)}... "
58
57
  content = load_json(File.read(item)).to_smash
59
- if(content[:sfn_parameters_lock])
58
+ if content[:sfn_parameters_lock]
60
59
  content = unlock_content(content)
61
60
  content.delete(:sfn_lock_enabled)
62
61
  File.write(item, format_json(content))
63
- ui.puts ui.color('unlocked', :green)
62
+ ui.puts ui.color("unlocked", :green)
64
63
  else
65
- ui.puts ui.color('no-op', :yellow)
64
+ ui.puts ui.color("no-op", :yellow)
66
65
  ui.warn "Item is already unlocked! (#{item})"
67
66
  end
68
67
  end
@@ -72,13 +71,13 @@ module Sfn
72
71
  # @param item [String] item to lock
73
72
  def run_action_show(item)
74
73
  item = validate_item(item)
75
- content = load_json(File.read(item)).to_smash
76
- if(content[:sfn_parameters_lock])
77
- ui.print ui.color(' *', :bold)
74
+ content = Bogo::Config.new(item).data
75
+ if content[:sfn_parameters_lock]
76
+ ui.print ui.color(" *", :bold)
78
77
  ui.print " Unlocking #{ui.color(item, :bold)} for display... "
79
78
  content = unlock_content(content)
80
79
  content.delete(:sfn_lock_enabled)
81
- ui.puts ui.color('unlocked', :green)
80
+ ui.puts ui.color("unlocked", :green)
82
81
  end
83
82
  ui.puts format_json(content)
84
83
  end
@@ -87,8 +86,8 @@ module Sfn
87
86
  #
88
87
  # @param item [String] item to lock
89
88
  def run_action_create(item)
90
- unless(ENV['EDITOR'])
91
- raise ArgumentError.new '$EDITOR must be set for create/edit commands!'
89
+ unless ENV["EDITOR"]
90
+ raise ArgumentError.new "$EDITOR must be set for create/edit commands!"
92
91
  end
93
92
  begin
94
93
  item = validate_item(item)
@@ -97,26 +96,26 @@ module Sfn
97
96
  item = new_item(item)
98
97
  end
99
98
  FileUtils.mkdir_p(File.dirname(item))
100
- tmp = Bogo::EphemeralFile.new(['sfn-parameters', '.json'])
99
+ tmp = Bogo::EphemeralFile.new(["sfn-parameters", ".json"])
101
100
  content = new_item ? NEW_ITEM_DEFAULT : load_json(File.read(item)).to_smash
102
- if(content[:sfn_parameters_lock])
103
- ui.print ui.color(' *', :bold)
101
+ if content[:sfn_parameters_lock]
102
+ ui.print ui.color(" *", :bold)
104
103
  ui.print " Unlocking #{ui.color(item, :bold)} for edit... "
105
104
  content = unlock_content(content)
106
- ui.puts ui.color('unlocked', :green)
105
+ ui.puts ui.color("unlocked", :green)
107
106
  end
108
107
  lock_enabled = content.delete(:sfn_lock_enabled) || new_item
109
108
  tmp.write(format_json(content))
110
109
  tmp.flush
111
- system("#{ENV['EDITOR']} #{tmp.path}")
110
+ system("#{ENV["EDITOR"]} #{tmp.path}")
112
111
  content = load_json(File.read(tmp.path)).to_smash
113
- ui.print ui.color(' *', :bold)
114
- if(lock_enabled)
112
+ ui.print ui.color(" *", :bold)
113
+ if lock_enabled
115
114
  ui.print " Locking #{ui.color(item, :bold)} for storage... "
116
115
  content = lock_content(content)
117
- ui.puts ui.color('locked', :blue)
116
+ ui.puts ui.color("locked", :blue)
118
117
  else
119
- ui.puts " Storing #{ui.color(item, :bold)} for storage... #{ui.color('unlocked', :yellow)}"
118
+ ui.puts " Storing #{ui.color(item, :bold)} for storage... #{ui.color("unlocked", :yellow)}"
120
119
  end
121
120
  File.write(item, format_json(content))
122
121
  tmp.close
@@ -135,21 +134,21 @@ module Sfn
135
134
  # @param item [String]
136
135
  # @return [String]
137
136
  def new_item(item)
138
- unless(item.include?(File::SEPARATOR))
137
+ unless item.include?(File::SEPARATOR)
139
138
  prefixes = [
140
139
  config.get(:sfn_parameters, :directory),
141
- 'infrastructure',
142
- 'stacks'
140
+ "infrastructure",
141
+ "stacks",
143
142
  ].compact
144
143
  prefix = prefixes.find_all do |dir|
145
144
  File.directory?(dir)
146
145
  end
147
- if(prefix.size > 1)
146
+ if prefix.size > 1
148
147
  raise ArgumentError.new "Unable to auto-determine directory for item! Multiple directories found. " \
149
- "(detected: #{prefix.join(', ')})"
150
- elsif(prefix.empty?)
148
+ "(detected: #{prefix.join(", ")})"
149
+ elsif prefix.empty?
151
150
  raise ArgumentError.new "No existing parameter directories found. Please create required directory. " \
152
- "(checked: #{prefixes.join(', ')})"
151
+ "(checked: #{prefixes.join(", ")})"
153
152
  end
154
153
  File.join(prefix.first, "#{item}.json")
155
154
  end
@@ -161,49 +160,39 @@ module Sfn
161
160
  # @param item [String]
162
161
  # @return [String]
163
162
  def validate_item(item)
164
- if(item.to_s.empty?)
165
- raise NameError.new 'Item name is required. No item name provided.'
163
+ if item.to_s.empty?
164
+ raise NameError.new "Item name is required. No item name provided."
166
165
  end
167
- items = [
168
- item,
169
- File.join(
170
- config.fetch(
171
- :sfn_parameters, :directory, 'stacks'
172
- ),
173
- item
174
- ),
175
- File.join(
176
- config.fetch(
177
- :sfn_parameters, :directory, 'stacks'
166
+ items = [item]
167
+ ["", ".json", ".rb", ".xml", ".yaml", ".yml"].each do |extension|
168
+ items += [
169
+ File.join(
170
+ config.fetch(
171
+ :sfn_parameters, :directory, "stacks"
172
+ ),
173
+ "#{item}#{extension}"
178
174
  ),
179
- "#{item}.json"
180
- ),
181
- File.join(
182
- config.fetch(
183
- :sfn_parameters, :directory, 'infrastructure'
175
+ File.join(
176
+ config.fetch(
177
+ :sfn_parameters, :directory, "infrastructure"
178
+ ),
179
+ "#{item}#{extension}"
184
180
  ),
185
- item
186
- ),
187
- File.join(
188
- config.fetch(
189
- :sfn_parameters, :directory, 'infrastructure'
190
- ),
191
- "#{item}.json"
192
- )
193
- ].map{|item| File.expand_path(item) }.uniq
181
+ ]
182
+ end
183
+ items = items.map { |item| File.expand_path(item) }.uniq
194
184
  valid = items.find_all do |file|
195
185
  File.exist?(file)
196
186
  end
197
- if(valid.empty?)
187
+ if valid.empty?
198
188
  raise ArgumentError.new "Failed to locate item `#{item}`!"
199
- elsif(valid.size > 1)
189
+ elsif valid.size > 1
200
190
  raise ArgumentError.new "Multiple matches detected for item `#{item}`. " \
201
- "(Matches: #{valid.join(', ')})"
191
+ "(Matches: #{valid.join(", ")})"
202
192
  else
203
193
  valid.first
204
194
  end
205
195
  end
206
-
207
196
  end
208
197
  end
209
198
  end
@@ -1,15 +1,14 @@
1
- require 'sfn-parameters'
1
+ require "sfn-parameters"
2
2
 
3
3
  module Sfn
4
4
  class Callback
5
5
  # Auto load stack parameters for infrastructure pattern
6
6
  class ParametersInfrastructure < Callback
7
-
8
7
  include Sfn::Utils::JSON
9
8
  include SfnParameters::Utils
10
9
 
11
10
  # Valid file extensions for configuration file
12
- VALID_EXTENSIONS = ['.rb', '.xml', '.json', '.yaml', '.yml']
11
+ VALID_EXTENSIONS = [".rb", ".xml", ".json", ".yaml", ".yml"]
13
12
 
14
13
  # Update configuration after configuration is loaded
15
14
  #
@@ -24,7 +23,8 @@ module Sfn
24
23
  process_information_hash(content, [])
25
24
  nil
26
25
  end
27
- alias_method :after_config_create, :after_config_update
26
+
27
+ alias_method :after_config, :after_config_update
28
28
 
29
29
  protected
30
30
 
@@ -33,14 +33,14 @@ module Sfn
33
33
  # @param stack_name [String]
34
34
  # @return [Smash]
35
35
  def load_file_for(stack_name)
36
- root_path = config.fetch(:sfn_parameters, :directory, 'infrastructure')
37
- isolation_name = config.fetch(:sfn_parameters, :destination,
38
- ENV.fetch('SFN_PARAMETERS_DESTINATION', 'default')
39
- )
40
- paths = Dir.glob(File.join(root_path, "#{isolation_name}{#{VALID_EXTENSIONS.join(',')}}")).map(&:to_s)
41
- if(paths.size > 1)
42
- raise ArgumentError.new "Multiple parameter file matches encountered! (#{paths.join(', ')})"
43
- elsif(paths.empty?)
36
+ root_path = config.fetch(:sfn_parameters, :directory, "infrastructure")
37
+ isolation_name = config.fetch(
38
+ :sfn_parameters, :destination,
39
+ ENV.fetch("SFN_PARAMETERS_DESTINATION", "default"))
40
+ paths = Dir.glob(File.join(root_path, "#{isolation_name}{#{VALID_EXTENSIONS.join(",")}}")).map(&:to_s)
41
+ if paths.size > 1
42
+ raise ArgumentError.new "Multiple parameter file matches encountered! (#{paths.join(", ")})"
43
+ elsif paths.empty?
44
44
  Smash.new
45
45
  else
46
46
  unlock_content(Bogo::Config.new(paths.first).data)
@@ -52,21 +52,21 @@ module Sfn
52
52
  # @param hash [Hash]
53
53
  # @param path [Array<String>] stack name hierarchy
54
54
  # @return [TrueClass]
55
- def process_information_hash(hash, path=[])
56
- if(path.empty? && hash[:template])
55
+ def process_information_hash(hash, path = [])
56
+ if path.empty? && hash[:template]
57
57
  config[:file] = hash[:template]
58
58
  end
59
59
  hash.fetch(:parameters, {}).each do |key, value|
60
- key = [*path, key].compact.map(&:to_s).join('__')
61
- if(current_value = config[:parameters][key])
60
+ key = [*path, key].compact.map(&:to_s).join("__")
61
+ if current_value = config[:parameters][key]
62
62
  ui.debug "Not setting template parameter `#{key}`. Already set within config. (`#{current_value}`)"
63
63
  else
64
64
  config[:parameters][key] = value
65
65
  end
66
66
  end
67
67
  hash.fetch(:compile_parameters, {}).each do |key, value|
68
- key = [*path, key].compact.map(&:to_s).join('__')
69
- if(current_value = config[:compile_parameters][key])
68
+ key = [*path, key].compact.map(&:to_s).join("__")
69
+ if current_value = config[:compile_parameters][key]
70
70
  ui.debug "Not setting compile time parameter `#{key}`. Already set within config. (`#{current_value}`)"
71
71
  else
72
72
  config[:compile_parameters][key] = value
@@ -76,7 +76,7 @@ module Sfn
76
76
  process_information_hash(value, [*path, key].compact)
77
77
  end
78
78
  hash.fetch(:mappings, {}).each do |key, value|
79
- value = [*path, Bogo::Utility.camel(value)].compact.map(&:to_s).join('__')
79
+ value = [*path, Bogo::Utility.camel(value)].compact.map(&:to_s).join("__")
80
80
  config[:apply_mapping][key] = value
81
81
  end
82
82
  hash.fetch(:apply_stacks, []).each do |s_name|
@@ -1,4 +1,4 @@
1
- require 'sfn-parameters'
1
+ require "sfn-parameters"
2
2
 
3
3
  module Sfn
4
4
  class Callback
@@ -10,17 +10,16 @@ module Sfn
10
10
  # @param stack_name [String]
11
11
  # @return [Smash]
12
12
  def load_file_for(stack_name)
13
- root_path = config.fetch(:sfn_parameters, :directory, 'stacks')
14
- paths = Dir.glob(File.join(root_path, "#{stack_name}{#{VALID_EXTENSIONS.join(',')}}")).map(&:to_s)
15
- if(paths.size > 1)
16
- raise ArgumentError.new "Multiple parameter file matches encountered! (#{paths.join(', ')})"
17
- elsif(paths.empty?)
13
+ root_path = config.fetch(:sfn_parameters, :directory, "stacks")
14
+ paths = Dir.glob(File.join(root_path, "#{stack_name}{#{VALID_EXTENSIONS.join(",")}}")).map(&:to_s)
15
+ if paths.size > 1
16
+ raise ArgumentError.new "Multiple parameter file matches encountered! (#{paths.join(", ")})"
17
+ elsif (paths.empty?)
18
18
  Smash.new
19
19
  else
20
20
  unlock_content(Bogo::Config.new(paths.first).data)
21
21
  end
22
22
  end
23
-
24
23
  end
25
24
  end
26
25
  end
@@ -1,3 +1,3 @@
1
1
  module SfnParameters
2
- VERSION = Gem::Version.new('0.2.4')
2
+ VERSION = Gem::Version.new("0.2.6")
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sfn-parameters
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Roberts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-12 00:00:00.000000000 Z
11
+ date: 2018-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sfn
@@ -69,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
69
  version: '0'
70
70
  requirements: []
71
71
  rubyforge_project:
72
- rubygems_version: 2.5.1
72
+ rubygems_version: 2.7.6
73
73
  signing_key:
74
74
  specification_version: 4
75
75
  summary: SparkleFormation Parameters Callback