Class: TopologicalInventory::Providers::Common::Operations::SourcesApiClient
- Inherits:
-
SourcesApiClient::ApiClient
- Object
- SourcesApiClient::ApiClient
- TopologicalInventory::Providers::Common::Operations::SourcesApiClient
- Defined in:
- lib/topological_inventory/providers/common/operations/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.
12 13 14 15 16 |
# File 'lib/topological_inventory/providers/common/operations/sources_api_client.rb', line 12 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
28 29 30 31 |
# File 'lib/topological_inventory/providers/common/operations/sources_api_client.rb', line 28 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
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/topological_inventory/providers/common/operations/sources_api_client.rb', line 33 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
23 24 25 26 |
# File 'lib/topological_inventory/providers/common/operations/sources_api_client.rb', line 23 def fetch_default_endpoint(source_id) endpoints = api.list_source_endpoints(source_id)&.data || [] endpoints.find(&:default) end |
#init_default_api ⇒ Object
18 19 20 21 |
# File 'lib/topological_inventory/providers/common/operations/sources_api_client.rb', line 18 def init_default_api default_headers.merge!(identity) if identity.present? ::SourcesApiClient::DefaultApi.new(self) end |