sfn 3.0.32 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,61 @@
1
+ module Sfn
2
+ class Error < StandardError
3
+ # @return [Integer] exit code to report
4
+ attr_reader :exit_code
5
+ # @return [Exception, nil] original exception
6
+ attr_reader :original
7
+
8
+ # Exit code used when no custom code provided
9
+ DEFAULT_EXIT_CODE = 1
10
+
11
+ def self.exit_code(c = nil)
12
+ if c || !defined?(@exit_code)
13
+ @exit_code = c.to_i != 0 ? c : DEFAULT_EXIT_CODE
14
+ end
15
+ @exit_code
16
+ end
17
+
18
+ def self.error_msg(m = nil)
19
+ if m || !defined?(@error_msg)
20
+ @error_msg = m
21
+ end
22
+ @error_msg
23
+ end
24
+
25
+ def initialize(*args)
26
+ opts = args.detect { |a| a.is_a?(Hash) } || {}
27
+ opts = opts.to_smash
28
+ msg = args.first.is_a?(String) ? args.first : self.class.error_msg
29
+ super(msg)
30
+ @exit_code = opts.fetch(:exit_code, self.class.exit_code).to_i
31
+ if opts[:original]
32
+ if opts[:original].is_a?(Exception)
33
+ @original = opts[:original]
34
+ else
35
+ raise TypeError.new "Expected `Exception` type in `:original` " \
36
+ "option but received `#{opts[:original].class}`"
37
+ end
38
+ end
39
+ end
40
+
41
+ class InteractionDisabled < Error
42
+ error_msg "Interactive prompting is disabled"
43
+ exit_code 2
44
+ end
45
+
46
+ class StackNotFound < Error
47
+ error_msg "Failed to locate requested stack"
48
+ exit_code 3
49
+ end
50
+
51
+ class StackPlanNotFound < Error
52
+ error_msg "Failed to locate requested stack plan"
53
+ exit_code 4
54
+ end
55
+
56
+ class StackStateIncomplete < Error
57
+ error_msg "Stack did not reach a successful completion state"
58
+ exit_code 5
59
+ end
60
+ end
61
+ end
@@ -1,4 +1,4 @@
1
1
  module Sfn
2
2
  # Current library version
3
- VERSION = Gem::Version.new("3.0.32")
3
+ VERSION = Gem::Version.new("3.1.0")
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sfn
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.32
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Roberts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-06 00:00:00.000000000 Z
11
+ date: 2018-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bogo-cli
@@ -390,7 +390,6 @@ files:
390
390
  - docs/v/highlight.min.js
391
391
  - docs/v/jquery-2.1.3.min.js
392
392
  - docs/v/loader.js
393
- - lib/chef/knife/knife_plugin_seed.rb
394
393
  - lib/sfn.rb
395
394
  - lib/sfn/api_provider.rb
396
395
  - lib/sfn/api_provider/google.rb
@@ -420,6 +419,7 @@ files:
420
419
  - lib/sfn/command/plan.rb
421
420
  - lib/sfn/command/print.rb
422
421
  - lib/sfn/command/promote.rb
422
+ - lib/sfn/command/realize.rb
423
423
  - lib/sfn/command/update.rb
424
424
  - lib/sfn/command/validate.rb
425
425
  - lib/sfn/command_module.rb
@@ -445,8 +445,10 @@ files:
445
445
  - lib/sfn/config/plan.rb
446
446
  - lib/sfn/config/print.rb
447
447
  - lib/sfn/config/promote.rb
448
+ - lib/sfn/config/realize.rb
448
449
  - lib/sfn/config/update.rb
449
450
  - lib/sfn/config/validate.rb
451
+ - lib/sfn/error.rb
450
452
  - lib/sfn/lint.rb
451
453
  - lib/sfn/lint/definition.rb
452
454
  - lib/sfn/lint/rule.rb
