insights-api-common 4.1.1 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 38345e2eca706bb365900e3e3eb7ea2488d38587b654536cfe60bc04367a9e8c
4
- data.tar.gz: 101d18e408627530170f6b62013ed494970939fa40e46fecb8e38e7cf4493685
3
+ metadata.gz: 2d9fb8764a0f41c1080473eddd2d98dee2df8170f88da25fa2b033470957cf4f
4
+ data.tar.gz: eb025888657a1ad4c68054aba85aa099ae4455e0ec028d1208ca7468f1a7a04d
5
5
  SHA512:
6
- metadata.gz: fcf19c204af28d1a540408f86967e96e25e7345ffe0cdd1cfd9fc07b697cdbfba2abfee9fb9dca9f042c34988826dd3f2e000e57239fd3d1f5a19b1fd72309f8
7
- data.tar.gz: a0bb8e4e1499fcdca95a925565fe601db6cc1a410c2c2d0c36b47ec3d766e248477bb67ecb842d4c79540a4cb3b49df332faa87c9913bb3e2851fe60a8e2a514
6
+ metadata.gz: 9faab22d7dc2bd6f140fbf0db52c1f546101fff8c08039d3acef806495a5381baa5969e63eb345b769869fe321534cbc0fe26601eff88ce327aec22a6cf1a3ea
7
+ data.tar.gz: 928591637a490109a8a3d38841c4b5b79e13205f565a9f14d145270257952885f40cc4cf84574bc70fdb2bc2b4338f17cc55274636261e5de630b7ae558c7e01
@@ -14,7 +14,6 @@ module Insights
14
14
  end
15
15
 
16
16
  def rescue_from_handler(exception)
17
- logger.error("#{exception.class.name}: #{exception.message}\n#{exception.backtrace.join("\n")}")
18
17
  errors = Insights::API::Common::ErrorDocument.new.tap do |error_document|
19
18
  exception_list_from(exception).each do |exc|
20
19
  if api_client_exception?(exc)
@@ -123,7 +123,8 @@ module Insights
123
123
 
124
124
  def sanctified_permit_param(api_doc_definition, attributes)
125
125
  api_doc_definition['properties'].each_with_object([]) do |(k, v), memo|
126
- next unless attributes.each { |attr| attr.include?(k) }
126
+ # only add to the permit hash if we're actually trying to update it.
127
+ next unless attributes.any? { |attr| attr.include?(k) }
127
128
 
128
129
  memo << if v['type'] == 'array'
129
130
  { k => [] }
@@ -7,7 +7,8 @@ module Insights
7
7
  def self.custom_message(exception)
8
8
  case exception.class.to_s
9
9
  when "Pundit::NotAuthorizedError"
10
- "You are not authorized to #{exception.query.delete_suffix('?')} this #{exception.record.model_name.human.downcase}"
10
+ exception.policy.try(:error_message) ||
11
+ "You are not authorized to perform the #{exception.query.to_s.delete_suffix('?')} action for this #{exception.record.model_name.human.downcase}"
11
12
  end
12
13
  end
13
14
  end
@@ -6,12 +6,13 @@ module Insights
6
6
  require 'prometheus_exporter'
7
7
  require 'prometheus_exporter/client'
8
8
 
9
+ setup_custom_metrics(args[:custom_metrics])
10
+
9
11
  return if metrics_port == 0
10
12
 
11
13
  ensure_exporter_server
12
14
  enable_in_process_metrics
13
15
  enable_web_server_metrics(prefix)
14
- setup_custom_metrics(args[:custom_metrics])
15
16
  end
16
17
 
17
18
  private_class_method def self.ensure_exporter_server
@@ -41,14 +42,18 @@ module Insights
41
42
  return if custom_metrics.nil?
42
43
 
43
44
  custom_metrics.each do |metric|
44
- instance_variable_set("@#{metric[:name]}_#{metric[:type]}", PrometheusExporter::Client.default.register(metric[:type], metric[:name], metric[:description]))
45
-
46
- define_singleton_method(metric[:name]) do
47
- case metric[:type]
48
- when :counter
49
- instance_variable_get("@#{metric[:name]}_#{metric[:type]}")&.observe(1)
50
- else
51
- "Metric of type #{metric[:type]} unsupported, implement it in Insights::API::Common::Metrics#L45"
45
+ if metrics_port == 0
46
+ define_singleton_method(metric[:name]) {}
47
+ else
48
+ instance_variable_set("@#{metric[:name]}_#{metric[:type]}", PrometheusExporter::Client.default.register(metric[:type], metric[:name], metric[:description]))
49
+
50
+ define_singleton_method(metric[:name]) do
51
+ case metric[:type]
52
+ when :counter
53
+ instance_variable_get("@#{metric[:name]}_#{metric[:type]}")&.observe(1)
54
+ else
55
+ "Metric of type #{metric[:type]} unsupported, implement it in Insights::API::Common::Metrics#L45"
56
+ end
52
57
  end
53
58
  end
54
59
  end
@@ -441,7 +441,7 @@ module Insights
441
441
  end
442
442
 
443
443
  # Take existing attrs, that we won't generate
444
- ['example', 'format', 'readOnly', 'title', 'description'].each do |property_key|
444
+ ['example', 'format', 'nullable', 'readOnly', 'title', 'description'].each do |property_key|
445
445
  property_value = openapi_contents.dig(*path_parts(SCHEMAS_PATH), klass_name, "properties", key, property_key)
446
446
  properties_value[property_key] = property_value if property_value
447
447
  end
@@ -57,6 +57,9 @@ module Insights
57
57
  self.current = request
58
58
  self.current_request_id = current&.request_id
59
59
  yield current
60
+ rescue => exception
61
+ Rails.logger.error("#{exception.class.name}: #{exception.message}\n#{exception.backtrace.join("\n")}")
62
+ raise
60
63
  ensure
61
64
  self.current = saved
62
65
  self.current_request_id = saved_request_id
@@ -8,7 +8,7 @@ module Insights
8
8
  @route_mapper = route_mapper
9
9
  end
10
10
 
11
- def redirect_major_version(version, prefix, via: [:delete, :get, :options, :patch, :post])
11
+ def redirect_major_version(version, prefix, via: [:delete, :get, :options])
12
12
  route_mapper.match(
13
13
  "/#{version.split('.').first}/*path(.:format)",
14
14
  :format => false,
@@ -1,7 +1,7 @@
1
1
  module Insights
2
2
  module API
3
3
  module Common
4
- VERSION = "4.1.1".freeze
4
+ VERSION = "5.0.0".freeze
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: insights-api-common
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.1
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Insights Authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-09 00:00:00.000000000 Z
11
+ date: 2021-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: acts_as_tenant
@@ -92,14 +92,14 @@ dependencies:
92
92
  requirements:
93
93
  - - "~>"
94
94
  - !ruby/object:Gem::Version
95
- version: '0.2'
95
+ version: 0.2.1
96
96
  type: :runtime
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
100
  - - "~>"
101
101
  - !ruby/object:Gem::Version
102
- version: '0.2'
102
+ version: 0.2.1
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: prometheus_exporter
105
105
  requirement: !ruby/object:Gem::Requirement
@@ -246,6 +246,48 @@ dependencies:
246
246
  - - ">="
247
247
  - !ruby/object:Gem::Version
248
248
  version: 12.3.3
249
+ - !ruby/object:Gem::Dependency
250
+ name: rubocop
251
+ requirement: !ruby/object:Gem::Requirement
252
+ requirements:
253
+ - - "~>"
254
+ - !ruby/object:Gem::Version
255
+ version: 1.0.0
256
+ type: :development
257
+ prerelease: false
258
+ version_requirements: !ruby/object:Gem::Requirement
259
+ requirements:
260
+ - - "~>"
261
+ - !ruby/object:Gem::Version
262
+ version: 1.0.0
263
+ - !ruby/object:Gem::Dependency
264
+ name: rubocop-performance
265
+ requirement: !ruby/object:Gem::Requirement
266
+ requirements:
267
+ - - "~>"
268
+ - !ruby/object:Gem::Version
269
+ version: '1.8'
270
+ type: :development
271
+ prerelease: false
272
+ version_requirements: !ruby/object:Gem::Requirement
273
+ requirements:
274
+ - - "~>"
275
+ - !ruby/object:Gem::Version
276
+ version: '1.8'
277
+ - !ruby/object:Gem::Dependency
278
+ name: rubocop-rails
279
+ requirement: !ruby/object:Gem::Requirement
280
+ requirements:
281
+ - - "~>"
282
+ - !ruby/object:Gem::Version
283
+ version: '2.8'
284
+ type: :development
285
+ prerelease: false
286
+ version_requirements: !ruby/object:Gem::Requirement
287
+ requirements:
288
+ - - "~>"
289
+ - !ruby/object:Gem::Version
290
+ version: '2.8'
249
291
  - !ruby/object:Gem::Dependency
250
292
  name: rspec
251
293
  requirement: !ruby/object:Gem::Requirement