proxes 0.8.4 → 0.8.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: b5c247703a4d859125efdd51491b63191c0843f5
4
- data.tar.gz: 5a1d36dced8609f6367f545a25f5f13a7ef72897
3
+ metadata.gz: 32dfc0bf135b58396f6425bab73d3c93712c8e1b
4
+ data.tar.gz: 65e8bc0358e0fb03d07d366504f462f127e4c541
5
5
  SHA512:
6
- metadata.gz: 7c0b0f03f37285547e99c7560d21ee0df1bdb3bd43dd2000633820d6d8e423bded97979705bcd4f5e6ee78d6e6c7f3aefeae62a1a5bacec08e1a0604d8666260
7
- data.tar.gz: ca62df0d37592701df2e2185d8bf4f9450dfc0a12d91c936488ca8a3a3d55d9f30ca6bff6b7f2e124a54cafbf305f50f8fc48d52762fc23a048a97ca3ada6f06
6
+ metadata.gz: b042e47673ab0b50987e9485f8263eeabc3c0989661dab8ea0ea096f9927e1765d6b393c028a0227152ad9f3c4473a07727b7f286e13aee9f7a5b20bcdc9769d
7
+ data.tar.gz: 94950e321514ba200c45ba65da960b8c2f1d31a2ec45ce199d3a3188efde2f03a90c67d1b026fcb73e810b99d0df641c7b8ef5f1a60aa8b63d460cfc5c2eaab8
data/.gitignore CHANGED
@@ -15,3 +15,4 @@
15
15
  /Gemfile.dev.lock
16
16
  proxes-*.gem
17
17
  migrations
18
+ .env
@@ -1,20 +1,28 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.4.0
5
- - 2.3.3
6
- - 2.2.6
4
+ - 2.4.0
5
+ - 2.3.3
6
+ - 2.2.6
7
7
  gemfile: Gemfile.ci
8
8
  env:
9
- - DATABASE_URL="sqlite::memory:" ELASTICSEARCH_URL="http://localhost:9200" RACK_ENV=test
9
+ - DATABASE_URL="sqlite::memory:" ELASTICSEARCH_URL="http://localhost:9200" RACK_ENV=test
10
10
  services:
11
- - elasticsearch
11
+ - elasticsearch
12
12
  before_script:
13
- - sleep 10
14
- - bundle exec rake ditty:prep
13
+ - sleep 10
14
+ - bundle exec rake ditty:prep
15
15
  before_install: gem install bundler -v 1.12.5
16
16
  addons:
17
17
  code_climate:
18
18
  repo_token: 1f562305f75e169f5f5eca3b738fee879550c98e50099c2b9cd6ae71478007a0
19
+ deploy:
20
+ provider: rubygems
21
+ api_key:
22
+ secure: WDO/FSVmUxyz8U6LJyoEEA/Gorw90VbQ8Q4rAu9+L6Lru/PftaVUlcW3ZMATjASHcVX/1KjVJlZNilgMYrV0eayudkeNjWglBozw5FxnhJntgzZAH2Fo/aepF9NHSU29A4SGtl1W0kj8zez9prYn+qcdX/8ei9YMfnP8KkQCKEUeO3/jScHqSZlYZIFI7Ft+QQbJeUTlKc1sJRC5XHG9Oz4lFfSZY0XgZMd5IJsBmwNCGisqgKxBuDEG/9KWwhqops6K6XGPvuhxd8+DFFrDSrI3HR1NsP9RrQxwFc9TnIc+Rzu/FjSF44NJgaiFKKPdZ116w5ChnpY0B59tzOyh/aCwvAl2w7usIqNkhXey0eJ/MZm4S+7l1AoVlxYVujBBl/tRt8PeqlRqjJWAnr1mu/p74cS/jyXhZbHJpNvmv5M7YJzzFIYI12el4Wm05fPo2L605g0c7+pFCW3F+HPAp5qItrjlNx3HoMNNoGDQO+057g3OeVjOivV5Vxjp9IYwZmNCD35IaLFXk+umYD4Jw047rUSGoboc0i/5k6ZYHSBrvIivvRCZNAXSbGi1nLR/lv42Chu2wRCWzMjyPgQQ4I0xGlVwu8kfIQsvPVAM3szNczl9xY8S311eBJforo5prPr6wLaEile0KLmMOai+1n0sr+exy056Z7ttBjwIwoQ=
23
+ gem: proxes
24
+ on:
25
+ tags: true
26
+ repo: EagerELK/proxes
19
27
  after_success:
20
- - bundle exec codeclimate-test-reporter
28
+ - bundle exec codeclimate-test-reporter
@@ -0,0 +1,43 @@
1
+ FROM ruby:2.4-alpine
2
+ MAINTAINER Jurgens du Toit <jurgens@datatools.io>
3
+
4
+ EXPOSE 9292
5
+ # Add your certificates to the project and uncomment the following lines to enable SSL
6
+ # COPY privkey.pem /usr/src/app
7
+ # COPY fullchain.pem /usr/src/app
8
+ # EXPOSE 9293
9
+
10
+ WORKDIR /usr/src/app
11
+ RUN apk add --update \
12
+ build-base \
13
+ libxml2-dev \
14
+ libxslt-dev \
15
+ openssh \
16
+ openssl \
17
+ openssl-dev \
18
+ postgresql-dev \
19
+ && rm -rf /var/cache/apk/* \
20
+ && mkdir /root/.ssh \
21
+ && mkdir /usr/src/app/tmp \
22
+ && mkdir /usr/src/app/logs \
23
+ && mkdir /usr/src/app/config \
24
+ && touch /var/log/cron.log \
25
+ && ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts \
26
+ && gem install bundler
27
+
28
+ COPY config.ru /usr/src/app/
29
+ COPY config/logger.yml /usr/src/app/config/
30
+ COPY config/puma.rb /usr/src/app/config/
31
+ COPY Gemfile.deploy /usr/src/app/Gemfile
32
+ COPY Gemfile.deploy.lock /usr/src/app/Gemfile.lock
33
+ COPY Rakefile /usr/src/app/
34
+ COPY startup.sh /
35
+
36
+ RUN bundle install --deployment --without=test development \
37
+ && bundle exec rake ditty:prep \
38
+ && chmod 755 /startup.sh
39
+
40
+ ENV APP_ROOT="/usr/src/app"
41
+ ENV RACK_ENV="production"
42
+
43
+ ENTRYPOINT ["/startup.sh"]
data/Gemfile.ci CHANGED
@@ -4,7 +4,8 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  gem 'codeclimate-test-reporter', '~> 1.0.0'
7
- gem 'ditty', git: 'https://github.com/EagerELK/ditty.git', branch: 'master'
7
+ #gem 'ditty', git: 'https://github.com/EagerELK/ditty.git', branch: 'master'
8
+ gem 'ditty', path: '../ditty'
8
9
  gem 'dotenv'
9
10
  gem 'rspec'
10
11
  gem 'rubocop'
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'dotenv'
4
+ gem 'pg'
5
+ gem 'proxes'
6
+ gem 'puma'
7
+ gem 'rake'
@@ -0,0 +1,124 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ activesupport (5.1.4)
5
+ concurrent-ruby (~> 1.0, >= 1.0.2)
6
+ i18n (~> 0.7)
7
+ minitest (~> 5.1)
8
+ tzinfo (~> 1.1)
9
+ backports (3.11.0)
10
+ bcrypt (3.1.11)
11
+ bcrypt-ruby (3.1.5)
12
+ bcrypt (>= 3.1.3)
13
+ concurrent-ruby (1.0.5)
14
+ ditty (0.3.2)
15
+ activesupport (>= 3)
16
+ bcrypt (~> 3.1)
17
+ haml (~> 5.0)
18
+ logger (~> 1.0)
19
+ omniauth (~> 1.0)
20
+ omniauth-identity (~> 1.0)
21
+ pundit (~> 1.0)
22
+ rack-contrib (~> 1.0)
23
+ rake (~> 12.0)
24
+ sequel (~> 4.0)
25
+ sinatra (~> 2.0)
26
+ sinatra-contrib (~> 2.0)
27
+ sinatra-flash (~> 0.3)
28
+ tilt (>= 2)
29
+ wisper (~> 2.0)
30
+ dotenv (2.2.1)
31
+ elasticsearch (6.0.0)
32
+ elasticsearch-api (= 6.0.0)
33
+ elasticsearch-transport (= 6.0.0)
34
+ elasticsearch-api (6.0.0)
35
+ multi_json
36
+ elasticsearch-transport (6.0.0)
37
+ faraday
38
+ multi_json
39
+ faraday (0.13.1)
40
+ multipart-post (>= 1.2, < 3)
41
+ haml (5.0.4)
42
+ temple (>= 0.8.0)
43
+ tilt
44
+ hashie (3.5.7)
45
+ highline (1.7.10)
46
+ i18n (0.9.1)
47
+ concurrent-ruby (~> 1.0)
48
+ logger (1.2.8)
49
+ minitest (5.11.1)
50
+ multi_json (1.13.0)
51
+ multipart-post (2.0.0)
52
+ mustermann (1.0.1)
53
+ omniauth (1.8.1)
54
+ hashie (>= 3.4.6, < 3.6.0)
55
+ rack (>= 1.6.2, < 3)
56
+ omniauth-http-basic (1.1.0)
57
+ omniauth (>= 1.0)
58
+ omniauth-identity (1.1.1)
59
+ bcrypt-ruby (~> 3.0)
60
+ omniauth (~> 1.0)
61
+ pg (1.0.0)
62
+ proxes (0.8.4)
63
+ activesupport (>= 3)
64
+ bcrypt (~> 3.1)
65
+ ditty (>= 0.2)
66
+ elasticsearch (>= 2)
67
+ haml (~> 5.0)
68
+ highline (~> 1.7)
69
+ logger (~> 1.0)
70
+ omniauth (~> 1.0)
71
+ omniauth-http-basic (~> 1.0)
72
+ omniauth-identity (~> 1.0)
73
+ pundit (~> 1.0)
74
+ rack-contrib (~> 1.0)
75
+ rake (~> 12.0)
76
+ sequel (~> 4.0)
77
+ sinatra (~> 2.0)
78
+ sinatra-contrib (~> 2.0)
79
+ sinatra-flash (~> 0.3)
80
+ tilt (>= 2)
81
+ wisper (~> 2.0)
82
+ puma (3.11.0)
83
+ pundit (1.1.0)
84
+ activesupport (>= 3.0.0)
85
+ rack (2.0.3)
86
+ rack-contrib (1.2.0)
87
+ rack (>= 0.9.1)
88
+ rack-protection (2.0.0)
89
+ rack
90
+ rake (12.3.0)
91
+ sequel (4.49.0)
92
+ sinatra (2.0.0)
93
+ mustermann (~> 1.0)
94
+ rack (~> 2.0)
95
+ rack-protection (= 2.0.0)
96
+ tilt (~> 2.0)
97
+ sinatra-contrib (2.0.0)
98
+ backports (>= 2.0)
99
+ multi_json
100
+ mustermann (~> 1.0)
101
+ rack-protection (= 2.0.0)
102
+ sinatra (= 2.0.0)
103
+ tilt (>= 1.3, < 3)
104
+ sinatra-flash (0.3.0)
105
+ sinatra (>= 1.0.0)
106
+ temple (0.8.0)
107
+ thread_safe (0.3.6)
108
+ tilt (2.0.8)
109
+ tzinfo (1.2.4)
110
+ thread_safe (~> 0.1)
111
+ wisper (2.0.0)
112
+
113
+ PLATFORMS
114
+ ruby
115
+
116
+ DEPENDENCIES
117
+ dotenv
118
+ pg
119
+ proxes
120
+ puma
121
+ rake
122
+
123
+ BUNDLED WITH
124
+ 1.16.1
data/README.md CHANGED
@@ -28,29 +28,20 @@ gem install proxes
28
28
 
29
29
  ## Usage
30
30
 
31
- 1. Add the components to your rack config file. See the included [`config.ru`](https://github.com/EagerELK/proxes/blob/master/config.ru) file for an example setup
32
- 2. Add the ProxES rake tasks to your Rakefile: `require 'proxes/rake_tasks'`
33
- 3. Set the DB connection as the `DATABASE_URL` ENV variable: `DATABASE_URL=sqlite://development.db`
34
- 4. Create and populate the DB and secret tokens:
31
+ ### As part of another project
32
+
33
+ ProxES has two [components](https://github.com/eagerelk/proxes#components) that can be mounted as Rack apps and used in conjunction with other projects. Check the supplied files on how to add proxes to another project.
35
34
 
36
- ```bash
37
- bundle exec rake proxes:prep
38
- bundle exec rake proxes:generate_tokens
39
- bundle exec rake proxes:migrate
40
- bundle exec rake proxes:seed
41
- bundle exec whenever --update-crontab
42
- ```
43
35
 
44
- 5. Create the necessary folders:
36
+ ### Docker
37
+
38
+ ProxES can be run in a Docker container:
39
+
45
40
 
46
41
  ```bash
47
- mkdir tmp
48
- mkdir logs
49
- mkdir config
42
+ docker run -e ELASTICSEARCH_URL=http://elasticsearch -e DATABASE_URL=postgres://username:password@database:5432/proxes --add-host=database:10.0.2.15 --add-host=elasticearch:10.0.2.15 eagerelk/proxes web-proxes
50
43
  ```
51
44
 
52
- 6. Start up the web app: `bundle exec rackup`
53
-
54
45
  ## Components
55
46
 
56
47
  ProxES has two main components that works together, but can be used separately
data/Rakefile CHANGED
@@ -1,15 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rake'
4
- require 'bundler/gem_tasks'
5
- require 'ditty/rake_tasks'
3
+ require 'dotenv/load'
6
4
 
5
+ require 'rake'
7
6
  require 'ditty'
8
- require 'proxes'
7
+ require 'ditty/db' if ENV['DATABASE_URL']
9
8
 
9
+ require 'ditty/components/app'
10
10
  Ditty.component :app
11
+
12
+ require 'proxes'
11
13
  Ditty.component :proxes
12
14
 
15
+ require 'ditty/rake_tasks'
16
+ require 'bundler/gem_tasks' if File.exist? 'proxes.gemspec'
17
+
13
18
  begin
14
19
  require 'rspec/core/rake_task'
15
20
  RSpec::Core::RakeTask.new(:spec)
data/config.ru CHANGED
@@ -4,38 +4,56 @@ libdir = File.expand_path(File.dirname(__FILE__) + '/lib')
4
4
  $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
5
5
 
6
6
  require 'dotenv/load'
7
- require 'proxes'
8
- require 'proxes/proxes'
9
- require 'rack/protection'
10
- ProxES::Container.plugin(:proxes)
11
7
 
8
+ # Session
12
9
  use Rack::Session::Cookie,
13
10
  key: '_ProxES_session',
11
+ path: '/',
14
12
  # :secure=>!TEST_MODE, # Uncomment if only allowing https:// access
15
13
  secret: File.read('.session_secret')
14
+
15
+ # Rack Protection
16
+ require 'rack/protection'
16
17
  use Rack::Protection::RemoteToken
17
18
  use Rack::Protection::SessionHijacking
18
19
 
19
20
  map '/_proxes' do
20
- require 'proxes/omniauth'
21
+ require 'ditty/components/app'
22
+ Ditty.component :app
21
23
 
22
- use OmniAuth::Builder do
23
- configure do |config|
24
- config.path_prefix = '/auth'
25
- config.on_failure = ProxES::App
26
- end
24
+ require 'ditty/controllers/application'
25
+ Ditty::Application.set :map_path, '/_proxes'
26
+
27
+ require 'omniauth'
28
+ require 'omniauth/identity'
29
+ OmniAuth.config.logger = Ditty::Services::Logger.instance
30
+ OmniAuth.config.on_failure = proc { |env|
31
+ OmniAuth::FailureEndpoint.new(env).redirect_to_failure
32
+ }
27
33
 
34
+ require 'ditty/controllers/main'
35
+ require 'ditty/models/identity'
36
+ use OmniAuth::Builder do
28
37
  # The identity provider is used by the App.
29
38
  provider :identity,
30
39
  fields: [:username],
31
40
  callback_path: '/auth/identity/callback',
32
- model: ProxES::Identity,
33
- on_login: ProxES::App,
34
- on_registration: ProxES::App,
41
+ model: Ditty::Identity,
42
+ on_login: Ditty::Main,
43
+ on_registration: Ditty::Main,
35
44
  locate_conditions: ->(req) { { username: req['username'] } }
36
45
  end
37
46
 
38
- run Rack::URLMap.new Ditty.routes
47
+ # Management App
48
+ require 'proxes'
49
+ Ditty.component :proxes
50
+
51
+ run Rack::URLMap.new Ditty::Components.routes
52
+ end
53
+
54
+ require 'sidekiq/web'
55
+ map '/_sidekiq' do
56
+ run Sidekiq::Web
39
57
  end
40
58
 
41
59
  map '/' do
@@ -0,0 +1,15 @@
1
+ require 'dotenv/load'
2
+
3
+ root = Dir.getwd.to_s
4
+ threads_count = Integer(ENV['MAX_THREADS'] || 5)
5
+
6
+ workers Integer(ENV['WEB_CONCURRENCY'] || 2)
7
+ pidfile "#{root}/pids/puma.pid"
8
+ state_path "#{root}/pids/puma.state"
9
+ threads threads_count, threads_count
10
+
11
+ bind 'tcp://0.0.0.0:9292'
12
+
13
+ if File.exist?('./privkey.pem') && File.exist?('./fullchain.pem')
14
+ ssl_bind '0.0.0.0', 9293, key: './privkey.pem', cert: './fullchain.pem'
15
+ end
@@ -1,13 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ditty/controllers/component'
3
+ require 'ditty/controllers/application'
4
4
  require 'proxes/policies/status_policy'
5
- require 'proxes/helpers/es'
6
- require 'pp'
5
+ require 'proxes/services/es'
7
6
 
8
7
  module ProxES
9
- class Status < Ditty::Component
10
- helpers ProxES::Helpers::ES
8
+ class Status < Ditty::Application
9
+ helpers ProxES::Services::ES
11
10
 
12
11
  def find_template(views, name, engine, &block)
13
12
  super(views, name, engine, &block) # Root
@@ -24,44 +23,80 @@ module ProxES
24
23
  checks << { text: 'Cluster Reachable', passed: true, value: health['cluster_name'] }
25
24
  checks << { text: 'Cluster Health', passed: health['status'] == 'green', value: health['status'] }
26
25
 
27
- node_stats = client.nodes.stats metric: 'os,fs,jvm'
26
+ node_stats = client.nodes.stats
27
+
28
+ master_nodes = []
29
+ data_nodes = []
30
+ ingestion_nodes = []
31
+ node_stats['nodes'].values.each do |node|
32
+ if node['roles']
33
+ master_nodes << node['name'] if node['roles'].include? 'master'
34
+ data_nodes << node['name'] if node['roles'].include? 'data'
35
+ ingestion_nodes << node['name'] if node['roles'].include? 'ingest'
36
+ elsif node['attributes']
37
+ master_nodes << node['name'] unless node['attributes']['master'] == 'false'
38
+ data_nodes << node['name'] unless node['attributes']['data'] == 'false'
39
+ ingestion_nodes << node['name'] unless node['attributes']['ingest'] == 'false'
40
+ elsif node['settings']
41
+ master_nodes << node['name'] unless node['settings']['node']['master'] == 'false'
42
+ data_nodes << node['name'] unless node['settings']['node']['data'] == 'false'
43
+ ingestion_nodes << node['name'] unless node['settings']['node']['ingest'] == 'false'
44
+ end
45
+ end
46
+ checks << {
47
+ text: 'Master Nodes',
48
+ passed: master_nodes.count > 0,
49
+ value: master_nodes.count > 0 ? master_nodes.sort : 'None'
50
+ }
51
+ checks << {
52
+ text: 'Data Nodes',
53
+ passed: data_nodes.count > 0,
54
+ value: data_nodes.count > 0 ? data_nodes.sort : 'None'
55
+ }
56
+ checks << {
57
+ text: 'Ingestion Nodes',
58
+ passed: true,
59
+ value: ingestion_nodes.count > 0 ? ingestion_nodes.sort : 'None'
60
+ }
28
61
 
29
62
  jvm_values = []
30
63
  jvm_passed = true
31
- node_stats['nodes'].each do |name, node|
32
- jvm_values << "#{name}: #{node['jvm']['mem']['heap_used_percent']}%"
64
+ node_stats['nodes'].values.each do |node|
65
+ jvm_values << "#{node['name']}: #{node['jvm']['mem']['heap_used_percent']}%"
33
66
  jvm_passed = false if node['jvm']['mem']['heap_used_percent'] > 85
34
67
  end
35
- checks << { text: 'Node JVM Heap', passed: jvm_passed, value: jvm_values }
68
+ checks << { text: 'Node JVM Heap', passed: jvm_passed, value: jvm_values.sort }
36
69
 
37
70
  fs_values = []
38
71
  fs_passed = true
39
- node_stats['nodes'].each do |name, node|
72
+ node_stats['nodes'].values.each do |node|
73
+ next if node['attributes'] && node['attributes']['data'] == 'false'
74
+ next if node['roles'] && node['roles'].include?('data') == false
40
75
  stats = node['fs']['total']
41
76
  left = stats['available_in_bytes'] / stats['total_in_bytes'].to_f * 100
42
- fs_values << "#{name}: #{'%.02f' % left}% Free"
77
+ fs_values << "#{node['name']}: #{'%.02f' % left}% Free"
43
78
  fs_passed = false if left < 10
44
79
  end
45
- checks << { text: 'Node File Systems', passed: fs_passed, value: fs_values }
80
+ checks << { text: 'Node File Systems', passed: fs_passed, value: fs_values.sort }
46
81
 
47
82
  cpu_values = []
48
83
  cpu_passed = true
49
- node_stats['nodes'].each do |name, node|
50
- cpu_values << "#{name}: #{node['os']['cpu']['percent']}"
51
- cpu_passed = false if node['os']['cpu']['percent'].to_i > 70
84
+ node_stats['nodes'].values.each do |node|
85
+ value = (node['os']['cpu_percent'] || node['os']['cpu']['percent'])
86
+ cpu_values << "#{node['name']}: #{value}"
87
+ cpu_passed = false if value.to_i > 70
52
88
  end
53
- checks << { text: 'Node CPU Usage', passed: cpu_passed, value: cpu_values }
89
+ checks << { text: 'Node CPU Usage', passed: cpu_passed, value: cpu_values.sort }
54
90
 
55
91
  memory_values = []
56
92
  memory_passed = true
57
- node_stats['nodes'].each do |name, node|
58
- memory_values << "#{name}: #{node['os']['mem']['used_percent']}"
93
+ node_stats['nodes'].values.each do |node|
94
+ memory_values << "#{node['name']}: #{node['os']['mem']['used_percent']}"
59
95
  memory_passed = false if node['os']['mem']['used_percent'].to_i >= 100
60
96
  end
61
- checks << { text: 'Node Memory Usage', passed: memory_passed, value: memory_values }
62
-
63
- rescue StandardError
64
- checks << { text: 'Cluster Reachable', passed: false}
97
+ checks << { text: 'Node Memory Usage', passed: memory_passed, value: memory_values.sort }
98
+ rescue Faraday::Error => e
99
+ checks << { text: 'Cluster Reachable', passed: false, value: e.message }
65
100
  end
66
101
 
67
102
  status checks.find { |c| c[:passed] == false } ? 500 : 200
@@ -13,6 +13,13 @@ module ProxES
13
13
  def call(env)
14
14
  http = Net::HTTP.new(backend.host, backend.port)
15
15
  http.use_ssl = true if backend.is_a? URI::HTTPS
16
+ if ENV['SSL_VERIFY_NONE'].to_i == 1
17
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
18
+ store = OpenSSL::X509::Store.new
19
+ store.set_default_paths
20
+ http.cert_store = store
21
+ end
22
+
16
23
  request = request_from(env)
17
24
  request.basic_auth backend.user, backend.password
18
25
  response = http.request(request)
@@ -47,7 +47,7 @@ module ProxES
47
47
  private
48
48
 
49
49
  def path_parts
50
- @path_parts ||= path[1..-1].split('/')
50
+ @path_parts ||= path.split('?')[0][1..-1].split('/')
51
51
  end
52
52
 
53
53
  def check_part(val)
@@ -25,7 +25,7 @@ module ProxES
25
25
  end
26
26
 
27
27
  def indices?
28
- true
28
+ %w[shards indices segments count recovery].include? type.first
29
29
  end
30
30
  end
31
31
  end
@@ -61,29 +61,28 @@ module ProxES
61
61
  error 'Elasticsearch not listening at ' + ENV['ELASTICSEARCH_URL']
62
62
  end
63
63
 
64
+ def log(request, stage)
65
+ logger.debug '============' + stage.ljust(56) + '============'
66
+ logger.debug '= ' + "Request: #{request.request_method} #{request.fullpath} (#{request.class.name})".ljust(76) + ' ='
67
+ logger.debug '= ' + "Endpoint: #{request.endpoint}".ljust(76) + ' ='
68
+ logger.debug '================================================================================'
69
+ end
70
+
64
71
  def call(env)
65
72
  @env = env
66
73
 
67
74
  request = Request.from_env(env)
68
75
  broadcast(:call_started, request)
69
76
 
70
- logger.debug '==========================BEFORE================================================'
71
- logger.debug '= ' + "Request: #{request.request_method} #{request.fullpath} (#{request.class.name})".ljust(76) + ' ='
72
- logger.debug '= ' + "Endpoint: #{request.endpoint}".ljust(76) + ' ='
73
- logger.debug '================================================================================'
74
-
77
+ log(request, 'BEFORE')
75
78
  unless env['PROXES_PASSTHROUGH']
76
79
  result = check(request)
77
80
  return result if result.is_a?(Array) # Rack Response
78
81
 
79
82
  request.index = policy_scope(request) if request.indices?
83
+ log(request, 'AFTER')
80
84
  end
81
85
 
82
- logger.debug '==========================AFTER================================================='
83
- logger.debug '= ' + "Request: #{request.request_method} #{request.fullpath} (#{request.class.name})".ljust(76) + ' ='
84
- logger.debug '= ' + "Endpoint: #{request.endpoint}".ljust(76) + ' ='
85
- logger.debug '================================================================================'
86
-
87
86
  forward request
88
87
  end
89
88
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'elasticsearch'
4
+ require 'ditty/services/logger'
5
+
6
+ module ProxES
7
+ module Services
8
+ module ES
9
+ def client
10
+ @client ||= Elasticsearch::Client.new(
11
+ url: ENV['ELASTICSEARCH_URL'],
12
+ transport_options: {
13
+ ssl: { verify: ENV['SSL_VERIFY_NONE'].to_i != 1 }
14
+ },
15
+ logger: Ditty::Services::Logger.instance
16
+ )
17
+ end
18
+
19
+ def cluster_health(level = 'cluster')
20
+ client.cluster.health level: level
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ProxES
4
- VERSION = '0.8.4'.freeze
4
+ VERSION = '0.8.5'.freeze
5
5
  end
@@ -27,6 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency 'database_cleaner'
28
28
  spec.add_development_dependency 'factory_girl'
29
29
  spec.add_development_dependency 'timecop'
30
+ spec.add_development_dependency 'webmock'
30
31
 
31
32
  spec.add_dependency 'ditty', '>= 0.2'
32
33
  spec.add_dependency 'activesupport', '>= 3'
@@ -0,0 +1,19 @@
1
+ #!/bin/sh
2
+ set -e
3
+
4
+ echo "DATABASE_URL: $DATABASE_URL"
5
+ echo "ELASTICSEARCH_URL: $ELASTICSEARCH_URL"
6
+ echo "APP_ROOT: $APP_ROOT"
7
+
8
+ if [ "$1" = 'web-proxes' ]
9
+ then
10
+ cd /usr/src/app
11
+ bundle exec rake ditty:generate_tokens
12
+ bundle exec rake ditty:migrate
13
+ bundle exec rake ditty:seed
14
+ bundle exec whenever --update-crontab
15
+ crond
16
+ exec bundle exec pumactl start "$@"
17
+ fi
18
+
19
+ exec "$@"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proxes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.4
4
+ version: 0.8.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jurgens du Toit
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-14 00:00:00.000000000 Z
11
+ date: 2018-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: ditty
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -389,8 +403,11 @@ files:
389
403
  - ".rubocop.yml"
390
404
  - ".ruby-version"
391
405
  - ".travis.yml"
406
+ - Dockerfile
392
407
  - Gemfile
393
408
  - Gemfile.ci
409
+ - Gemfile.deploy
410
+ - Gemfile.deploy.lock
394
411
  - Gemfile.dev
395
412
  - LICENSE.txt
396
413
  - README.md
@@ -401,13 +418,13 @@ files:
401
418
  - bin/setup
402
419
  - config.ru
403
420
  - config/logger.yml
421
+ - config/puma.rb
404
422
  - gulpfile.js
405
423
  - lib/ditty/components/proxes.rb
406
424
  - lib/proxes.rb
407
425
  - lib/proxes/controllers/permissions.rb
408
426
  - lib/proxes/controllers/status.rb
409
427
  - lib/proxes/forwarder.rb
410
- - lib/proxes/helpers/es.rb
411
428
  - lib/proxes/helpers/indices.rb
412
429
  - lib/proxes/loggers/elasticsearch.rb
413
430
  - lib/proxes/models/permission.rb
@@ -432,6 +449,7 @@ files:
432
449
  - lib/proxes/request/snapshot.rb
433
450
  - lib/proxes/request/stats.rb
434
451
  - lib/proxes/security.rb
452
+ - lib/proxes/services/es.rb
435
453
  - lib/proxes/version.rb
436
454
  - migrate/20170209_permissions.rb
437
455
  - migrate/20170416_user_specific_permissions.rb
@@ -450,6 +468,7 @@ files:
450
468
  - public/js/vendors.js
451
469
  - public/manifest.json
452
470
  - src/scripts/app.js
471
+ - startup.sh
453
472
  - views/permissions/display.haml
454
473
  - views/permissions/edit.haml
455
474
  - views/permissions/form.haml
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ProxES
4
- module Helpers
5
- module ES
6
- def client
7
- @client ||= Elasticsearch::Client.new url: ENV['ELASTICSEARCH_URL']
8
- end
9
-
10
- def cluster_health(level = 'cluster')
11
- client.cluster.health level: level
12
- end
13
- end
14
- end
15
- end