skalera-services 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4eb2ac00691e718c26fa79f2cc816a8eca2d46b0
4
- data.tar.gz: 52fb334e538f3f2c4a452c9701b0045554757ecf
3
+ metadata.gz: 0274e8b794d6a41f2b67f9d71df9ccfca37e6d78
4
+ data.tar.gz: 9bfcbb458fb88f1cdd96d72b217e56556855dd5e
5
5
  SHA512:
6
- metadata.gz: 4ef642048d4efabecb726fcb2846b92edcd380ae35148cba38db560d1222ecb61fa3644f4904b969298379c92621a31a7556944768234b50269ca66db621cc32
7
- data.tar.gz: f829b3ce5e65aa8233b302f4087eee1f1c0c5242db016a70d4b9009009c25ad46bb3e59398b8e647fdbb9c313428645b84525f8856df5ffd458134e1b5a7f044
6
+ metadata.gz: 4c68bd0f591322fb5d4f2de9883793ebdd01a50c7044a7d82f590a6048c4cbbae036f6ebf05545bcf4c156b1d4d443cc8a63659f53af927d4b5563b4f42cde42
7
+ data.tar.gz: 04e8f56aac5a66b9c2127398f628464c93e810a6706cedd1da3f251d3427e8629877d5c98991f023184a9067f026f85f5d4717e43c6cd3f816ae9e0bc16a98f2
@@ -1,3 +1,4 @@
1
+ require 'uri'
1
2
  require 'influxdb'
2
3
 
3
4
  module Skalera
@@ -5,15 +6,24 @@ module Skalera
5
6
  class InfluxDB
6
7
  SERVICE_NAME = 'influxdb-8086'
7
8
  def self.instance(database)
8
- influxdb_config = Diplomat::Service.get(SERVICE_NAME)
9
+ url = ENV['SKALERA_INFLUXDB_URL']
10
+ if url
11
+ uri = URI(url)
12
+ host = uri.host
13
+ port = uri.port || '8086'
14
+ user = uri.user
15
+ password = uri.password
16
+ else
17
+ influxdb_config = Diplomat::Service.get(SERVICE_NAME)
18
+ host = influxdb_config.Address
19
+ port = influxdb_config.ServicePort
20
+ user = key('user')
21
+ password = key('password')
22
+ end
9
23
 
10
- influxdb = ::InfluxDB::Client.new(database,
11
- host: influxdb_config.Address,
12
- port: influxdb_config.ServicePort,
13
- user: key('user'),
14
- password: key('password'))
15
- # does not need an at_exit, as the influx clients takes care of it
16
- influxdb
24
+ ::InfluxDB::Client.new(database, host: host, port: port, user: user, password: password)
25
+ rescue URI::InvalidURIError => e
26
+ STDERR.puts "ERROR: could not parse URL: #{e.message}"
17
27
  rescue Diplomat::KeyNotFound
18
28
  STDERR.puts "ERROR: service not found: #{SERVICE_NAME}"
19
29
  end
@@ -1,3 +1,4 @@
1
+ require 'uri'
1
2
  require 'sequel'
2
3
 
3
4
  module Skalera
@@ -5,12 +6,20 @@ module Skalera
5
6
  class Postgres
6
7
  SERVICE_NAME = 'postgres'
7
8
  def self.instance(database)
8
- postgres_config = Diplomat::Service.get(SERVICE_NAME)
9
+ if ENV['SKALERA_DB_URL']
10
+ url = ENV['SKALERA_DB_URL']
11
+ else
12
+ postgres_config = Diplomat::Service.get(SERVICE_NAME)
9
13
 
10
- host = postgres_config.Address
11
- port = postgres_config.ServicePort
14
+ uri = URI('postgres:/')
15
+ uri.host = postgres_config.Address
16
+ uri.port = postgres_config.ServicePort
17
+ uri.user = key('user')
18
+ uri.password = key('password')
19
+ uri.path = "/#{database}"
20
+ url = uri.to_s
21
+ end
12
22
 
13
- url = "postgres://#{key('user')}:#{key('password')}@#{host}:#{port}/#{database}"
14
23
  db = ::Sequel.connect(url)
15
24
  at_exit { db.disconnect }
16
25
  db
@@ -1,3 +1,4 @@
1
+ require 'uri'
1
2
  require 'redis'
2
3
 
3
4
  module Skalera
@@ -5,20 +6,29 @@ module Skalera
5
6
  class Redis
6
7
  SERVICE_NAME = 'redis'
7
8
  def self.instance(database = 0)
8
- redis_config = Diplomat::Service.get(SERVICE_NAME)
9
+ if ENV['SKALERA_REDIS_URL']
10
+ redis_url = ENV['SKALERA_REDIS_URL']
11
+ else
12
+ redis_config = Diplomat::Service.get(SERVICE_NAME)
13
+ uri = URI('redis:/')
14
+ uri.host = redis_config.Address
15
+ uri.port = redis_config.ServicePort
16
+ uri.path = "/#{database}"
17
+ if password
18
+ uri.user = 'redis' # this is not used, but URI require a user when you have a password
19
+ uri.password = password
20
+ end
9
21
 
10
- redis = ::Redis.new(url: url(password, redis_config.Address, redis_config.ServicePort, database))
22
+ redis_url = uri.to_s
23
+ end
24
+
25
+ redis = ::Redis.new(url: redis_url)
11
26
  at_exit { redis.quit }
12
27
  redis
13
28
  rescue Diplomat::KeyNotFound
14
29
  STDERR.puts "ERROR: service not found: #{SERVICE_NAME}"
15
30
  end
16
31
 
17
- def self.url(password, host, port, database)
18
- pwd = password ? "#{password}:" : ''
19
- "redis://#{pwd}#{host}:#{port}/#{database}"
20
- end
21
-
22
32
  def self.password
23
33
  Diplomat.get('redis/password')
24
34
  rescue Diplomat::KeyNotFound
@@ -1,5 +1,5 @@
1
1
  module Skalera
2
2
  module Services
3
- VERSION = '0.2.4'
3
+ VERSION = '0.2.5'
4
4
  end
5
5
  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.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Englund
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-08 00:00:00.000000000 Z
11
+ date: 2016-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: airbrake