@@ -1,117 +0,0 @@
1
- begin
2
- kcfn = Gem::Specification.find_by_name("knife-cloudformation")
3
- $stderr.puts "[WARN]: Deprecated gem detected: #{kcfn.name} [V: #{kcfn.version}]"
4
- $stderr.puts "[WARN]: Uninstall gem to prevent any conflicts (`gem uninstall knife-cloudformation -a`)"
5
- rescue Gem::LoadError => e
6
- # ignore
7
- end
8
-
9
- unless defined?(Chef::Knife::CloudformationCreate)
10
- require "sfn"
11
- require "bogo"
12
-
13
- Chef::Config[:knife][:cloudformation] = {
14
- :options => {},
15
- :create => {},
16
- :update => {},
17
- }
18
- Chef::Config[:knife][:sparkleformation] = Chef::Config[:knife][:cloudformation]
19
-
20
- VALID_PREFIX = ["cloudformation", "sparkleformation"]
21
-
22
- Sfn::Config.constants.map do |konst|
23
- const = Sfn::Config.const_get(konst)
24
- if const.is_a?(Class) && const.ancestors.include?(Bogo::Config)
25
- const
26
- end
27
- end.compact.sort_by(&:to_s).each do |klass|
28
- VALID_PREFIX.each do |prefix|
29
- klass_name = klass.name.split("::").last
30
- command_class = "#{prefix.capitalize}#{klass_name}"
31
-
32
- knife_klass = Class.new(Chef::Knife)
33
- knife_klass.class_eval do
34
- include Bogo::AnimalStrings
35
-
36
- # Stub in names so knife will detect
37
- def self.name
38
- @name
39
- end
40
-
41
- def self.sfn_class
42
- @sfn_class
43
- end
44
-
45
- def name
46
- self.class.name
47
- end
48
-
49
- # Properly load in configurations and execute command
50
- def run
51
- knife = Chef::Config[:knife]
52
- if knife.respond_to?(:hash_dup)
53
- knife = knife.hash_dup
54
- end
55
- base = knife.to_smash
56
- keys = VALID_PREFIX.dup
57
- cmd_config = keys.unshift(keys.delete(snake(self.class.name.split("::").last).to_s.split("_").first)).map do |k|
58
- base[k]
59
- end.compact.first || {}
60
- cmd_config = cmd_config.to_smash
61
-
62
- reconfig = config.find_all do |k, v|
63
- !v.nil?
64
- end
65
- # Split up options provided multiple arguments
66
- reconfig.map! do |k, v|
67
- if v.is_a?(String) && v.include?(",")
68
- v = v.split(",").map(&:strip)
69
- end
70
- [k, v]
71
- end
72
- n_config = Smash[reconfig]
73
- cmd_config = cmd_config.deep_merge(n_config)
74
- self.class.sfn_class.new(cmd_config, name_args).execute!
75
- end
76
-
77
- # NOOP this merge as it breaks expected state
78
- def merge_configs
79
- config
80
- end
81
- end
82
- knife_klass.instance_variable_set(:@name, "Chef::Knife::#{command_class}")
83
- knife_klass.instance_variable_set(
84
- :@sfn_class,
85
- Bogo::Utility.constantize(klass.name.sub("Config", "Command"))
86
- )
87
- knife_klass.banner "knife #{prefix} #{Bogo::Utility.snake(klass_name)}"
88
-
89
- Sfn::Config.options_for(klass).each do |name, info|
90
- if info[:boolean]
91
- short = "-#{info[:short]}"
92
- long = "--[no-]#{info[:long]}"
93
- else
94
- val = "VALUE"
95
- if info[:multiple]
96
- val << "[,VALUE]"
97
- end
98
- short = "-#{info[:short]} #{val}"
99
- long = "--#{info[:long]} #{val}"
100
- end
101
- knife_klass.option(
102
- name.to_sym, {
103
- :short => short,
104
- :long => long,
105
- :boolean => info[:boolean],
106
- :default => info[:default],
107
- :description => info[:description],
108
- }
109
- )
110
- end
111
- # Set the class as a proper constant
112
- Chef::Knife.const_set(command_class, knife_klass)
113
- # Force knife to pick up as a subcommand
114
- Chef::Knife.inherited(knife_klass)
115
- end
116
- end
117
- end