skalera-services 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 58af74bd5695dce07aefdd1cbef432a8c00624e1
4
+ data.tar.gz: 73f3069de2a39e7434481fa3af35efea2c1fc698
5
+ SHA512:
6
+ metadata.gz: 3931ed536abb6ff2d2b6df0e62721256b85d8ab63c8d080cc6b784a60b53b54a7c08e696ece7a107596a1693acf3b8079a7a62c8b70e5a8d2e28b16acc81a822
7
+ data.tar.gz: 040e092cd683140363ee73a5157fa71ff5fcf77419f21bfbc2698366b739155f36452e71ddcd26d5f5575e5df47924cc68967dbd025f34d0dcdbd060467a9524
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .idea
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ Include:
3
+ - 'Rakefile'
4
+ Metrics/LineLength:
5
+ Max: 120
6
+ Metrics/ClassLength:
7
+ Max: 150
8
+ Metrics/MethodLength:
9
+ Max: 20
10
+ Metrics/AbcSize:
11
+ Max: 20
12
+ Documentation:
13
+ Enabled: false
@@ -0,0 +1 @@
1
+ 2.2.1
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in skalera-services.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Martin Englund
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,65 @@
1
+ # Skalera::Services
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/skalera/services`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'skalera-services'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install skalera-services
22
+
23
+ ## Usage
24
+ Here is a sample use of the skalera-services gem:
25
+
26
+ ```ruby
27
+ #!/usr/bin/env ruby
28
+
29
+ # make sure the program is invoked through bundle exec
30
+ exec('bundle', 'exec', $PROGRAM_NAME, *ARGV) unless ENV['BUNDLE_GEMFILE']
31
+
32
+ $LOAD_PATH << File.expand_path('../lib', File.dirname(__FILE__))
33
+
34
+ SERVICE_NAME = ENV['SERVICE_NAME'] || 'sample'
35
+ require 'skalera/services'
36
+
37
+ # configures consul, errbit & airbrake
38
+ Skalera::Services.bootstrap(SERVICE_NAME)
39
+
40
+ begin
41
+ # run your stuff here...
42
+ influx = Skalera::Services::InfluxDB.instance('metrics')
43
+ redis = Skalera::Services::Redis.instance
44
+ DB = Skalera::Services::Postgres.instance('postgres')
45
+ rescue => e
46
+ STDERR.puts("#{e.class.name}: #{e.message}")
47
+ STDERR.puts(e.backtrace)
48
+ Airbrake.notify_or_ignore(e, cgi_data: ENV.to_hash)
49
+ exit(1)
50
+ end
51
+ ```
52
+
53
+ ## Development
54
+
55
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
56
+
57
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
58
+
59
+ ## Contributing
60
+
61
+ 1. Fork it ( https://github.com/[my-github-username]/skalera-services/fork )
62
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
63
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
64
+ 4. Push to the branch (`git push origin my-new-feature`)
65
+ 5. Create a new Pull Request
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'skalera/services'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ require 'pry'
11
+ Pry.start
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # make sure the program is invoked through bundle exec
4
+ exec('bundle', 'exec', $PROGRAM_NAME, *ARGV) unless ENV['BUNDLE_GEMFILE']
5
+
6
+ $LOAD_PATH << File.expand_path('../lib', File.dirname(__FILE__))
7
+
8
+ SERVICE_NAME = ENV['SERVICE_NAME'] || 'sample'
9
+ require 'skalera/services'
10
+
11
+ # configures consul, errbit & airbrake
12
+ Skalera::Services.bootstrap(SERVICE_NAME)
13
+
14
+ begin
15
+ # run your stuff here...
16
+ influx = Skalera::Services::InfluxDB.instance('metrics')
17
+ redis = Skalera::Services::Redis.instance
18
+ DB = Skalera::Services::Postgres.instance('postgres')
19
+ rescue => e
20
+ STDERR.puts("#{e.class.name}: #{e.message}")
21
+ STDERR.puts(e.backtrace)
22
+ Airbrake.notify_or_ignore(e, cgi_data: ENV.to_hash)
23
+ exit(1)
24
+ end
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,19 @@
1
+ require 'skalera/services/airbrake'
2
+ require 'skalera/services/consul'
3
+ require 'skalera/services/errbit'
4
+ require 'skalera/services/influxdb'
5
+ require 'skalera/services/postgres'
6
+ require 'skalera/services/redis'
7
+ require 'skalera/services/version'
8
+
9
+ module Skalera
10
+ module Services
11
+ def bootstrap(service_name)
12
+ Skalera::Services::Consul.configure(service_name)
13
+ Skalera::Services::Errbit.configure(service_name)
14
+ Skalera::Services::Airbrake.configure(service_name)
15
+ end
16
+
17
+ module_function :bootstrap
18
+ end
19
+ end
@@ -0,0 +1,18 @@
1
+ require 'airbrake'
2
+
3
+ module Skalera
4
+ module Services
5
+ class Airbrake
6
+ def self.configure(service_name)
7
+ api_key = Errbit.api_key(service_name)
8
+ errbit_config = Errbit.config
9
+ ::Airbrake.configure do |config|
10
+ config.api_key = api_key
11
+ config.host = errbit_config.Address
12
+ config.port = errbit_config.ServicePort
13
+ config.secure = config.port == 443
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,22 @@
1
+ require 'diplomat'
2
+
3
+ module Skalera
4
+ module Services
5
+ class Consul
6
+ def self.configure(service_name)
7
+ consul = ENV['CONSUL'] || 'consul'
8
+ Diplomat.configuration.url = "http://#{consul}:8500"
9
+ token = ENV['CONSUL_ACL_TOKEN']
10
+ Diplomat.configuration.acl_token = token if token
11
+
12
+ # force a lookup just to make a connection so we can bail out early if consul id down
13
+ Diplomat.get("services/#{service_name}")
14
+ rescue Diplomat::KeyNotFound
15
+ Diplomat.put("services/#{service_name}", service_name)
16
+ rescue Faraday::ConnectionFailed => e
17
+ STDERR.puts("ERROR: could not lookup host #{consul}")
18
+ raise e
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,28 @@
1
+ require 'diplomat'
2
+ require 'securerandom'
3
+
4
+ module Skalera
5
+ module Services
6
+ class Errbit
7
+ def self.configure(service_name)
8
+ api_key(service_name)
9
+ end
10
+
11
+ def self.config
12
+ Diplomat::Service.get('errbit')
13
+ end
14
+
15
+ def self.key_name(service_name)
16
+ "#{service_name}/errbit/key"
17
+ end
18
+
19
+ def self.api_key(service_name)
20
+ Diplomat.get(key_name(service_name))
21
+ rescue Diplomat::KeyNotFound
22
+ key = SecureRandom.hex(8)
23
+ puts "created errbit key '#{key}' for service '#{service_name}'"
24
+ Diplomat::Kv.put(key_name(service_name), key)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,23 @@
1
+ require 'influxdb'
2
+
3
+ module Skalera
4
+ module Services
5
+ class InfluxDB
6
+ def self.instance(database)
7
+ influxdb_config = Diplomat::Service.get('influxdb-8086')
8
+
9
+ influxdb = ::InfluxDB::Client.new(database,
10
+ host: influxdb_config.Address,
11
+ port: influxdb_config.ServicePort,
12
+ user: key('user'),
13
+ password: key('password'))
14
+ # does not need an at_exit, as the influx clients takes care of it
15
+ influxdb
16
+ end
17
+
18
+ def self.key(key)
19
+ Diplomat.get("influxdb/#{key}")
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ require 'sequel'
2
+
3
+ module Skalera
4
+ module Services
5
+ class Postgres
6
+ def self.instance(database)
7
+ postgres_config = Diplomat::Service.get('postgres')
8
+
9
+ host = postgres_config.Address
10
+ port = postgres_config.ServicePort
11
+
12
+ url = "postgres://#{key('user')}:#{key('password')}@#{host}:#{port}/#{database}"
13
+ db = ::Sequel.connect(url)
14
+ at_exit { db.disconnect }
15
+ db
16
+ end
17
+
18
+ def self.key(key)
19
+ Diplomat.get("postgres/#{key}")
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,26 @@
1
+ require 'redis'
2
+
3
+ module Skalera
4
+ module Services
5
+ class Redis
6
+ def self.instance(database=0)
7
+ redis_config = Diplomat::Service.get('redis')
8
+
9
+ redis = ::Redis.new(url: url(password, redis_config.Address, redis_config.ServicePort, database))
10
+ at_exit { redis.quit }
11
+ redis
12
+ end
13
+
14
+ def self.url(password, host, port, database)
15
+ pwd = password ? "#{password}:" : ''
16
+ "redis://#{pwd}#{host}:#{port}/#{database}"
17
+ end
18
+
19
+ def self.password
20
+ Diplomat.get('redis/password')
21
+ rescue Diplomat::KeyNotFound
22
+ nil
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ module Skalera
2
+ module Services
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'skalera/services/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'skalera-services'
8
+ spec.version = Skalera::Services::VERSION
9
+ spec.authors = ['Martin Englund']
10
+ spec.email = ['martin@englund.nu']
11
+
12
+ spec.summary = 'Helper gem to handle services in consul.'
13
+ spec.homepage = 'http://skalera.com/'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec|features)/}) }
17
+ spec.bindir = 'bin'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'airbrake', '~> 4'
22
+ spec.add_dependency 'diplomat', '~> 0'
23
+ spec.add_dependency 'redis', '~> 3'
24
+ spec.add_dependency 'sequel', '~> 4'
25
+ spec.add_dependency 'pg', '~> 0'
26
+ spec.add_dependency 'influxdb', '~> 0'
27
+
28
+ spec.add_development_dependency 'bundler', '~> 1'
29
+ spec.add_development_dependency 'rake', '~> 10'
30
+ spec.add_development_dependency 'pry', '~> 0'
31
+ end
metadata ADDED
@@ -0,0 +1,193 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: skalera-services
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Martin Englund
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: airbrake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: diplomat
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: redis
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sequel
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pg
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: influxdb
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: bundler
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '10'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '10'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description:
140
+ email:
141
+ - martin@englund.nu
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - ".rspec"
148
+ - ".rubocop.yml"
149
+ - ".ruby-version"
150
+ - ".travis.yml"
151
+ - CODE_OF_CONDUCT.md
152
+ - Gemfile
153
+ - LICENSE.txt
154
+ - README.md
155
+ - Rakefile
156
+ - bin/console
157
+ - bin/dummy.rb
158
+ - bin/setup
159
+ - lib/skalera/services.rb
160
+ - lib/skalera/services/airbrake.rb
161
+ - lib/skalera/services/consul.rb
162
+ - lib/skalera/services/errbit.rb
163
+ - lib/skalera/services/influxdb.rb
164
+ - lib/skalera/services/postgres.rb
165
+ - lib/skalera/services/redis.rb
166
+ - lib/skalera/services/version.rb
167
+ - skalera-services.gemspec
168
+ homepage: http://skalera.com/
169
+ licenses:
170
+ - MIT
171
+ metadata: {}
172
+ post_install_message:
173
+ rdoc_options: []
174
+ require_paths:
175
+ - lib
176
+ required_ruby_version: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ required_rubygems_version: !ruby/object:Gem::Requirement
182
+ requirements:
183
+ - - ">="
184
+ - !ruby/object:Gem::Version
185
+ version: '0'
186
+ requirements: []
187
+ rubyforge_project:
188
+ rubygems_version: 2.4.5
189
+ signing_key:
190
+ specification_version: 4
191
+ summary: Helper gem to handle services in consul.
192
+ test_files: []
193
+ has_rdoc: