smart_proxy_discovery 1.0.1 → 1.0.2

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: c44e7552bc04515acee1e8328dffda3fd594d215
4
- data.tar.gz: d1d3e26f7abd3962fe84d4ab7aeae107e32a349e
3
+ metadata.gz: e7ba59c0ad52b0cd69c9ab51fdfe85d833dd624e
4
+ data.tar.gz: 849a4f4ae8f9de1092d5e96569a358c7d49c67e1
5
5
  SHA512:
6
- metadata.gz: 085cac6a876cca7bb6e9b0c2333e5100eee192fd82fec65040a5d10a9f0d240412247e535e5bf24365be947037a557f36d6c1f9ddb99918de6e5d6e2a2e0c37c
7
- data.tar.gz: 00195756941fdd901fa70443085ba12999e39aee15013c16087f07bbd5f5f5bf3d14ac884b2d06dfa6574cf50051c7ab7cdc5a7341d801b92013d1b15aaf8e13
6
+ metadata.gz: b780662313b5efcd778a3d203e396294806a93aa68a681cc56217564c847bf65ba3de69c8990a57374573d068d4bba8bc6ee4f8a264cdaa4d35054b4f0c11faf
7
+ data.tar.gz: e266f8c9cfb8ea229de42a39db7d5865403998af0d085fa1c6132f8c0dffbb029da62df69582b9f2dedfbd9a49d503df5db0d06fe5a9cde29fb07e9048b0b152
@@ -4,9 +4,29 @@ require 'smart_proxy_discovery/discovery_main'
4
4
 
5
5
  module Proxy::Discovery
6
6
 
7
- class Api < ::Sinatra::Base
7
+ # This plugin has two separate Sinatra applications with different contexts
8
+ # (authorization helpers). Inbound communication is unauthorized,
9
+ class Dispatcher
10
+ def call(env)
11
+ if env['PATH_INFO'] == '/create'
12
+ InboundApi.new.call(env)
13
+ else
14
+ OutboundApi.new.call(env)
15
+ end
16
+ end
17
+ end
18
+
19
+ module ApiHelpers
20
+ def error_responder(error)
21
+ error_code = error.respond_to?(:http_code) ? error.http_code : 500
22
+ log_halt(error_code, "failed to update Foreman: #{error}")
23
+ end
24
+ end
25
+
26
+ # Inbound communication: Discovered Host -> Proxy Plugin -> Foreman
27
+ class InboundApi < ::Sinatra::Base
8
28
  helpers ::Proxy::Helpers
9
- authorize_with_trusted_hosts
29
+ include ApiHelpers
10
30
 
11
31
  post '/create' do
12
32
  content_type :json
@@ -17,6 +37,14 @@ module Proxy::Discovery
17
37
  end
18
38
  end
19
39
 
40
+ end
41
+
42
+ # Outbound communication: Foreman -> Proxy Plugin -> Discovered Host
43
+ class OutboundApi < ::Sinatra::Base
44
+ helpers ::Proxy::Helpers
45
+ include ApiHelpers
46
+ authorize_with_trusted_hosts
47
+
20
48
  get '/:ip/facts' do
21
49
  content_type :json
22
50
  begin
@@ -34,12 +62,5 @@ module Proxy::Discovery
34
62
  error_responder(error)
35
63
  end
36
64
  end
37
-
38
- private
39
-
40
- def error_responder(error)
41
- error_code = error.respond_to?(:http_code) ? error.http_code : 500
42
- log_halt(error_code, "failed to update Foreman: #{error}")
43
- end
44
65
  end
45
66
  end
@@ -11,8 +11,11 @@ module Proxy::Discovery
11
11
 
12
12
  def create_discovered_host(request)
13
13
  foreman_request = Proxy::HttpRequest::ForemanRequest.new()
14
- req = foreman_request.request_factory.create_post(CREATE_DISCOVERED_HOST_PATH, request.body)
15
- foreman_request.send_request(req)
14
+ req = foreman_request.request_factory.create_post(CREATE_DISCOVERED_HOST_PATH, request.body.read)
15
+ response = foreman_request.send_request(req)
16
+ unless response.is_a? Net::HTTPSuccess
17
+ raise response
18
+ end
16
19
  end
17
20
 
18
21
  def refresh_facts(ip)
@@ -1,5 +1,5 @@
1
1
  require 'smart_proxy_discovery/discovery_api'
2
2
 
3
3
  map '/discovery' do
4
- run Proxy::Discovery::Api
4
+ run Proxy::Discovery::Dispatcher.new
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module Proxy
2
2
  module Discovery
3
- VERSION = '1.0.1'
3
+ VERSION = '1.0.2'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_proxy_discovery
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shlomi Zadok
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-09 00:00:00.000000000 Z
11
+ date: 2015-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -70,16 +70,22 @@ dependencies:
70
70
  name: rest-client
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - ">"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 1.6.2
76
+ - - "<"
77
+ - !ruby/object:Gem::Version
78
+ version: '1.7'
76
79
  type: :runtime
77
80
  prerelease: false
78
81
  version_requirements: !ruby/object:Gem::Requirement
79
82
  requirements:
80
- - - ">="
83
+ - - ">"
81
84
  - !ruby/object:Gem::Version
82
- version: '0'
85
+ version: 1.6.2
86
+ - - "<"
87
+ - !ruby/object:Gem::Version
88
+ version: '1.7'
83
89
  description: Smart proxy discovery plugin
84
90
  email: szadok@redhat.com
85
91
  executables: []