smart_proxy_chef 0.1.8 → 0.2.0

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: ba7ac48c06fec7733e47f6ee326e4832f1a0aeed
4
- data.tar.gz: d63b9f03d18889953c05cf904f93cd62c3535ec9
3
+ metadata.gz: cb1a8d45f99bf8244a5ca235ccb3922e7cbd65df
4
+ data.tar.gz: 9b3363fe645754749974940d2fc9a826ad5e5ab9
5
5
  SHA512:
6
- metadata.gz: f1db01e97e6b3c1b96550b5521e595a5de4be163ca1c992421e86e133b3bb61a1fccd0d5e6058a937a3b0685b557858dc555a8f53091bf80be8841c1ecae701e
7
- data.tar.gz: 5c8735a45ecc99937bc9d5899711f9bfd0a23d5eacadad5a29d89a28cd9a310ea805aa0a84a4d8874fd394c268686fda5f225353844d80dd1289dcc436e13153
6
+ metadata.gz: aedec5996cc1cfaa621eccb21407403844cfb9a721fee5febd9310839092e48dbf634d71b62c5588fed52f8ae00a0ba58e823799c92de0be6d106a63597321c8
7
+ data.tar.gz: d6e9984216441b57692c6f81bccf4e1cbd8b4374572895f19b3c237d127f6a3153463e0dd127decaa0852499897b305972dfb1a79720941800aa5d7219160508
@@ -33,7 +33,14 @@ module ChefPlugin
33
33
 
34
34
  def authenticate_chef_signature(request)
35
35
  logger.debug('starting chef signature authentication')
36
- content = request.env["rack.input"].read
36
+ case request.request_method
37
+ when 'POST'
38
+ content = request.env["rack.input"].read
39
+ when 'GET'
40
+ content = request.env['HTTP_X_FOREMAN_CLIENT']
41
+ else
42
+ log_halt 401, "Don't know how to authenticate #{request.request_method} requests"
43
+ end
37
44
 
38
45
  auth = true
39
46
  if ChefPlugin::Plugin.settings.chef_authenticate_nodes
@@ -15,6 +15,9 @@ module ChefPlugin
15
15
  end
16
16
 
17
17
  connection
18
+ rescue => e
19
+ logger.error "Unable to establish a connection to chef server because of #{e.message}"
20
+ raise e
18
21
  end
19
22
  end
20
23
  end
@@ -1,6 +1,8 @@
1
1
  require 'proxy/request'
2
2
  require 'smart_proxy_chef_plugin/request'
3
3
  require 'smart_proxy_chef_plugin/authentication'
4
+ require 'uri'
5
+ require 'yaml'
4
6
 
5
7
  module ChefPlugin
6
8
  ::Sinatra::Base.register Authentication
@@ -32,6 +34,23 @@ module ChefPlugin
32
34
  log_result(foreman_response)
33
35
  end
34
36
 
37
+ get '/enc/:client' do |client|
38
+ begin
39
+ if client != request.env['HTTP_X_FOREMAN_CLIENT']
40
+ log_halt(401, "Unauthorized : client '#{request.env['HTTP_X_FOREMAN_CLIENT']}' is asking for other client '#{client}' data")
41
+ end
42
+ content_type :json
43
+ result = ChefPlugin::HttpRequest::Hosts.new.host_enc(client)
44
+ log_result(result)
45
+ log_halt(500, "Could not fetch ENC for #{client}, see Foreman production.log for more details") unless result.code.to_s.start_with?('2')
46
+
47
+ yaml_enc = result.body
48
+ YAML.load(yaml_enc).to_json
49
+ rescue => e
50
+ log_halt 400, e
51
+ end
52
+ end
53
+
35
54
  private
36
55
 
37
56
  def get_content
@@ -13,5 +13,11 @@ module ChefPlugin
13
13
  send_request(request_factory.create_post('api/reports', report))
14
14
  end
15
15
  end
16
+
17
+ class Hosts < ::Proxy::HttpRequest::ForemanRequest
18
+ def host_enc(host)
19
+ send_request(request_factory.create_get("node/#{host}", { :format => 'yml' }))
20
+ end
21
+ end
16
22
  end
17
23
  end
@@ -1,3 +1,3 @@
1
1
  module ChefPlugin
2
- VERSION = '0.1.8'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_proxy_chef
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marek Hulan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-22 00:00:00.000000000 Z
11
+ date: 2017-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,7 +108,8 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
- description: " Chef support for Foreman Smart-Proxy\n"
111
+ description: |2
112
+ Chef support for Foreman Smart-Proxy
112
113
  email:
113
114
  - mhulan@redhat.com
114
115
  executables: []
@@ -154,4 +155,3 @@ signing_key:
154
155
  specification_version: 4
155
156
  summary: Chef support for Foreman Smart-Proxy
156
157
  test_files: []
157
- has_rdoc: