topological_inventory-providers-common 1.0.11 → 2.1.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.
Files changed (27) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +31 -0
  3. data/.rubocop.yml +1 -1
  4. data/.yamllint +8 -0
  5. data/CHANGELOG.md +28 -4
  6. data/lib/topological_inventory/providers/common.rb +1 -2
  7. data/lib/topological_inventory/providers/common/logging.rb +6 -3
  8. data/lib/topological_inventory/providers/common/messaging_client.rb +40 -0
  9. data/lib/topological_inventory/providers/common/metrics.rb +84 -0
  10. data/lib/topological_inventory/providers/common/mixins/sources_api.rb +61 -0
  11. data/lib/topological_inventory/providers/common/mixins/statuses.rb +19 -0
  12. data/lib/topological_inventory/providers/common/mixins/topology_api.rb +26 -0
  13. data/lib/topological_inventory/providers/common/mixins/x_rh_headers.rb +24 -0
  14. data/lib/topological_inventory/providers/common/operations/async_worker.rb +61 -0
  15. data/lib/topological_inventory/providers/common/operations/processor.rb +46 -104
  16. data/lib/topological_inventory/providers/common/operations/source.rb +183 -144
  17. data/lib/topological_inventory/providers/common/sources_api_client.rb +92 -0
  18. data/lib/topological_inventory/providers/common/topology_api_client.rb +43 -0
  19. data/lib/topological_inventory/providers/common/version.rb +1 -1
  20. data/spec/support/shared/availability_check.rb +254 -90
  21. data/spec/topological_inventory/providers/common/operations/async_worker_spec.rb +45 -0
  22. data/spec/topological_inventory/providers/common/operations/processor_spec.rb +52 -83
  23. data/topological_inventory-providers-common.gemspec +14 -10
  24. metadata +74 -9
  25. data/lib/topological_inventory/providers/common/operations/endpoint_client.rb +0 -65
  26. data/lib/topological_inventory/providers/common/operations/sources_api_client.rb +0 -94
  27. data/lib/topological_inventory/providers/common/operations/topology_api_client.rb +0 -28
@@ -1,94 +0,0 @@
1
- require "sources-api-client"
2
-
3
- module TopologicalInventory
4
- module Providers
5
- module Common
6
- module Operations
7
- class SourcesApiClient < ::SourcesApiClient::ApiClient
8
- delegate :update_source, :update_endpoint, :update_application, :to => :api
9
-
10
- INTERNAL_API_PATH = '//internal/v1.0'.freeze
11
-
12
- def initialize(identity = nil)
13
- super(::SourcesApiClient::Configuration.default)
14
- self.identity = identity
15
- self.api = init_default_api
16
- end
17
-
18
- def init_default_api
19
- default_headers.merge!(identity) if identity.present?
20
- ::SourcesApiClient::DefaultApi.new(self)
21
- end
22
-
23
- def fetch_default_endpoint(source_id)
24
- endpoints = api.list_source_endpoints(source_id)&.data || []
25
- endpoints.find(&:default)
26
- end
27
-
28
- def fetch_application(source_id)
29
- applications = api.list_source_applications(source_id)&.data || []
30
- applications.first
31
- end
32
-
33
- def fetch_authentication(source_id, default_endpoint = nil, authtype = nil)
34
- endpoint = default_endpoint || fetch_default_endpoint(source_id)
35
- return if endpoint.nil?
36
-
37
- endpoint_authentications = api.list_endpoint_authentications(endpoint.id.to_s).data || []
38
- return if endpoint_authentications.empty?
39
-
40
- auth_id = if authtype.nil?
41
- endpoint_authentications.first&.id
42
- else
43
- endpoint_authentications.detect { |a| a.authtype = authtype }&.id
44
- end
45
- return if auth_id.nil?
46
-
47
- fetch_authentication_with_password(auth_id)
48
- end
49
-
50
- private
51
-
52
- attr_accessor :identity, :api, :custom_base_path
53
-
54
- def fetch_authentication_with_password(auth_id)
55
- on_internal_api do
56
- local_var_path = "/authentications/#{auth_id}"
57
-
58
- query_params = "expose_encrypted_attribute[]=password"
59
-
60
- header_params = { 'Accept' => select_header_accept(['application/json']) }
61
- return_type = 'Authentication'
62
- data, _, _ = call_api(:GET, local_var_path,
63
- :header_params => header_params,
64
- :query_params => query_params,
65
- :auth_names => ['UserSecurity'],
66
- :return_type => return_type)
67
- data
68
- end
69
- end
70
-
71
- def build_request_url(path)
72
- # Add leading and trailing slashes to path
73
- path = "/#{path}".gsub(/\/+/, '/')
74
- URI.encode((custom_base_url || @config.base_url) + path)
75
- end
76
-
77
- def custom_base_url
78
- return nil if custom_base_path.nil?
79
-
80
- url = "#{@config.scheme}://#{[@config.host, custom_base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
81
- URI.encode(url)
82
- end
83
-
84
- def on_internal_api
85
- self.custom_base_path = INTERNAL_API_PATH
86
- yield
87
- ensure
88
- self.custom_base_path = nil
89
- end
90
- end
91
- end
92
- end
93
- end
94
- end
@@ -1,28 +0,0 @@
1
- module TopologicalInventory
2
- module Providers
3
- module Common
4
- module Operations
5
- module TopologyApiClient
6
- def topology_api_client
7
- @topology_api_client ||=
8
- begin
9
- api_client = TopologicalInventoryApiClient::ApiClient.new
10
- api_client.default_headers.merge!(identity) if identity.present?
11
- TopologicalInventoryApiClient::DefaultApi.new(api_client)
12
- end
13
- end
14
-
15
- def update_task(task_id, state:, status:, context:)
16
- task = TopologicalInventoryApiClient::Task.new("state" => state, "status" => status, "context" => context)
17
- topology_api_client.update_task(task_id, task)
18
- end
19
-
20
- def svc_instance_url(service_instance)
21
- rest_api_path = '/service_instances/{id}'.sub('{' + 'id' + '}', service_instance&.id.to_s)
22
- topology_api_client.api_client.build_request(:GET, rest_api_path).url
23
- end
24
- end
25
- end
26
- end
27
- end
28
- end