oci-logging-analytics-kubernetes-discovery 1.0.3 → 1.1.0

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.
@@ -33,7 +33,7 @@ module Util
33
33
  upload_discovery_data_details = payload,
34
34
  opts)
35
35
  rescue StandardError => e
36
- logger.error("Error while uploading payload to 'Log Analytics': #{e}")
36
+ logger.error("Error while uploading payload to 'Log Analytics'. Error: #{e}")
37
37
  raise StandardError, "Unable to upload data to 'Log Analytics' client."
38
38
  end
39
39
  response
@@ -56,7 +56,7 @@ module Util
56
56
  region = signer.region
57
57
  else
58
58
  logger.warn("Unknown auth_type provided for Discovery API (raw request): #{auth_object[:auth_type]}")
59
- raise StandardError 'Unknown auth_type for Discovery API (raw request)'
59
+ raise StandardError, 'Unknown auth_type for Discovery API (raw request)'
60
60
  end
61
61
 
62
62
  # Construct URL protocol, subdomain, domain and port
@@ -15,10 +15,10 @@ module Util
15
15
 
16
16
  attr_accessor :oci_clients, :ce_client, :id_client, :lb_client, :la_client, :rs_client,
17
17
  :vcn_client, :oci_config, :instance_principals_signer, :la_endpoint,
18
- :auth_type, :auth_config_object, :oci_domain
18
+ :auth_type, :auth_config_object, :oci_domain, :oci_retry_config, :oci_region
19
19
 
20
20
  # This must be the first method called before any other method
21
- def initialize(auth_config_hash, options)
21
+ def initialize(auth_config_hash)
22
22
  begin
23
23
  initialize_auth_config(auth_config_hash)
24
24
  rescue StandardError => e
@@ -28,7 +28,7 @@ module Util
28
28
  logger.debug('Successfully loaded the OCI auth config.')
29
29
 
30
30
  begin
31
- create_clients(options)
31
+ create_clients
32
32
  rescue StandardError => e
33
33
  logger.error("Error occurred in creating OCI clients - #{e}")
34
34
  raise e
@@ -38,27 +38,86 @@ module Util
38
38
  set_clients
39
39
  end
40
40
 
41
- def create_clients(options)
41
+ def initialize_auth_config(auth_config_hash)
42
+ @auth_type = auth_config_hash[:auth_type]
43
+ @oci_domain = auth_config_hash[:oci_domain]
44
+ @la_endpoint = auth_config_hash[:endpoint]
45
+
42
46
  begin
43
- @la_client = initialize_la_client(nil)
47
+ if @auth_type == Enum::AuthTypeEnum::INSTANCE_PRINCIPAL
48
+ @oci_config = OCI::Config.new
49
+ if @oci_domain.nil?
50
+ @instance_principals_signer = OCI::Auth::Signers::InstancePrincipalsSecurityTokenSigner.new
51
+ else
52
+ federation_endpoint = "https://auth.#{@oci_domain}/v1/x509"
53
+ logger.info("Federation Endpoint: #{federation_endpoint}")
54
+ @instance_principals_signer = OCI::Auth::Signers::InstancePrincipalsSecurityTokenSigner.new(
55
+ federation_endpoint: federation_endpoint
56
+ )
57
+ end
58
+ @oci_region = @instance_principals_signer.region
59
+ # elsif @auth_type == Enum::AuthTypeEnum::OKE_WORKLOAD_IDENTITY
60
+ # @workload_identity_signer = OCI::Auth::Signers::oke_workload_resource_principal_signer
61
+ elsif @auth_type == Enum::AuthTypeEnum::CONFIG
62
+ @oci_config = OCI::ConfigFileLoader.load_config(config_file_location: auth_config_hash[:config_file_location],
63
+ profile_name: auth_config_hash[:profile_name])
64
+ @oci_region = @oci_config.region
65
+ else
66
+ raise Exception::InvalidOption, "#{@auth_type}"
67
+ end
68
+ rescue StandardError => e
69
+ logger.error("Error occurred while initializing OCI authentication configuration. Error: #{e}")
70
+ raise e
71
+ end
72
+ set_auth_config_object
73
+ end
74
+
75
+ def set_clients
76
+ @oci_clients = {
77
+ ce_client: @ce_client,
78
+ id_client: @id_client,
79
+ lb_client: @lb_client,
80
+ la_client: @la_client,
81
+ rqs_client: @rqs_client,
82
+ vcn_client: @vcn_client,
83
+ rms_client: @rms_client
84
+ }
85
+ end
86
+
87
+ def get_clients
88
+ @oci_clients
89
+ end
90
+
91
+ def get_region
92
+ @oci_region
93
+ end
44
94
 
45
- return if options[:mode] == 'object'
95
+ def get_domain
96
+ @oci_domain
97
+ end
46
98
 
99
+ def create_clients()
100
+ begin
101
+ @oci_retry_config = Config::OCIClientRetryConfig.custom_retry_policy
102
+
103
+ @la_client = initialize_la_client
47
104
  @ce_client = initialize_ce_client
48
105
  @id_client = initialize_id_client
49
106
  @lb_client = initialize_lb_client
50
- @rs_client = initialize_rs_client
107
+ @rqs_client = initialize_rqs_client
51
108
  @vcn_client = initialize_vcn_client
52
-
109
+ @rms_client = initialize_rms_client
53
110
  rescue StandardError => e
54
111
  logger.error("Error while creating OCI clients. Error: #{e}")
55
112
  raise e
56
113
  end
114
+ logger.info('OCI clients created.')
57
115
  end
58
116
 
59
117
  def initialize_ce_client()
60
118
  client = nil
61
119
  endpoint = nil
120
+ retry_config = Config::OCIClientRetryConfig.oci_default_retry_config if @oci_retry_config.nil?
62
121
  unless @oci_domain.nil?
63
122
  endpoint = "https://containerengine.#{@oci_domain}"
64
123
  logger.info("CE Client endpoint: #{endpoint}")
@@ -67,13 +126,16 @@ module Util
67
126
  begin
68
127
  case @auth_type
69
128
  when Enum::AuthTypeEnum::CONFIG
70
- client = OCI::ContainerEngine::ContainerEngineClient.new(config: @oci_config, endpoint: endpoint)
129
+ client = OCI::ContainerEngine::ContainerEngineClient.new(config: @oci_config, endpoint: endpoint, retry_config: retry_config)
71
130
  when Enum::AuthTypeEnum::INSTANCE_PRINCIPAL
72
- client = OCI::ContainerEngine::ContainerEngineClient.new(config: @oci_config, endpoint: endpoint, signer: @instance_principals_signer)
131
+ client = OCI::ContainerEngine::ContainerEngineClient.new(
132
+ config: @oci_config, endpoint: endpoint,
133
+ signer: @instance_principals_signer,
134
+ retry_config: retry_config)
73
135
  else
74
136
  logger.warn("Unknown auth_type '#{@auth_type}' provided for container engine client.")
75
137
  end
76
- logger.info("CE Client created.")
138
+ logger.debug('CE Client created.')
77
139
  @ce_client = client
78
140
  rescue StandardError => e
79
141
  logger.error("Error while creating container engine client: #{e}")
@@ -85,6 +147,7 @@ module Util
85
147
  def initialize_id_client()
86
148
  client = nil
87
149
  endpoint = nil
150
+ retry_config = Config::OCIClientRetryConfig.oci_default_retry_config if @oci_retry_config.nil?
88
151
  unless @oci_domain.nil?
89
152
  endpoint = "https://identity.#{@oci_domain}"
90
153
  logger.info("ID Client endpoint: #{endpoint}")
@@ -93,13 +156,13 @@ module Util
93
156
  begin
94
157
  case @auth_type
95
158
  when Enum::AuthTypeEnum::CONFIG
96
- client = OCI::Identity::IdentityClient.new(config: @oci_config, endpoint: endpoint)
97
- when Enum::AuthTypeEnum::PRINCIPAL
98
- client = OCI::Identity::IdentityClient.new(config: @oci_config, endpoint: endpoint, signer: @instance_principals_signer)
159
+ client = OCI::Identity::IdentityClient.new(config: @oci_config, endpoint: endpoint, retry_config: retry_config)
160
+ when Enum::AuthTypeEnum::INSTANCE_PRINCIPAL
161
+ client = OCI::Identity::IdentityClient.new(config: @oci_config, endpoint: endpoint, signer: @instance_principals_signer, retry_config: retry_config)
99
162
  else
100
163
  logger.warn("Unknown auth_type '#{@auth_type}' provided for identity client.")
101
164
  end
102
- logger.info("ID Client created.")
165
+ logger.debug('ID Client created.')
103
166
  @id_client = client
104
167
  rescue StandardError => e
105
168
  logger.error("Error while creating identity client: #{e}")
@@ -111,6 +174,7 @@ module Util
111
174
  def initialize_lb_client()
112
175
  client = nil
113
176
  endpoint = nil
177
+ retry_config = Config::OCIClientRetryConfig.oci_default_retry_config if @oci_retry_config.nil?
114
178
  unless @oci_domain.nil?
115
179
  endpoint = "https://iaas.#{@oci_domain}"
116
180
  logger.info("LB Client endpoint: #{endpoint}")
@@ -119,13 +183,13 @@ module Util
119
183
  begin
120
184
  case @auth_type
121
185
  when Enum::AuthTypeEnum::CONFIG
122
- client = OCI::LoadBalancer::LoadBalancerClient.new(config: @oci_config, endpoint: endpoint)
123
- when Enum::AuthTypeEnum::PRINCIPAL
124
- client = OCI::LoadBalancer::LoadBalancerClient.new(config: @oci_config, endpoint: endpoint, signer: @instance_principals_signer)
186
+ client = OCI::LoadBalancer::LoadBalancerClient.new(config: @oci_config, endpoint: endpoint, retry_config: retry_config)
187
+ when Enum::AuthTypeEnum::INSTANCE_PRINCIPAL
188
+ client = OCI::LoadBalancer::LoadBalancerClient.new(config: @oci_config, endpoint: endpoint, signer: @instance_principals_signer, retry_config: retry_config)
125
189
  else
126
190
  logger.warn("Unknown auth_type '#{@auth_type}' provided for load balancer client.")
127
191
  end
128
- logger.info("LB Client created.")
192
+ logger.debug('LB Client created.')
129
193
  @lb_client = client
130
194
  rescue StandardError => e
131
195
  logger.error("Error while creating load balancer client: #{e}")
@@ -134,10 +198,11 @@ module Util
134
198
  @lb_client
135
199
  end
136
200
 
137
- def initialize_la_client(custom_retry_config)
138
- logger.debug("Creating log analytics client with auth_type: #{@auth_type}")
201
+ def initialize_la_client()
202
+ client = nil
203
+ retry_config = Config::OCIClientRetryConfig.oci_default_retry_config if @oci_retry_config.nil?
139
204
 
140
- Config::OCIClientRetryConfig.set_custom_retry_config(custom_retry_config) unless custom_retry_config.nil?
205
+ logger.debug("Creating log analytics client with auth_type: #{@auth_type}")
141
206
 
142
207
  endpoint = @la_endpoint
143
208
  if endpoint.nil? && !@oci_domain.nil?
@@ -145,24 +210,22 @@ module Util
145
210
  logger.info("LA Client endpoint: #{endpoint}")
146
211
  end
147
212
 
148
- client = nil
149
-
150
213
  begin
151
214
  case @auth_type
152
215
  when Enum::AuthTypeEnum::CONFIG
153
216
  client = OCI::LogAnalytics::LogAnalyticsClient.new(config: @oci_config,
154
217
  endpoint: endpoint,
155
- retry_config: Config::OCIClientRetryConfig.get_retry_config)
218
+ retry_config: retry_config)
156
219
  when Enum::AuthTypeEnum::INSTANCE_PRINCIPAL
157
220
  client = OCI::LogAnalytics::LogAnalyticsClient.new(config: @oci_config,
158
221
  endpoint: endpoint,
159
222
  signer: @instance_principals_signer,
160
- retry_config: Config::OCIClientRetryConfig.get_retry_config)
223
+ retry_config: retry_config)
161
224
  else
162
225
  logger.warn("Unknown auth_type while creating log analytics client: #{@auth_type}")
163
226
  raise StandardError, 'Unknown auth_type for log analytics client.'
164
227
  end
165
- logger.info("LA Client created.")
228
+ logger.debug('LA Client created.')
166
229
  @la_client = client
167
230
  rescue StandardError => e
168
231
  logger.error("Error while creating log analytics client: #{e}")
@@ -171,50 +234,60 @@ module Util
171
234
  @la_client
172
235
  end
173
236
 
174
- def initialize_rs_client()
237
+ def initialize_rqs_client()
175
238
  client = nil
176
239
  endpoint = nil
240
+ retry_config = Config::OCIClientRetryConfig.oci_default_retry_config if @oci_retry_config.nil?
241
+
177
242
  unless @oci_domain.nil?
178
243
  endpoint = "https://query.#{@oci_domain}"
179
- logger.info("RS Client endpoint: #{endpoint}")
244
+ logger.info("RQS Client endpoint: #{endpoint}")
180
245
  end
246
+
181
247
  logger.debug("Creating resource search client with auth_type: #{@auth_type}")
248
+
182
249
  begin
183
250
  case @auth_type
184
251
  when Enum::AuthTypeEnum::CONFIG
185
- client = OCI::ResourceSearch::ResourceSearchClient.new(config: @oci_config, endpoint: endpoint)
186
- when Enum::AuthTypeEnum::PRINCIPAL
187
- client = OCI::ResourceSearch::ResourceSearchClient.new(config: @oci_config, endpoint: endpoint, signer: @instance_principals_signer)
252
+ client = OCI::ResourceSearch::ResourceSearchClient.new(config: @oci_config, endpoint: endpoint, retry_config: retry_config)
253
+ when Enum::AuthTypeEnum::INSTANCE_PRINCIPAL
254
+ client = OCI::ResourceSearch::ResourceSearchClient.new(config: @oci_config, endpoint: endpoint, signer: @instance_principals_signer, retry_config: retry_config)
188
255
  else
189
256
  logger.warn("Unknown auth_type '#{@auth_type}' provided for resource search client.")
190
257
  end
191
- logger.info("RS Client created.")
192
- @rs_client = client
258
+ logger.debug('RQS Client created.')
259
+ @rqs_client = client
193
260
  rescue StandardError => e
194
261
  logger.error("Error while creating resource search client: #{e}")
195
262
  raise e
196
263
  end
197
- @rs_client
264
+ @rqs_client
198
265
  end
199
266
 
200
267
  def initialize_vcn_client()
201
268
  client = nil
202
269
  endpoint = nil
270
+ retry_config = Config::OCIClientRetryConfig.oci_default_retry_config if @oci_retry_config.nil?
271
+
203
272
  unless @oci_domain.nil?
204
- endpoint = "https://iass.#{@oci_domain}"
273
+ # NOTE: Dec 3rd, 2024
274
+ # VCN endpoint does not support region.oci.domain template hence converting to region.domain template
275
+ endpoint = "https://iaas.#{@oci_domain.gsub('.oci', '')}"
205
276
  logger.info("VCN Client endpoint: #{endpoint}")
206
277
  end
278
+
207
279
  logger.debug("Creating virtual network client with auth_type: #{@auth_type}")
280
+
208
281
  begin
209
282
  case @auth_type
210
283
  when Enum::AuthTypeEnum::CONFIG
211
- client = OCI::Core::VirtualNetworkClient.new(config: @oci_config, endpoint: endpoint)
212
- when Enum::AuthTypeEnum::PRINCIPAL
213
- client = OCI::Core::VirtualNetworkClient.new(config: @oci_config, endpoint: endpoint, signer: @instance_principals_signer)
284
+ client = OCI::Core::VirtualNetworkClient.new(config: @oci_config, endpoint: endpoint, retry_config: retry_config)
285
+ when Enum::AuthTypeEnum::INSTANCE_PRINCIPAL
286
+ client = OCI::Core::VirtualNetworkClient.new(config: @oci_config, endpoint: endpoint, signer: @instance_principals_signer, retry_config: retry_config)
214
287
  else
