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 +4 -4
- data/CHANGELOG.md +7 -2
- data/lib/receptor_controller/client/directive_blocking.rb +1 -1
- data/lib/receptor_controller/client/directive_non_blocking.rb +1 -1
- data/lib/receptor_controller/client/response_worker.rb +12 -3
- data/lib/receptor_controller/client/version.rb +1 -1
- data/spec/.yamllint +10 -0
- data/spec/receptor_controller/directive_blocking_spec.rb +28 -2
- data/spec/receptor_controller/directive_non_blocking_spec.rb +26 -3
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c93a4640b49698fe085a3f8eeeeb21ce3c7c087414e3ab7a177e8d6471c4453f
|
4
|
+
data.tar.gz: 296126023dafdb0325e4c7b4166720b333b5cd6fc3e6ca0709b4314cf109e142
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42522f3b97b78ac1a25a947351b822c827f01cc851772e61f464694fede11de3b9ab2746cc4de4bb5b2b262b8bf367266c292bf9af562ab9a89f87f24b26198d
|
7
|
+
data.tar.gz: 6c9edc4cde0acbc4396cc729af0b75051c922b197462e09a81afe3834fdd667febea56a9f70548cd77c5b52b00da407ca71da560e39c038960389e42d5ea6929
|
data/CHANGELOG.md
CHANGED
@@ -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.
|
34
|
-
[0.0.
|
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
|
-
|
109
|
-
|
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
|
data/spec/.yamllint
ADDED
@@ -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(:
|
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'}
|
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(:
|
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'}
|
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.
|
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:
|
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
|