kibana-rack 0.1.3 → 0.1.4

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: e8a77c4673874c623af6c587228a48f59400c531
4
- data.tar.gz: 89f98d20b09d90e4972a84f8006bf8af42fcdc75
3
+ metadata.gz: d9b991332964c43f341d86bf0eb6f037aba64e76
4
+ data.tar.gz: 5c25476aa7ac8daee036ec839b4b86d3eaa5fc4f
5
5
  SHA512:
6
- metadata.gz: ead603df5f794c5d3d72f173b987a796d0602b6e5479cce9983a19b918b0993fd9dd69ceab77603c5fba7eda53fcfe10531cfbaa08efec8688ce44f6ae55ecca
7
- data.tar.gz: 7040a490372406bc06e9925b084b4c6c6f7394ffbe6c829f934849c549d200540fc1fe8e79cdfa78a54d9d75aea6016dfa33e579d93e5373acb3e46c456a71d7
6
+ metadata.gz: e7339e39d1c59ae6be114aa0f5031e9ceac796272fa4e884059a3e188c9baa36b14f62c7b43f105ba7917bf867128dd55b974b3e6b0a912ff8f586dbf3fff748
7
+ data.tar.gz: 4c51e220d44aa5ee78d133314651b9c47a79a4cea0048bdacf90270fc4b88f99de16758a1f1d546e854337825da8443387a15047f94632a4f4bd857e4c26f66d
@@ -1,2 +1,3 @@
1
- ��#�PF`M?�0c0n�r�X�i������6�'M?D�ڲCp�U����d���HI�:"�?��eR��΍�υw���3k7��î�#ooj%9+-�ȉ���x7
2
- V�-�1�!a�!�`�]�����Xo��e��Cb��8���T�V���Nu���K����M���?N!-j؝U+���l.nʕ8
1
+ �tH���r�γ����9��YX<);��YI�Nnv���*���m)!�W9]��e�?A5D=��S��Ӗ�bڥ�6�%H?��%�Y�+� ��:�@��� �^�rF레Iך>��C��l���/�AƵ??�bx{p
2
+ '�@Ycm.�$+fqqDz�C t��F�Ԯ;�9�'��S�;��V��
3
+ �w����*Pq>}]
data.tar.gz.sig CHANGED
Binary file
@@ -0,0 +1,9 @@
1
+ # kibana-rack Authors
2
+
3
+ ## Maintainer
4
+
5
+ [Tony Burns](https://github.com/tabolario)
6
+
7
+ ## Contributors
8
+
9
+ [Dan Carley](https://github.com/dcarley)
@@ -1,5 +1,9 @@
1
1
  # Change history for kibana-rack
2
2
 
3
+ ## [v0.1.4](https://github.com/tabolario/kibana-rack/releases/tag/v0.1.4)
4
+
5
+ * [Bug] [Proxy temporary and permanent dashboards to ES](https://github.com/tabolario/kibana-rack/pull/12) - [dcarley](https://github.com/dcarley)
6
+
3
7
  ## [v0.1.3](https://github.com/tabolario/kibana-rack/releases/tag/v0.1.3)
4
8
 
5
9
  * [Bug] [Serve dashboard files from app/dashboards](https://github.com/tabolario/kibana-rack/issues/10)
@@ -1,5 +1,5 @@
1
1
  module Kibana
2
2
  module Rack
3
- VERSION = '0.1.3'
3
+ VERSION = '0.1.4'
4
4
  end
5
5
  end
@@ -15,11 +15,33 @@ module Kibana
15
15
  set :kibana_index, -> { Kibana.kibana_index }
16
16
 
17
17
  helpers do
18
+ def validate_kibana_index_name
19
+ render_not_found unless params[:index] == settings.kibana_index
20
+ end
21
+
18
22
  def proxy
19
23
  es_host = settings.elasticsearch_host
20
24
  es_port = settings.elasticsearch_port
21
25
  @proxy ||= Faraday.new(url: "http://#{es_host}:#{es_port}")
22
26
  end
27
+
28
+ def proxy_es_request
29
+ request.body.rewind
30
+
31
+ proxy_method = request.request_method.downcase.to_sym
32
+ proxy_response = proxy.send(proxy_method) do |proxy_request|
33
+ proxy_request.url(request.path_info)
34
+ proxy_request.headers['Content-Type'] = 'application/json'
35
+ proxy_request.params = env['rack.request.query_hash']
36
+ proxy_request.body = request.body.read if [:post, :put].include?(proxy_method)
37
+ end
38
+
39
+ [proxy_response.status, proxy_response.headers, proxy_response.body]
40
+ end
41
+
42
+ def render_not_found
43
+ halt(404, '<h1>Not Found</h1>')
44
+ end
23
45
  end
24
46
 
25
47
  get '/' do
@@ -36,25 +58,46 @@ module Kibana
36
58
  dashboard_ext = params[:captures][1]
37
59
  dashboard_path = File.join(settings.kibana_dashboards_path, "#{dashboard_name}.#{dashboard_ext}")
38
60
 
39
- halt(404, { 'Content-Type' => 'application/json' }, '{"error":"Not found"}') unless File.exist?(dashboard_path)
61
+ render_not_found unless File.exist?(dashboard_path)
40
62
 
41
63
  template = IO.read(dashboard_path)
42
64
  content_type "application/#{dashboard_ext}"
43
65
  erb template
44
66
  end
45
67
 
46
- route(:delete, :get, :post, :put, %r{^((/_(aliases|nodes))|(.+/_(aliases|mapping|search)))}) do
47
- request.body.rewind
68
+ route(:delete, :get, :post, :put, '/_aliases') do
69
+ proxy_es_request
70
+ end
48
71
 
49
- proxy_method = request.request_method.downcase.to_sym
50
- proxy_response = proxy.send(proxy_method) do |proxy_request|
51
- proxy_request.url(params[:captures].first)
52
- proxy_request.headers['Content-Type'] = 'application/json'
53
- proxy_request.params = env['rack.request.query_hash']
54
- proxy_request.body = request.body.read if proxy_method == :post
55
- end
72
+ route(:delete, :get, :post, :put, '/_nodes') do
73
+ proxy_es_request
74
+ end
75
+
76
+ route(:delete, :get, :post, :put, '/:index/_aliases') do
77
+ proxy_es_request
78
+ end
79
+
80
+ route(:delete, :get, :post, :put, '/:index/_mapping') do
81
+ proxy_es_request
82
+ end
83
+
84
+ route(:delete, :get, :post, :put, '/:index/_search') do
85
+ proxy_es_request
86
+ end
87
+
88
+ route(:delete, :get, :post, :put, '/:index/temp') do
89
+ validate_kibana_index_name
90
+ proxy_es_request
91
+ end
92
+
93
+ route(:delete, :get, :post, :put, '/:index/temp/:name') do
94
+ validate_kibana_index_name
95
+ proxy_es_request
96
+ end
56
97
 
57
- [proxy_response.status, proxy_response.headers, proxy_response.body]
98
+ route(:delete, :get, :post, :put, '/:index/dashboard/:dashboard') do
99
+ validate_kibana_index_name
100
+ proxy_es_request
58
101
  end
59
102
  end
60
103
  end
@@ -3,14 +3,16 @@ require 'spec_helper'
3
3
  describe Kibana::Rack::Web do
4
4
  include Rack::Test::Methods
5
5
 
6
- let(:app) { described_class }
6
+ KIBANA_INDEX = 'test-int'
7
7
 
8
+ let(:app) { described_class }
8
9
  let(:dashboards_path) { File.expand_path('../../../../fixtures/dashboards', __FILE__) }
9
10
 
10
11
  before do
11
12
  app.set(:raise_exceptions, true)
12
13
  app.set(:show_exceptions, false)
13
14
  app.set(:kibana_dashboards_path, dashboards_path)
15
+ app.set(:kibana_index, KIBANA_INDEX)
14
16
  end
15
17
 
16
18
  it 'serves the Kibana application' do
@@ -49,17 +51,44 @@ describe Kibana::Rack::Web do
49
51
  it 'returns 404 if a dashboard does not exist' do
50
52
  get '/app/dashboards/nonexistent.json'
51
53
 
52
- expect(last_response.body.strip).to eql('{"error":"Not found"}')
54
+ expect(last_response.body.strip).to eql('<h1>Not Found</h1>')
53
55
  expect(last_response.status).to eql(404)
54
56
  end
55
57
 
58
+ [
59
+ %w(put /_cluster/settings),
60
+ %w(post /_shutdown),
61
+ %w(post /_cluster/nodes/_shutdown),
62
+ %w(delete /*),
63
+ %w(delete /_all),
64
+ %w(delete /_all/_query?q=*),
65
+ %w(delete /logstash-2014.08.08/_query?q=*),
66
+ %w(delete /logstash-2014.08.08),
67
+ %w(post /logstash-2014.08.08),
68
+ %w(put /logstash-2014.08.08/message/123),
69
+ %w(post /logstash-2014.08.08/message/123/_update),
70
+ %w(get /logstash-2014.08.08/dashboard/123),
71
+ %w(get /logstash-2014.08.08/temp/123)
72
+ ].each do |method, path|
73
+ it "should prevent #{method.upcase} #{path} being proxied to Elasticsearch" do
74
+ send(method, path)
75
+
76
+ expect(last_response.body.strip).to eql('<h1>Not Found</h1>')
77
+ expect(last_response.status).to eql(404)
78
+ end
79
+ end
80
+
56
81
  {
57
82
  '/_aliases' => { method: :get },
58
83
  '/_nodes' => { method: :get },
59
84
  '/_all/_aliases' => { method: :get },
60
85
  '/_all/_mapping' => { method: :get },
61
86
  '/_all/_search' => { method: :post, body: '{"j":"s","o":"n"}' },
62
- '/logstash-2014.08.08,logstash-2014.08.09/_aliases' => { method: :get, params: { ignore_missing: 'true' } }
87
+ '/logstash-2014.08.08,logstash-2014.08.09/_aliases' => { method: :get, params: { ignore_missing: 'true' } },
88
+ "/#{KIBANA_INDEX}/temp?ttl=30d" => { method: :post, body: '{"j":"s","o":"n"}' },
89
+ "/#{KIBANA_INDEX}/temp/GjO0MfT5QL6dLqOytd6qDw" => { method: :get, params: { cache: 123 } },
90
+ "/#{KIBANA_INDEX}/dashboard/read_example" => { method: :get, params: { cache: 123 } },
91
+ "/#{KIBANA_INDEX}/dashboard/write_example" => { method: :put, body: '{"j":"s","o":"n"}' }
63
92
  }.each do |path, options|
64
93
  it "proxies #{options[:method].upcase} #{path} to Elasticsearch" do
65
94
  request_method = options[:method]
@@ -67,7 +96,7 @@ describe Kibana::Rack::Web do
67
96
  .with(body: options[:body], query: options[:params])
68
97
  .to_return(body: '{}', headers: { 'foo' => 'bar' }, status: 200)
69
98
 
70
- request_params = request_method == :post ? options[:body] : options[:params]
99
+ request_params = options[:body] || options[:params]
71
100
  send(request_method, path, request_params)
72
101
 
73
102
  expect(last_response.body).to eql('{}')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kibana-rack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Burns
@@ -30,7 +30,7 @@ cert_chain:
30
30
  WdK2SktNC0LYNRz+x3DdkcnVGS5BbSE7CYk7ap0J9jTobkmBTZ6tNWhVQiy7eJLr
31
31
  pOgabsoLeT6zXAW+EOudMh1S/ZA=
32
32
  -----END CERTIFICATE-----
33
- date: 2014-08-11 00:00:00.000000000 Z
33
+ date: 2014-08-14 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: faraday
@@ -104,6 +104,7 @@ files:
104
104
  - ".simplecov"
105
105
  - ".travis.yml"
106
106
  - ".yardopts"
107
+ - AUTHORS.md
107
108
  - CHANGELOG.md
108
109
  - CONTRIBUTING.md
109
110
  - Gemfile
metadata.gz.sig CHANGED
Binary file