skalera-services 0.1.0 → 0.2.0

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: 58af74bd5695dce07aefdd1cbef432a8c00624e1
4
- data.tar.gz: 73f3069de2a39e7434481fa3af35efea2c1fc698
3
+ metadata.gz: c758968620d43b811998ddda3e2792ef03560a70
4
+ data.tar.gz: 3799661c72f7b7a0bc5648f03dae68ac1ba56030
5
5
  SHA512:
6
- metadata.gz: 3931ed536abb6ff2d2b6df0e62721256b85d8ab63c8d080cc6b784a60b53b54a7c08e696ece7a107596a1693acf3b8079a7a62c8b70e5a8d2e28b16acc81a822
7
- data.tar.gz: 040e092cd683140363ee73a5157fa71ff5fcf77419f21bfbc2698366b739155f36452e71ddcd26d5f5575e5df47924cc68967dbd025f34d0dcdbd060467a9524
6
+ metadata.gz: dce29c6b934aea5ae3812ac0268de1d905daa090ca5ec525461bc49b9dd10df55b6471bc12ea9e8ee9619013fe0d1e2dd7eac0ceaa80e9e9bbed327e875f8909
7
+ data.tar.gz: 99cfe15a74c6dc3c3004d0c7c259dc5ca849ca30622413d53626d06ac6599d6712d13282b3d613855ceb8c151a9a0c75cf29f7a7d5b7a30ce35f0c31885cbe33
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.2.1
1
+ 2.2.3
data/Rakefile CHANGED
@@ -1 +1,38 @@
1
+ exec('bundle', 'exec', $PROGRAM_NAME, *ARGV) unless ENV['BUNDLE_GEMFILE']
2
+
1
3
  require 'bundler/gem_tasks'
4
+ require 'rubocop/rake_task'
5
+ require 'rspec/core/rake_task'
6
+
7
+ task default: [:spec, :rubocop]
8
+
9
+ task spec: [:'spec:unit', :'spec:integration']
10
+
11
+ def rspec_options(task)
12
+ # output xml if we are running through jenkins
13
+ return unless ENV['JENKINS_HOME']
14
+ opts = [
15
+ '--format RspecJunitFormatter',
16
+ "--out reports/#{task.name}.xml ",
17
+ '--format documentation'
18
+ ]
19
+ task.rspec_opts = opts.join(' ')
20
+ end
21
+
22
+ namespace :spec do
23
+ ENV['COVERAGE'] = 'yes'
24
+
25
+ desc 'run unit tests'
26
+ RSpec::Core::RakeTask.new(:unit) do |task|
27
+ rspec_options(task)
28
+ task.pattern = 'spec/unit/**/*_spec.rb'
29
+ end
30
+
31
+ desc 'run integration tests'
32
+ RSpec::Core::RakeTask.new(:integration) do |task|
33
+ rspec_options(task)
34
+ task.pattern = 'spec/integration/**/*_spec.rb'
35
+ end
36
+ end
37
+
38
+ RuboCop::RakeTask.new
data/bin/dummy.rb CHANGED
@@ -14,8 +14,13 @@ Skalera::Services.bootstrap(SERVICE_NAME)
14
14
  begin
15
15
  # run your stuff here...
16
16
  influx = Skalera::Services::InfluxDB.instance('metrics')
17
+ puts influx
17
18
  redis = Skalera::Services::Redis.instance
19
+ puts redis
18
20
  DB = Skalera::Services::Postgres.instance('postgres')
21
+ Skalera::Services::Credentials.for('vcenter') do |host, user, password|
22
+ puts "#{host} / #{user} / #{password}"
23
+ end
19
24
  rescue => e
20
25
  STDERR.puts("#{e.class.name}: #{e.message}")
21
26
  STDERR.puts(e.backtrace)
@@ -1,5 +1,6 @@
1
1
  require 'skalera/services/airbrake'
2
2
  require 'skalera/services/consul'
3
+ require 'skalera/services/credentials'
3
4
  require 'skalera/services/errbit'
4
5
  require 'skalera/services/influxdb'
5
6
  require 'skalera/services/postgres'
@@ -14,8 +14,13 @@ module Skalera
14
14
  rescue Diplomat::KeyNotFound
15
15
  Diplomat.put("services/#{service_name}", service_name)
16
16
  rescue Faraday::ConnectionFailed => e
17
+ # TODO: use logging
17
18
  STDERR.puts("ERROR: could not lookup host #{consul}")
18
19
  raise e
20
+ rescue Faraday::ClientError => e
21
+ # TODO: use logging
22
+ STDERR.puts("ERROR: #{e}")
23
+ raise e
19
24
  end
20
25
  end
21
26
  end
@@ -0,0 +1,39 @@
1
+ require 'diplomat'
2
+
3
+ module Skalera
4
+ module Services
5
+ class Credentials
6
+ def self.for(service_name)
7
+ creds = Diplomat::Kv.get("credentials/#{service_name}", recurse: true)
8
+
9
+ users = extract(creds, service_name, 'username')
10
+ passwords = extract(creds, service_name, 'password')
11
+
12
+ users.map do |host, username|
13
+ password = passwords[host]
14
+ if host.nil? || username.nil? || password.nil?
15
+ # TODO: use logging
16
+ STDERR.puts "host: #{host}, username: #{username}, password: '#{password}'"
17
+ next
18
+ end
19
+ yield host, username, password if block_given?
20
+ [host, username, password]
21
+ end.compact # in case there is an error
22
+ end
23
+
24
+ def self.extract(creds, key, field)
25
+ result = {}
26
+ creds.select { |c| c[:key].match(%r{/#{field}$}) }.each do |hash|
27
+ host = hash[:key].match(%r{#{key}/(.+)/#{field}})[1]
28
+ result[host] = hash[:value]
29
+ end
30
+ result
31
+ end
32
+
33
+ def self.add(service_name, host, username, password)
34
+ Diplomat::Kv.put("credentials/#{service_name}/#{host}/username", username)
35
+ Diplomat::Kv.put("credentials/#{service_name}/#{host}/password", password)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -20,6 +20,7 @@ module Skalera
20
20
  Diplomat.get(key_name(service_name))
21
21
  rescue Diplomat::KeyNotFound
22
22
  key = SecureRandom.hex(8)
23
+ # TODO: use logging
23
24
  puts "created errbit key '#{key}' for service '#{service_name}'"
24
25
  Diplomat::Kv.put(key_name(service_name), key)
25
26
  end
@@ -3,7 +3,7 @@ require 'redis'
3
3
  module Skalera
4
4
  module Services
5
5
  class Redis
6
- def self.instance(database=0)
6
+ def self.instance(database = 0)
7
7
  redis_config = Diplomat::Service.get('redis')
8
8
 
9
9
  redis = ::Redis.new(url: url(password, redis_config.Address, redis_config.ServicePort, database))
@@ -1,5 +1,5 @@
1
1
  module Skalera
2
2
  module Services
3
- VERSION = '0.1.0'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
@@ -28,4 +28,10 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency 'bundler', '~> 1'
29
29
  spec.add_development_dependency 'rake', '~> 10'
30
30
  spec.add_development_dependency 'pry', '~> 0'
31
+ spec.add_development_dependency 'rspec', '~> 3'
32
+ spec.add_development_dependency 'rubocop', '~> 0'
33
+ spec.add_development_dependency 'simplecov', '~> 0'
34
+ spec.add_development_dependency 'simplecov-json', '~> 0'
35
+ spec.add_development_dependency 'simplecov-rcov', '~> 0'
36
+ spec.add_development_dependency 'rspec_junit_formatter', '~> 0'
31
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skalera-services
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Englund
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-05 00:00:00.000000000 Z
11
+ date: 2015-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: airbrake
@@ -136,6 +136,90 @@ dependencies:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '3'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '3'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: simplecov
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: simplecov-json
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: simplecov-rcov
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: rspec_junit_formatter
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - "~>"
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - "~>"
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
139
223
  description:
140
224
  email:
141
225
  - martin@englund.nu
@@ -159,6 +243,7 @@ files:
159
243
  - lib/skalera/services.rb
160
244
  - lib/skalera/services/airbrake.rb
161
245
  - lib/skalera/services/consul.rb
246
+ - lib/skalera/services/credentials.rb
162
247
  - lib/skalera/services/errbit.rb
163
248
  - lib/skalera/services/influxdb.rb
164
249
  - lib/skalera/services/postgres.rb
@@ -185,9 +270,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
270
  version: '0'
186
271
  requirements: []
187
272
  rubyforge_project:
188
- rubygems_version: 2.4.5
273
+ rubygems_version: 2.4.5.1
189
274
  signing_key:
190
275
  specification_version: 4
191
276
  summary: Helper gem to handle services in consul.
192
277
  test_files: []
193
- has_rdoc: