receptor_controller-client 0.0.7 → 0.0.8

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
  SHA256:
3
- metadata.gz: ab72f29ace5c188996000048957bb58020940d3b8ce32b1a0b720602f4ff7e64
4
- data.tar.gz: 4b68d648d59809f80e108a1d998af10d09fee233db085e02b736c691db05b8d5
3
+ metadata.gz: c93a4640b49698fe085a3f8eeeeb21ce3c7c087414e3ab7a177e8d6471c4453f
4
+ data.tar.gz: 296126023dafdb0325e4c7b4166720b333b5cd6fc3e6ca0709b4314cf109e142
5
5
  SHA512:
6
- metadata.gz: 32b8c1c4a2173e38ec229bad3b4f0c6747c9f9cc50ce3be86746217a6682b60e4c820e9677adc38798548d81bb62db858994a7019cb85fc9b58c149eb0357c2e
7
- data.tar.gz: abfdf8a4c9924f4ba225310f5439b97f003d4ac01eedd14a822328d7750289a60cc9ec49a086ac125f446adbd0c84840afc02562a84c3c02c19f6402b201a469
6
+ metadata.gz: 42522f3b97b78ac1a25a947351b822c827f01cc851772e61f464694fede11de3b9ab2746cc4de4bb5b2b262b8bf367266c292bf9af562ab9a89f87f24b26198d
7
+ data.tar.gz: 6c9edc4cde0acbc4396cc729af0b75051c922b197462e09a81afe3834fdd667febea56a9f70548cd77c5b52b00da407ca71da560e39c038960389e42d5ea6929
@@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
7
  ## [Unreleased]
8
+ ## [0.0.8]
9
+ - Fix LOG_ALL_RECEPTOR_MESSAGES check #34
10
+ - Fix Directives with PSK header #33
11
+
8
12
  ## [0.0.7]
9
13
  - rdkafka changes #32
10
14
 
@@ -30,8 +34,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
30
34
  ### Added
31
35
  - Added extra logging for messages
32
36
 
33
- [Unreleased]: https://github.com/RedHatInsights/receptor_controller-client-ruby/compare/v0.0.7...HEAD
34
- [0.0.6]: https://github.com/RedHatInsights/receptor_controller-client-ruby/releases/tag/v0.0.7
37
+ [Unreleased]: https://github.com/RedHatInsights/receptor_controller-client-ruby/compare/v0.0.8...HEAD
38
+ [0.0.8]: https://github.com/RedHatInsights/receptor_controller-client-ruby/releases/tag/v0.0.8
39
+ [0.0.7]: https://github.com/RedHatInsights/receptor_controller-client-ruby/releases/tag/v0.0.7
35
40
  [0.0.6]: https://github.com/RedHatInsights/receptor_controller-client-ruby/releases/tag/v0.0.6
36
41
  [0.0.5]: https://github.com/RedHatInsights/receptor_controller-client-ruby/releases/tag/v0.0.5
37
42
  [0.0.4]: https://github.com/RedHatInsights/receptor_controller-client-ruby/releases/tag/v0.0.4
@@ -74,7 +74,7 @@ module ReceptorController
74
74
  attr_accessor :response_data, :response_exception, :response_lock, :response_waiting
75
75
 
76
76
  def connection
77
- @connection ||= Faraday.new(config.controller_url, :headers => client.headers) do |c|
77
+ @connection ||= Faraday.new(config.controller_url, :headers => client.headers(account)) do |c|
78
78
  c.use(Faraday::Response::RaiseError)
79
79
  c.adapter(Faraday.default_adapter)
80
80
  end
@@ -42,7 +42,7 @@ module ReceptorController
42
42
 
43
43
  # Entrypoint for request
44
44
  def call(body = default_body)
45
- response = Faraday.post(config.job_url, body.to_json, client.headers)
45
+ response = Faraday.post(config.job_url, body.to_json, client.headers(account))
46
46
  if response.success?
47
47
  msg_id = JSON.parse(response.body)['id']
48
48
 
@@ -105,8 +105,10 @@ module ReceptorController
105
105
  response = JSON.parse(message.payload)
106
106
 
107
107
  if (message_id = response['in_response_to'])
108
- logger.debug(response_log("Received message #{message_id}: serial: #{response["serial"]}, type: #{response['message_type']}, payload: #{response['payload'] || "n/a"}"))
109
- if (callbacks = registered_messages[message_id]).present?
108
+ callbacks = registered_messages[message_id]
109
+ log_received_message(callbacks, message_id, response)
110
+
111
+ if callbacks.present?
110
112
  # Reset last_checked_at to avoid timeout in multi-response messages
111
113
  reset_last_checked_at(callbacks)
112
114
 
@@ -150,7 +152,7 @@ module ReceptorController
150
152
 
151
153
  callbacks[:receiver].send(callbacks[:error_callback], message_id, response['code'], response['payload'])
152
154
  end
153
- elsif ENV["LOG_ALL_RECEPTOR_MESSAGES"]&.to_i != 0
155
+ elsif (ENV["LOG_ALL_RECEPTOR_MESSAGES"] || 0)&.to_i != 0
154
156
  # noop, it's not error if not registered, can be processed by another pod
155
157
  logger.debug(response_log("NOT REGISTERED | #{message_id} (#{response['code']})"))
156
158
  end
@@ -243,6 +245,13 @@ module ReceptorController
243
245
  }
244
246
  end
245
247
 
248
+ def log_received_message(callbacks, message_id, response)
249
+ log_all = (ENV["LOG_ALL_RECEPTOR_MESSAGES"] || 0).to_i != 0
250
+ if log_all || (!log_all && callbacks.present?)
251
+ logger.debug(response_log("Received message #{message_id}: serial: #{response["serial"]}, type: #{response['message_type']}, payload: #{response['payload'] || "n/a"}"))
252
+ end
253
+ end
254
+
246
255
  def response_log(message)
247
256
  "Receptor Response [#{queue_opts[:persist_ref]}]: #{message}"
248
257
  end
@@ -1,5 +1,5 @@
1
1
  module ReceptorController
2
2
  class Client
3
- VERSION = "0.0.7".freeze
3
+ VERSION = "0.0.8".freeze
4
4
  end
5
5
  end
@@ -0,0 +1,10 @@
1
+ ---
2
+ ignore: |
3
+
4
+ extends: relaxed
5
+
6
+ rules:
7
+ indentation:
8
+ indent-sequences: false
9
+ line-length:
10
+ max: 120
@@ -7,11 +7,21 @@ RSpec.describe ReceptorController::Client::DirectiveBlocking do
7
7
  let(:identity) do
8
8
  {"x-rh-identity" => Base64.strict_encode64({"identity" => {"account_number" => external_tenant, "user" => {"is_org_admin" => true}, "internal" => {"org_id" => organization_id}}}.to_json)}
9
9
  end
10
- let(:headers) do
10
+ let(:pre_shared_key) { '1234' }
11
+ let(:pre_shared_key_headers) do
12
+ {
13
+ 'x-rh-receptor-controller-psk' => pre_shared_key,
14
+ 'x-rh-receptor-controller-client-id' => "topological-inventory",
15
+ 'x-rh-receptor-controller-account' => external_tenant
16
+ }
17
+ end
18
+ let(:headers_common) do
11
19
  {"Content-Type" => "application/json",
12
20
  "Accept" => "*/*",
13
- "Accept-Encoding" => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3'}.merge(identity)
21
+ "Accept-Encoding" => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3'}
14
22
  end
23
+ let(:headers) { headers_common.merge(identity) }
24
+ let(:headers_psk) { headers_common.merge(pre_shared_key_headers) }
15
25
  let(:receptor_scheme) { 'http' }
16
26
  let(:receptor_host) { 'localhost:9090' }
17
27
  let(:receptor_node) { 'testing-receptor' }
@@ -52,6 +62,22 @@ RSpec.describe ReceptorController::Client::DirectiveBlocking do
52
62
  subject.call
53
63
  end
54
64
 
65
+ it "makes POST /job request with PSK headers if set in the config" do
66
+ receptor_config.pre_shared_key = pre_shared_key
67
+ allow(subject).to receive(:wait_for_response)
68
+
69
+ response = {"id" => '1234'}
70
+
71
+ stub_request(:post, "#{receptor_scheme}://#{receptor_host}/job")
72
+ .with(:body => subject.default_body.to_json,
73
+ :headers => headers_psk)
74
+ .to_return(:status => 200, :body => response.to_json, :headers => {})
75
+
76
+ expect(subject.response_worker).to receive(:register_message).with(response['id'], subject)
77
+
78
+ subject.call
79
+ end
80
+
55
81
  it "raises ControllerResponseError if POST /job returns error" do
56
82
  stub_request(:post, "#{receptor_scheme}://#{receptor_host}/job")
57
83
  .with(:body => subject.default_body.to_json,
@@ -6,11 +6,21 @@ RSpec.describe ReceptorController::Client::DirectiveNonBlocking do
6
6
  let(:identity) do
7
7
  {"x-rh-identity" => Base64.strict_encode64({"identity" => {"account_number" => external_tenant, "user" => {"is_org_admin" => true}, "internal" => {"org_id" => organization_id}}}.to_json)}
8
8
  end
9
- let(:headers) do
9
+ let(:pre_shared_key) { '1234' }
10
+ let(:pre_shared_key_headers) do
11
+ {
12
+ 'x-rh-receptor-controller-psk' => pre_shared_key,
13
+ 'x-rh-receptor-controller-client-id' => "topological-inventory",
14
+ 'x-rh-receptor-controller-account' => external_tenant
15
+ }
16
+ end
17
+ let(:headers_common) do
10
18
  {"Content-Type" => "application/json",
11
19
  "Accept" => "*/*",
12
- "Accept-Encoding" => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3'}.merge(identity)
20
+ "Accept-Encoding" => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3'}
13
21
  end
22
+ let(:headers) { headers_common.merge(identity) }
23
+ let(:headers_psk) { headers_common.merge(pre_shared_key_headers) }
14
24
  let(:receptor_scheme) { 'http' }
15
25
  let(:receptor_host) { 'localhost:9090' }
16
26
  let(:receptor_node) { 'testing-receptor' }
@@ -21,7 +31,7 @@ RSpec.describe ReceptorController::Client::DirectiveNonBlocking do
21
31
  end
22
32
  end
23
33
  let(:receptor_client) do
24
- client = ReceptorController::Client.new
34
+ client = ReceptorController::Client.new(:config => receptor_config)
25
35
  client.identity_header = identity
26
36
  client
27
37
  end
@@ -64,6 +74,19 @@ RSpec.describe ReceptorController::Client::DirectiveNonBlocking do
64
74
 
65
75
  expect(subject.call).to be_nil
66
76
  end
77
+
78
+ it "makes a POST request with PSK headers if provided" do
79
+ receptor_config.pre_shared_key = pre_shared_key
80
+
81
+ response = {"id" => '1234'}
82
+
83
+ stub_request(:post, "#{receptor_scheme}://#{receptor_host}/job")
84
+ .with(:body => subject.default_body.to_json,
85
+ :headers => headers_psk)
86
+ .to_return(:status => 200, :body => response.to_json, :headers => {})
87
+
88
+ expect(subject.call).to eq(response['id'])
89
+ end
67
90
  end
68
91
 
69
92
  context "callbacks" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: receptor_controller-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Slemr
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-02 00:00:00.000000000 Z
11
+ date: 2021-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -232,6 +232,7 @@ files:
232
232
  - lib/receptor_controller/client/response_worker.rb
233
233
  - lib/receptor_controller/client/version.rb
234
234
  - receptor_controller-client.gemspec
235
+ - spec/.yamllint
235
236
  - spec/receptor_controller/client_spec.rb
236
237
  - spec/receptor_controller/directive_blocking_spec.rb
237
238
  - spec/receptor_controller/directive_non_blocking_spec.rb
@@ -261,8 +262,8 @@ signing_key:
261
262
  specification_version: 4
262
263
  summary: Client for communication with Platform Receptor Controller - Gem
263
264
  test_files:
264
- - spec/receptor_controller/directive_non_blocking_spec.rb
265
- - spec/receptor_controller/response_worker_spec.rb
266
265
  - spec/receptor_controller/directive_blocking_spec.rb
266
+ - spec/receptor_controller/directive_non_blocking_spec.rb
267
267
  - spec/receptor_controller/client_spec.rb
268
+ - spec/receptor_controller/response_worker_spec.rb
268
269
  - spec/spec_helper.rb