Class: TopologicalInventory::Providers::Common::SourcesApiClient
- Inherits:
-
SourcesApiClient::ApiClient
- Object
- SourcesApiClient::ApiClient
- TopologicalInventory::Providers::Common::SourcesApiClient
- Defined in:
- lib/topological_inventory/providers/common/sources_api_client.rb
Constant Summary collapse
- INTERNAL_API_PATH =
'//internal/v1.0'.freeze
Instance Method Summary collapse
- #fetch_application(source_id) ⇒ Object
- #fetch_authentication(source_id, default_endpoint = nil, authtype = nil) ⇒ Object
- #fetch_default_endpoint(source_id) ⇒ Object
- #init_default_api ⇒ Object
-
#initialize(identity = nil) ⇒ SourcesApiClient
constructor
A new instance of SourcesApiClient.
Constructor Details
#initialize(identity = nil) ⇒ SourcesApiClient
Returns a new instance of SourcesApiClient.
11 12 13 14 15 |
# File 'lib/topological_inventory/providers/common/sources_api_client.rb', line 11 def initialize(identity = nil) super(::SourcesApiClient::Configuration.default) self.identity = identity self.api = init_default_api end |
Instance Method Details
#fetch_application(source_id) ⇒ Object
27 28 29 30 |
# File 'lib/topological_inventory/providers/common/sources_api_client.rb', line 27 def fetch_application(source_id) applications = api.list_source_applications(source_id)&.data || [] applications.first end |
#fetch_authentication(source_id, default_endpoint = nil, authtype = nil) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/topological_inventory/providers/common/sources_api_client.rb', line 32 def fetch_authentication(source_id, default_endpoint = nil, authtype = nil) endpoint = default_endpoint || fetch_default_endpoint(source_id) return if endpoint.nil? endpoint_authentications = api.list_endpoint_authentications(endpoint.id.to_s).data || [] return if endpoint_authentications.empty? auth_id = if authtype.nil? endpoint_authentications.first&.id else endpoint_authentications.detect { |a| a.authtype = authtype }&.id end return if auth_id.nil? fetch_authentication_with_password(auth_id) end |
#fetch_default_endpoint(source_id) ⇒ Object
22 23 24 25 |
# File 'lib/topological_inventory/providers/common/sources_api_client.rb', line 22 def fetch_default_endpoint(source_id) endpoints = api.list_source_endpoints(source_id)&.data || [] endpoints.find(&:default) end |
#init_default_api ⇒ Object
17 18 19 20 |
# File 'lib/topological_inventory/providers/common/sources_api_client.rb', line 17 def init_default_api default_headers.merge!(identity) if identity.present? ::SourcesApiClient::DefaultApi.new(self) end |