kelbim 0.3.1.beta2 → 0.3.1.beta3

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
2
  SHA1:
3
- metadata.gz: 22165f5f97872d15363922b62b96e54f456df68e
4
- data.tar.gz: 802e0593b150f7c251a21e9f6e39094c93fd4853
3
+ metadata.gz: 946b1efa8b0465ff57a4cf034aa96718b7b634b0
4
+ data.tar.gz: e5981c6807626c6453ab6f3ac9c501e49ba9ef1f
5
5
  SHA512:
6
- metadata.gz: 44286e575763ce0906581e16ce88c1432313dc5d135412ba7472fe67827ab192dd2efb28b75429464c0443fbb6d5e647787c5683e15dc5562dc03b960bc208e5
7
- data.tar.gz: 95f1231e72915d67a10272446005a1585101f24fed8868af854774d9e6fb91bc67da3560ec3fefa1d44733b529a540adc477b776e6b0a850e74bef77ae7554ed
6
+ metadata.gz: dc80b4de4adea9d1edeee91322999e37cd7827bea630f35bbc89c62b761bea20f26586a49e85f7ca8de921024bba74cafce2dbb2559759a4d1522bbea0d1978e
7
+ data.tar.gz: 6c58a999f82449216d5d9da254d3bb23fe69e2b65dd68853e1e330d2c3966067419de1222aa35633eda5417c68b4bed106d632a26eb65f04eea8e4b05f2f2148
data/bin/kelbim~ ADDED
@@ -0,0 +1,187 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+ $: << File.expand_path("#{File.dirname __FILE__}/../lib")
4
+ require 'rubygems'
5
+ require 'fileutils'
6
+ require 'json'
7
+ require 'kelbim'
8
+ require 'optparse'
9
+ require 'rspec'
10
+ require 'kelbim/rspec-formatter'
11
+
12
+ DEFAULT_FILENAME = 'ELBfile'
13
+
14
+ mode = nil
15
+ file = DEFAULT_FILENAME
16
+ output_file = '-'
17
+ split = false
18
+
19
+ options = {
20
+ :dry_run => false,
21
+ :color => true,
22
+ :debug => false,
23
+ }
24
+
25
+ ARGV.options do |opt|
26
+ begin
27
+ access_key = nil
28
+ secret_key = nil
29
+ region = nil
30
+ profile_name = nil
31
+ credentials_path = nil
32
+
33
+ opt.on('-p', '--profile PROFILE_NAME') {|v| profile_name = v }
34
+ opt.on('' , '--credentials-path PATH') {|v| credentials_path = v }
35
+ opt.on('-k', '--access-key ACCESS_KEY') {|v| access_key = v }
36
+ opt.on('-s', '--secret-key SECRET_KEY') {|v| secret_key = v }
37
+ opt.on('-r', '--region REGION') {|v| region = v }
38
+ opt.on('-a', '--apply') { mode = :apply }
39
+ opt.on('-f', '--file FILE') {|v| file = v }
40
+ opt.on('-n', '--elb-name REGEXP') {|v| options[:elb_name] = Regexp.new(v) }
41
+ opt.on('', '--exclude-elb-name REGEXP') {|v| options[:exclude_elb_name] = Regexp.new(v) }
42
+ opt.on('', '--dry-run') { options[:dry_run] = true }
43
+ opt.on('', '--ec2s VPC_IDS', Array) {|v| options[:ec2s] = v }
44
+ opt.on('', '--without-deleting-policy') { options[:without_deleting_policy] = true }
45
+ opt.on('-e', '--export') { mode = :export }
46
+ opt.on('-o', '--output FILE') {|v| output_file = v }
47
+ opt.on('', '--split') { split = true }
48
+ opt.on('', '--split-more') { split = :more }
49
+ opt.on('-t', '--test') { mode = :test }
50
+ opt.on('', '--show-load-balancers') { mode = :show_load_balancers }
51
+ opt.on('', '--show-policies') { mode = :show_policies }
52
+ opt.on('' , '--no-color') { options[:color] = false }
53
+ opt.on('' , '--debug') { options[:debug] = true }
54
+ opt.parse!
55
+
56
+ aws_opts = {}
57
+ if access_key and secret_key
58
+ aws_opts[:access_key_id] = access_key
59
+ aws_opts[:secret_access_key] = secret_key
60
+ elsif profile_name or credentials_path
61
+ credentials_opts = {}
62
+ credentials_opts[:profile_name] = profile_name if profile_name
63
+ credentials_opts[:path] = credentials_path if credentials_path
64
+ provider = AWS::Core::CredentialProviders::SharedCredentialFileProvider.new(credentials_opts)
65
+ aws_opts[:credential_provider] = provider
66
+ elsif (access_key and !secret_key) or (!access_key and secret_key) or mode.nil?
67
+ puts opt.help
68
+ exit 1
69
+ end
70
+
71
+ aws_opts[:region] = region if region
72
+ AWS.config(aws_opts)
73
+ rescue => e
74
+ $stderr.puts("[ERROR] #{e.message}")
75
+ exit 1
76
+ end
77
+ end
78
+
79
+ String.colorize = options[:color]
80
+
81
+ if options[:debug]
82
+ AWS.config({
83
+ :http_wire_trace => true,
84
+ :logger => Kelbim::Logger.instance,
85
+ })
86
+ end
87
+
88
+ begin
89
+ logger = Kelbim::Logger.instance
90
+ logger.set_debug(options[:debug])
91
+ client = Kelbim::Client.new(options)
92
+
93
+ case mode
94
+ when :export
95
+ if split
96
+ logger.info('Export ELB')
97
+
98
+ output_file = DEFAULT_FILENAME if output_file == '-'
99
+ requires = []
100
+
101
+ client.export(options) do |exported, converter|
102
+ exported.each do |vpc, elbs|
103
+ if split == :more
104
+ elb_dir = File.join(File.dirname(output_file), "#{vpc || :classic}")
105
+ FileUtils.mkdir_p(elb_dir)
106
+
107
+ elbs.each do |name, attrs|
108
+ elb_file = File.join(elb_dir, "#{name}.elb")
109
+ requires << elb_file
110
+
111
+ logger.info(" write `#{elb_file}`")
112
+
113
+ open(elb_file, 'wb') do |f|
114
+ f.puts converter.call(vpc => {name => attrs})
115
+ end
116
+ end
117
+ else
118
+ elb_file = File.join(File.dirname(output_file), "#{vpc || :classic}.elb")
119
+ requires << elb_file
120
+
121
+ logger.info(" write `#{elb_file}`")
122
+
123
+ open(elb_file, 'wb') do |f|
124
+ f.puts converter.call(vpc => elbs)
125
+ end
126
+ end
127
+ end
128
+ end
129
+
130
+ logger.info(" write `#{output_file}`")
131
+ path_prefix = File.dirname(output_file)
132
+
133
+ open(output_file, 'wb') do |f|
134
+ requires.each do |elb_file|
135
+ elb_file.sub!(%r|\A#{Regexp.escape(path_prefix)}/|, '')
136
+ f.puts "require '#{elb_file}'"
137
+ end
138
+ end
139
+ else
140
+ if output_file == '-'
141
+ logger.info('# Export ELB')
142
+ puts client.export(options)
143
+ else
144
+ logger.info("Export ELB to `#{output_file}`")
145
+ open(output_file, 'wb') {|f| f.puts client.export(options) }
146
+ end
147
+ end
148
+ when :apply
149
+ unless File.exist?(file)
150
+ raise "No ELBfile found (looking for: #{file})"
151
+ end
152
+
153
+ msg = "Apply `#{file}` to ELB"
154
+ msg << ' (dry-run)' if options[:dry_run]
155
+ logger.info(msg)
156
+
157
+ updated = client.apply(file)
158
+
159
+ logger.info('No change'.intense_blue) unless updated
160
+ when :test
161
+ unless File.exist?(file)
162
+ raise "No ELBfile found (looking for: #{file})"
163
+ end
164
+
165
+ RSpec.configure do |config|
166
+ config.color = options[:color]
167
+ config.output_stream = $stdout # formatterをセットする前に設定…
168
+ config.formatter = Kelbim::RSpecFormatter
169
+ end
170
+
171
+ logger.info("Test `#{file}`")
172
+ client.test(file)
173
+ when :show_load_balancers
174
+ puts JSON.pretty_generate(client.load_balancers)
175
+ when :show_policies
176
+ puts JSON.pretty_generate(client.policies)
177
+ else
178
+ raise 'must not happen'
179
+ end
180
+ rescue => e
181
+ if options[:debug]
182
+ raise e
183
+ else
184
+ $stderr.puts("[ERROR] #{e.message}".red)
185
+ exit 1
186
+ end
187
+ end
@@ -1,5 +1,5 @@
1
1
  module Kelbim
2
- VERSION = "0.3.1.beta2"
2
+ VERSION = "0.3.1.beta3"
3
3
  end
4
4
 
5
5
  Version = Kelbim::VERSION
@@ -26,9 +26,11 @@ module Kelbim
26
26
  @policy.name == dsl_name_or_attrs
27
27
  else
28
28
  aws_attrs = PolicyTypes.expand(@policy.type, @policy.attributes)
29
- aws_attrs.each do |name, value|
30
- value = value[0] if value.length < 2
31
- aws_attrs[name] = value
29
+ if aws_attrs.is_a?(Hash)
30
+ aws_attrs.each do |name, value|
31
+ value = value[0] if value.length < 2
32
+ aws_attrs[name] = value
33
+ end
32
34
  end
33
35
  aws_attrs.sort == dsl_name_or_attrs.sort
34
36
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kelbim
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1.beta2
4
+ version: 0.3.1.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - winebarrel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-22 00:00:00.000000000 Z
11
+ date: 2017-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-v1
@@ -156,11 +156,13 @@ email:
156
156
  - sgwr_dts@yahoo.co.jp
157
157
  executables:
158
158
  - kelbim
159
+ - kelbim~
159
160
  extensions: []
160
161
  extra_rdoc_files: []
161
162
  files:
162
163
  - README.md
163
164
  - bin/kelbim
165
+ - bin/kelbim~
164
166
  - lib/kelbim.rb
165
167
  - lib/kelbim/client.rb
166
168
  - lib/kelbim/dsl.rb
@@ -211,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
211
213
  version: 1.3.1
212
214
  requirements: []
213
215
  rubyforge_project:
214
- rubygems_version: 2.5.2
216
+ rubygems_version: 2.5.1
215
217
  signing_key:
216
218
  specification_version: 4
217
219
  summary: Kelbim is a tool to manage ELB.