topological_inventory-providers-common 2.1.4 → 3.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +24 -6
- data/lib/topological_inventory/providers/common/clowder_config.rb +68 -0
- data/lib/topological_inventory/providers/common/messaging_client.rb +3 -2
- data/lib/topological_inventory/providers/common/operations/source.rb +4 -3
- data/lib/topological_inventory/providers/common/sources_api_client.rb +18 -1
- data/lib/topological_inventory/providers/common/version.rb +1 -1
- data/spec/support/shared/availability_check.rb +6 -2
- data/spec/topological_inventory/providers/common/operations/source_spec.rb +10 -0
- data/topological_inventory-providers-common.gemspec +2 -1
- metadata +24 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ecc26cbace6fd3e43de690666e17f8c7d27e153efb05a2d48fb281712f073e8c
|
4
|
+
data.tar.gz: 0221166156a11b5f75da12b3fc1bb861b8594a058823fa2771c62a529ea165f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce5b60dd2047b2b316fa8e0add3b114664f707feae697afd45febf1abd265af96990b89c32ba53e6084f5abfb0a177cdc5ea2eb8c1f9437fdd3791e2dd19b2f0
|
7
|
+
data.tar.gz: d5ebb51170ffb18b7aaba271f5361742c1a2d849c96b181274b7f2562e67e4cb29bf94f83067ca41e26c51ff01a5ccf595fa4c776135a3b4cd1b154a7b3fea97
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,18 @@ All notable changes to this project will be documented in this file.
|
|
3
3
|
|
4
4
|
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
|
+
## [3.0.2] - 2021-08-24
|
7
|
+
Support PSK headers in sources api client #78
|
8
|
+
|
9
|
+
## [3.0.1] - 2021-04-30
|
10
|
+
More generic activesupport dependency #77
|
11
|
+
|
12
|
+
## [3.0.0] - 2021-03-08
|
13
|
+
Clowder migration #75
|
14
|
+
|
15
|
+
## [2.1.5] - 2021-01-07
|
16
|
+
Include x-rh-id header in Kafka Availability-Status message #73
|
17
|
+
|
6
18
|
## [2.1.4] - 2020-12-14
|
7
19
|
Common Counter metrics init #71
|
8
20
|
|
@@ -81,12 +93,18 @@ manageiq-loggers to >= 0.4.2 #20
|
|
81
93
|
## [1.0.0] - 2020-03-19
|
82
94
|
### Initial release to rubygems.org
|
83
95
|
|
84
|
-
[Unreleased]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/
|
85
|
-
[
|
86
|
-
[
|
87
|
-
[
|
88
|
-
[2.1.
|
89
|
-
[2.
|
96
|
+
[Unreleased]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v3.0.2.freeze...HEAD
|
97
|
+
[3.0.2]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v3.0.1.freeze...v3.0.2.freeze
|
98
|
+
[3.0.1]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v3.0.0.freeze...v3.0.1.freeze
|
99
|
+
[3.0.0]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v2.1.5.freeze...v3.0.0.freeze
|
100
|
+
[2.1.5]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v2.1.4.freeze...v2.1.5.freeze
|
101
|
+
[2.1.5]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v2.1.4.freeze...v2.1.5.freeze
|
102
|
+
[2.1.4]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v2.1.3.freeze...v2.1.4.freeze
|
103
|
+
[2.1.3]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v2.1.2.freeze...v2.1.3.freeze
|
104
|
+
[2.1.2]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v2.1.1.freeze...v2.1.2.freeze
|
105
|
+
[2.1.1]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v2.1.0.freeze...v2.1.1.freeze
|
106
|
+
[2.1.0]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v2.0.0.freeze...v2.1.0.freeze
|
107
|
+
[2.0.0]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v1.0.12...v2.0.0.freeze
|
90
108
|
[1.0.12]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v1.0.11...v1.0.12
|
91
109
|
[1.0.11]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v1.0.10...v1.0.11
|
92
110
|
[1.0.10]: https://github.com/RedHatInsights/topological_inventory-providers-common/compare/v1.0.9...v1.0.10
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'clowder-common-ruby'
|
2
|
+
require 'singleton'
|
3
|
+
|
4
|
+
module TopologicalInventory
|
5
|
+
module Providers
|
6
|
+
module Common
|
7
|
+
class ClowderConfig
|
8
|
+
include Singleton
|
9
|
+
|
10
|
+
def self.clowder_enabled?
|
11
|
+
::ClowderCommonRuby::Config.clowder_enabled?
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.instance
|
15
|
+
@instance ||= {}.tap do |options|
|
16
|
+
if clowder_enabled?
|
17
|
+
config = ::ClowderCommonRuby::Config.load
|
18
|
+
options["awsAccessKeyId"] = config.logging.cloudwatch.accessKeyId
|
19
|
+
options["awsRegion"] = config.logging.cloudwatch.region
|
20
|
+
options["awsSecretAccessKey"] = config.logging.cloudwatch.secretAccessKey
|
21
|
+
broker = config.kafka.brokers.first
|
22
|
+
options["kafkaHost"] = broker.hostname
|
23
|
+
options["kafkaPort"] = broker.port
|
24
|
+
|
25
|
+
options["kafkaTopics"] = {}.tap do |topics|
|
26
|
+
config.kafka.topics.each do |topic|
|
27
|
+
topics[topic.requestedName.to_s] = topic.name.to_s
|
28
|
+
end
|
29
|
+
end
|
30
|
+
options["logGroup"] = config.logging.cloudwatch.logGroup
|
31
|
+
options["metricsPort"] = config.metricsPort
|
32
|
+
options["metricsPath"] = config.metricsPath # not supported by PrometheusExporter
|
33
|
+
else
|
34
|
+
options["awsAccessKeyId"] = ENV['CW_AWS_ACCESS_KEY_ID']
|
35
|
+
options["awsRegion"] = 'us-east-1'
|
36
|
+
options["awsSecretAccessKey"] = ENV['CW_AWS_SECRET_ACCESS_KEY']
|
37
|
+
options["kafkaBrokers"] = ["#{ENV['QUEUE_HOST']}:#{ENV['QUEUE_PORT']}"]
|
38
|
+
options["kafkaHost"] = ENV['QUEUE_HOST'] || 'localhost'
|
39
|
+
options["kafkaPort"] = (ENV['QUEUE_PORT'] || '9092').to_i
|
40
|
+
options["kafkaTopics"] = {}
|
41
|
+
options["logGroup"] = 'platform-dev'
|
42
|
+
options["metricsPort"] = (ENV['METRICS_PORT'] || 9394).to_i
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.fill_args_operations(args)
|
48
|
+
args[:metrics_port] = instance['metricsPort']
|
49
|
+
args[:queue_host] = instance['kafkaHost']
|
50
|
+
args[:queue_port] = instance['kafkaPort']
|
51
|
+
args
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.kafka_topic(name)
|
55
|
+
instance["kafkaTopics"][name] || name
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# ManageIQ Message Client depends on these variables
|
63
|
+
ENV["QUEUE_HOST"] = TopologicalInventory::Providers::Common::ClowderConfig.instance["kafkaHost"]
|
64
|
+
ENV["QUEUE_PORT"] = TopologicalInventory::Providers::Common::ClowderConfig.instance["kafkaPort"].to_s
|
65
|
+
|
66
|
+
# ManageIQ Logger depends on these variables
|
67
|
+
ENV['CW_AWS_ACCESS_KEY_ID'] = TopologicalInventory::Providers::Common::ClowderConfig.instance["awsAccessKeyId"]
|
68
|
+
ENV['CW_AWS_SECRET_ACCESS_KEY'] = TopologicalInventory::Providers::Common::ClowderConfig.instance["awsSecretAccessKey"]
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require "more_core_extensions/core_ext/module/cache_with_timeout"
|
2
2
|
require "manageiq-messaging"
|
3
|
+
require "topological_inventory/providers/common/clowder_config"
|
3
4
|
|
4
5
|
module TopologicalInventory
|
5
6
|
module Providers
|
@@ -11,8 +12,8 @@ module TopologicalInventory
|
|
11
12
|
attr_accessor :queue_port
|
12
13
|
|
13
14
|
def initialize
|
14
|
-
self.queue_host =
|
15
|
-
self.queue_port =
|
15
|
+
self.queue_host = TopologicalInventory::Providers::Common::ClowderConfig.instance["kafkaHost"]
|
16
|
+
self.queue_port = TopologicalInventory::Providers::Common::ClowderConfig.instance["kafkaPort"].to_i
|
16
17
|
end
|
17
18
|
|
18
19
|
def self.default
|
@@ -17,7 +17,7 @@ module TopologicalInventory
|
|
17
17
|
|
18
18
|
STATUS_AVAILABLE, STATUS_UNAVAILABLE = %w[available unavailable].freeze
|
19
19
|
EVENT_AVAILABILITY_STATUS = "availability_status".freeze
|
20
|
-
|
20
|
+
KAFKA_TOPIC_NAME = "platform.sources.status".freeze
|
21
21
|
|
22
22
|
ERROR_MESSAGES = {
|
23
23
|
:authentication_not_found => "Authentication not found in Sources API",
|
@@ -209,9 +209,10 @@ module TopologicalInventory
|
|
209
209
|
|
210
210
|
def availability_status_message(payload)
|
211
211
|
messaging_client.publish_topic(
|
212
|
-
:service =>
|
212
|
+
:service => TopologicalInventory::Providers::Common::ClowderConfig.kafka_topic(KAFKA_TOPIC_NAME),
|
213
213
|
:event => EVENT_AVAILABILITY_STATUS,
|
214
|
-
:payload => payload.to_json
|
214
|
+
:payload => payload.to_json,
|
215
|
+
:headers => identity
|
215
216
|
)
|
216
217
|
rescue => err
|
217
218
|
logger.availability_check("Failed to update #{payload[:resource_type]} id: #{payload[:resource_id]} - #{err.message}", :error)
|
@@ -15,10 +15,27 @@ module TopologicalInventory
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def init_default_api
|
18
|
-
|
18
|
+
# TODO: remove this once PSK is set up everywhere.
|
19
|
+
if identity.present?
|
20
|
+
if psk
|
21
|
+
parsed_identity = JSON.parse(Base64.decode64(identity.fetch('x-rh-identity')))
|
22
|
+
|
23
|
+
default_headers.merge!(
|
24
|
+
"x-rh-sources-psk" => psk,
|
25
|
+
"x-rh-sources-account-number" => parsed_identity['identity']['account_number']
|
26
|
+
)
|
27
|
+
else
|
28
|
+
default_headers.merge!(identity)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
19
32
|
::SourcesApiClient::DefaultApi.new(self)
|
20
33
|
end
|
21
34
|
|
35
|
+
def psk
|
36
|
+
@psk ||= ENV.fetch("SOURCES_PSK", nil)
|
37
|
+
end
|
38
|
+
|
22
39
|
def fetch_default_endpoint(source_id)
|
23
40
|
endpoints = api.list_source_endpoints(source_id)&.data || []
|
24
41
|
endpoints.find(&:default)
|
@@ -9,7 +9,8 @@ RSpec.shared_examples "availability_check" do
|
|
9
9
|
let(:external_tenant) { '11001' }
|
10
10
|
let(:kafka_client) { TopologicalInventory::Providers::Common::MessagingClient.default.client }
|
11
11
|
let(:identity) { {'x-rh-identity' => Base64.strict_encode64({'identity' => {'account_number' => external_tenant, 'user' => {'is_org_admin' => true}}}.to_json)} }
|
12
|
-
let(:
|
12
|
+
let(:identity_with_psk) { { "x-rh-sources-account-number" => external_tenant, "x-rh-sources-psk" => '1234' } }
|
13
|
+
let(:headers) { ENV['SOURCES_PSK'] ? {'Content-Type' => 'application/json'}.merge(identity_with_psk) : {'Content-Type' => 'application/json'}.merge(identity) }
|
13
14
|
let(:status_available) { described_class::STATUS_AVAILABLE }
|
14
15
|
let(:status_unavailable) { described_class::STATUS_UNAVAILABLE }
|
15
16
|
let(:error_message) { 'error_message' }
|
@@ -38,12 +39,15 @@ RSpec.shared_examples "availability_check" do
|
|
38
39
|
|
39
40
|
def kafka_message(resource_type, resource_id, status, error_message = nil)
|
40
41
|
res = {
|
41
|
-
:service => described_class::
|
42
|
+
:service => described_class::KAFKA_TOPIC_NAME,
|
42
43
|
:event => described_class::EVENT_AVAILABILITY_STATUS,
|
43
44
|
:payload => {
|
44
45
|
:resource_type => resource_type,
|
45
46
|
:resource_id => resource_id,
|
46
47
|
:status => status
|
48
|
+
},
|
49
|
+
:headers => {
|
50
|
+
"x-rh-identity" => "eyJpZGVudGl0eSI6eyJhY2NvdW50X251bWJlciI6IjExMDAxIiwidXNlciI6eyJpc19vcmdfYWRtaW4iOnRydWV9fX0="
|
47
51
|
}
|
48
52
|
}
|
49
53
|
res[:payload][:error] = error_message if error_message
|
@@ -1,5 +1,15 @@
|
|
1
1
|
require "topological_inventory/providers/common/operations/source"
|
2
2
|
|
3
3
|
RSpec.describe TopologicalInventory::Providers::Common::Operations::Source do
|
4
|
+
context "PSK" do
|
5
|
+
around do |example|
|
6
|
+
ENV['SOURCES_PSK'] = '1234'
|
7
|
+
example.run
|
8
|
+
ENV['SOURCES_PSK'] = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
it_behaves_like "availability_check"
|
12
|
+
end
|
13
|
+
|
4
14
|
it_behaves_like "availability_check"
|
5
15
|
end
|
@@ -23,7 +23,8 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
24
|
spec.require_paths = ["lib"]
|
25
25
|
|
26
|
-
spec.add_runtime_dependency 'activesupport', '~> 5.2.4.3'
|
26
|
+
spec.add_runtime_dependency 'activesupport', '~> 5.2', '>= 5.2.4.3'
|
27
|
+
spec.add_runtime_dependency 'clowder-common-ruby', '~> 0.2.1'
|
27
28
|
spec.add_runtime_dependency 'config', '~> 1.7', '>= 1.7.2'
|
28
29
|
spec.add_runtime_dependency 'json', '~> 2.3'
|
29
30
|
spec.add_runtime_dependency 'manageiq-loggers', '>= 0.4.2'
|
metadata
CHANGED
@@ -1,20 +1,23 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: topological_inventory-providers-common
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Slemr
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.2'
|
20
|
+
- - ">="
|
18
21
|
- !ruby/object:Gem::Version
|
19
22
|
version: 5.2.4.3
|
20
23
|
type: :runtime
|
@@ -22,8 +25,25 @@ dependencies:
|
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
27
|
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '5.2'
|
30
|
+
- - ">="
|
25
31
|
- !ruby/object:Gem::Version
|
26
32
|
version: 5.2.4.3
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: clowder-common-ruby
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 0.2.1
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.2.1
|
27
47
|
- !ruby/object:Gem::Dependency
|
28
48
|
name: config
|
29
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -304,6 +324,7 @@ files:
|
|
304
324
|
- bin/console
|
305
325
|
- bin/setup
|
306
326
|
- lib/topological_inventory/providers/common.rb
|
327
|
+
- lib/topological_inventory/providers/common/clowder_config.rb
|
307
328
|
- lib/topological_inventory/providers/common/collector.rb
|
308
329
|
- lib/topological_inventory/providers/common/collector/inventory_collection_storage.rb
|
309
330
|
- lib/topological_inventory/providers/common/collector/inventory_collection_wrapper.rb
|
@@ -358,7 +379,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
358
379
|
- !ruby/object:Gem::Version
|
359
380
|
version: '0'
|
360
381
|
requirements: []
|
361
|
-
rubygems_version: 3.0.3
|
382
|
+
rubygems_version: 3.0.3.1
|
362
383
|
signing_key:
|
363
384
|
specification_version: 4
|
364
385
|
summary: Common classes for topological-inventory collectors/operations
|