215
288
  logger.warn("Unknown auth_type '#{@auth_type}' provided for virtual network client.")
216
289
  end
217
- logger.info("VCN Client created.")
290
+ logger.debug('VCN Client created.')
218
291
  @vcn_client = client
219
292
  rescue StandardError => e
220
293
  logger.error("Error while creating virtual network client: #{e}")
@@ -223,51 +296,37 @@ module Util
223
296
  @vcn_client
224
297
  end
225
298
 
226
- def initialize_auth_config(auth_config_hash)
227
- @auth_type = auth_config_hash[:auth_type]
228
- @oci_domain = auth_config_hash[:oci_domain]
229
- @la_endpoint = auth_config_hash[:endpoint]
299
+ def initialize_rms_client()
300
+ client = nil
301
+ endpoint = nil
302
+ retry_config = Config::OCIClientRetryConfig.oci_default_retry_config if @oci_retry_config.nil?
303
+
304
+ unless @oci_domain.nil?
305
+ endpoint = "https://resourcemanager.#{@oci_domain}"
306
+ logger.info("VCN Client endpoint: #{endpoint}")
307
+ end
230
308
 
231
309
  begin
232
- if @auth_type == Enum::AuthTypeEnum::INSTANCE_PRINCIPAL
233
- @oci_config = OCI::Config.new
234
- if @oci_domain.nil?
235
- @instance_principals_signer = OCI::Auth::Signers::InstancePrincipalsSecurityTokenSigner.new
236
- else
237
- fedration_endpoint = "https://auth.#{@oci_domain}/v1/x509"
238
- logger.info("Federation Endpoint: #{fedration_endpoint}")
239
- @instance_principals_signer = OCI::Auth::Signers::InstancePrincipalsSecurityTokenSigner.new(
240
- federation_endpoint: fedration_endpoint
241
- )
242
- end
243
- # elsif @auth_type == Enum::AuthTypeEnum::OKE_WORKLOAD_IDENTITY
244
- # @workload_identity_signer = OCI::Auth::Signers::oke_workload_resource_principal_signer
245
- elsif @auth_type == Enum::AuthTypeEnum::CONFIG
246
- @oci_config = OCI::ConfigFileLoader.load_config(config_file_location: auth_config_hash[:config_file_location],
247
- profile_name: auth_config_hash[:profile_name])
310
+ case @auth_type
311
+ when Enum::AuthTypeEnum::CONFIG
312
+ client = OCI::ResourceManager::ResourceManagerClient.new(config: @oci_config,
313
+ endpoint: endpoint,
314
+ retry_config: retry_config)
315
+ when Enum::AuthTypeEnum::INSTANCE_PRINCIPAL
316
+ client = OCI::ResourceManager::ResourceManagerClient.new(config: @oci_config,
317
+ endpoint: endpoint,
318
+ signer: @instance_principals_signer,
319
+ retry_config: retry_config)
248
320
  else
249
- raise Exception::InvalidOption, "#{@auth_type}"
321
+ logger.warn("Unknown auth_type '#{auth_object[:auth_type]}' provided for resource manager client.")
250
322
  end
323
+ logger.debug('RMS Client created.')
324
+ @rms_client = client
251
325
  rescue StandardError => e
252
- logger.error("Error occurred while initializing OCI authentication configuration. Error: #{e}")
326
+ logger.error("Error while creating resource manager client: #{e}")
253
327
  raise e
254
328
  end
255
- set_auth_config_object
256
- end
257
-
258
- def get_clients
259
- @oci_clients
260
- end
261
-
262
- def set_clients
263
- @oci_clients = {
264
- ce_client: @ce_client,
265
- id_client: @id_client,
266
- lb_client: @lb_client,
267
- la_client: @la_client,
268
- rs_client: @rs_client,
269
- vcn_client: @vcn_client
270
- }
329
+ @rms_client
271
330
  end
272
331
 
273
332
  def get_auth_config_object