insights-api-common 4.1.3 → 5.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/lib/insights/api/common/application_controller_mixins/exception_handling.rb +0 -1
- data/lib/insights/api/common/application_controller_mixins/parameters.rb +2 -1
- data/lib/insights/api/common/custom_exceptions.rb +2 -1
- data/lib/insights/api/common/filter.rb +12 -2
- data/lib/insights/api/common/graphql/generator.rb +25 -1
- data/lib/insights/api/common/metrics.rb +1 -1
- data/lib/insights/api/common/request.rb +3 -0
- data/lib/insights/api/common/routing.rb +1 -1
- data/lib/insights/api/common/version.rb +1 -1
- metadata +48 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2aa2430e936c484f6b54cbcc8587462ab0ace760f6a2ab7a295e02258953a932
|
4
|
+
data.tar.gz: a41b5a30792c05b38b48df621f60ced0aa098b49fc6c1dbf3282d36bfbb5830c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48d2cff3476fa94a453cdb247c2a452a6197729f531361ac093e76c03530777f22a097487b1a0f4bcc6e733cad32f7425764d976ddc2a72d2edb1efe84e15eb8
|
7
|
+
data.tar.gz: da7a2598ce95a1769f028a26461436a5962aa2455605dbf4ac7fd23a5c86d7ca0aaaa2eb68e20e423286a5d2e8cc812892cf94fc26b6200acac2d1cd94e636c3
|
data/README.md
CHANGED
@@ -30,6 +30,7 @@ Or install it yourself as:
|
|
30
30
|
| Supported Comparators | Comparator |
|
31
31
|
| --------------------- | ---------- |
|
32
32
|
| Integer | eq |
|
33
|
+
| | not_eq |
|
33
34
|
| | gt |
|
34
35
|
| | gte |
|
35
36
|
| | lt |
|
@@ -37,12 +38,14 @@ Or install it yourself as:
|
|
37
38
|
| | nil |
|
38
39
|
| | not_nil |
|
39
40
|
| String | eq |
|
41
|
+
| | not_eq |
|
40
42
|
| | contains |
|
41
43
|
| | starts_with |
|
42
44
|
| | ends_with |
|
43
45
|
| | nil |
|
44
46
|
| | not_nil |
|
45
47
|
| String (case insensitive) | eq_i |
|
48
|
+
| | not_eq_i |
|
46
49
|
| | contains_i |
|
47
50
|
| | starts_with_i |
|
48
51
|
| | ends_with_i |
|
@@ -53,6 +56,7 @@ After implementing filtering in your application, this is the way to filter via
|
|
53
56
|
| --------------- | --------------------- | ----------------- |
|
54
57
|
| "?filter[name]=reviews" | { :filter => { :name => "reviews" } } | filter: { name: "reviews" } |
|
55
58
|
| "?filter[name][eq]=reviews" | { :filter => { :name => { :eq => "reviews" } } } | filter: { name: { eq: "reviews" } } |
|
59
|
+
| "?filter[name][not_eq]=reviews" | { :filter => { :name => { :not_eq => "reviews" } } } | filter: { name: { not_eq: "reviews" } } |
|
56
60
|
| "?filter[name][starts_with]=a" | { :filter => { :name => { :starts_with => "a" } } } | filter: { name: { starts_with: "a" } } |
|
57
61
|
| "?filter[name][ends_with]=manager" | { :filter => { :name => { :ends_with => "manager" } } } | filter: { name: { ends_with: "manager" } } |
|
58
62
|
| "?filter[name][contains]=openshift" | { :filter => { :name => { :contains => "openshift" } } } | filter: { name: { contains: "openshift" } } |
|
@@ -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
|
-
|
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
|
-
|
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
|
@@ -2,8 +2,8 @@ module Insights
|
|
2
2
|
module API
|
3
3
|
module Common
|
4
4
|
class Filter
|
5
|
-
INTEGER_COMPARISON_KEYWORDS = ["eq", "gt", "gte", "lt", "lte", "nil", "not_nil"].freeze
|
6
|
-
STRING_COMPARISON_KEYWORDS = ["contains", "contains_i", "eq", "eq_i", "starts_with", "starts_with_i", "ends_with", "ends_with_i", "nil", "not_nil"].freeze
|
5
|
+
INTEGER_COMPARISON_KEYWORDS = ["eq", "not_eq", "gt", "gte", "lt", "lte", "nil", "not_nil"].freeze
|
6
|
+
STRING_COMPARISON_KEYWORDS = ["contains", "contains_i", "eq", "not_eq", "eq_i", "not_eq_i", "starts_with", "starts_with_i", "ends_with", "ends_with_i", "nil", "not_nil"].freeze
|
7
7
|
ALL_COMPARISON_KEYWORDS = (INTEGER_COMPARISON_KEYWORDS + STRING_COMPARISON_KEYWORDS).uniq.freeze
|
8
8
|
|
9
9
|
attr_reader :apply, :arel_table, :api_doc_definition, :extra_filterable_attributes, :model
|
@@ -242,6 +242,16 @@ module Insights
|
|
242
242
|
self.query = query.where(model_arel_attribute(key).eq_any(Array(value)))
|
243
243
|
end
|
244
244
|
|
245
|
+
def comparator_not_eq(key, value)
|
246
|
+
self.query = query.where.not(model_arel_attribute(key).eq_any(Array(value)))
|
247
|
+
end
|
248
|
+
|
249
|
+
def comparator_not_eq_i(key, value)
|
250
|
+
values = Array(value).map { |v| query.sanitize_sql_like(v.downcase) }
|
251
|
+
|
252
|
+
self.query = query.where.not(model_arel_table(key).grouping(arel_lower(key).matches_any(values)))
|
253
|
+
end
|
254
|
+
|
245
255
|
def comparator_eq_i(key, value)
|
246
256
|
values = Array(value).map { |v| query.sanitize_sql_like(v.downcase) }
|
247
257
|
|
@@ -20,8 +20,32 @@ module Insights
|
|
20
20
|
openapi_path.split("/")[1..-1]
|
21
21
|
end
|
22
22
|
|
23
|
+
def self.template_file_by(type, root_dir = __dir__)
|
24
|
+
Pathname.new(root_dir).join(File.expand_path("templates", root_dir), "#{type}.erb")
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.root_dir
|
28
|
+
Rails.root
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.app_name
|
32
|
+
Rails.application.class.parent.name.underscore
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.pluggable_template_file_by(type)
|
36
|
+
templates_relative_path = "lib/#{app_name}/api/graphql/templates"
|
37
|
+
template_path = File.expand_path(templates_relative_path, root_dir)
|
38
|
+
Pathname.new(root_dir).join(template_path, "#{type}.erb")
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.template_path_by(type)
|
42
|
+
template_path_pluggable = pluggable_template_file_by(type)
|
43
|
+
template_path_default = template_file_by(type)
|
44
|
+
template_path_pluggable.exist? ? template_path_pluggable : template_path_default
|
45
|
+
end
|
46
|
+
|
23
47
|
def self.template(type)
|
24
|
-
File.read(
|
48
|
+
File.read(template_path_by(type))
|
25
49
|
end
|
26
50
|
|
27
51
|
def self.graphql_type(property_name, property_format, property_type)
|
@@ -17,7 +17,7 @@ module Insights
|
|
17
17
|
|
18
18
|
private_class_method def self.ensure_exporter_server
|
19
19
|
require 'socket'
|
20
|
-
TCPSocket.open("
|
20
|
+
TCPSocket.open("127.0.0.1", metrics_port) {}
|
21
21
|
rescue Errno::ECONNREFUSED
|
22
22
|
require 'prometheus_exporter/server'
|
23
23
|
server = PrometheusExporter::Server::WebServer.new(port: metrics_port)
|
@@ -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
|
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,
|
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
|
+
version: 5.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Insights Authors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: acts_as_tenant
|
@@ -160,16 +160,16 @@ dependencies:
|
|
160
160
|
name: graphql
|
161
161
|
requirement: !ruby/object:Gem::Requirement
|
162
162
|
requirements:
|
163
|
-
- -
|
163
|
+
- - '='
|
164
164
|
- !ruby/object:Gem::Version
|
165
|
-
version:
|
165
|
+
version: 1.11.7
|
166
166
|
type: :runtime
|
167
167
|
prerelease: false
|
168
168
|
version_requirements: !ruby/object:Gem::Requirement
|
169
169
|
requirements:
|
170
|
-
- -
|
170
|
+
- - '='
|
171
171
|
- !ruby/object:Gem::Version
|
172
|
-
version:
|
172
|
+
version: 1.11.7
|
173
173
|
- !ruby/object:Gem::Dependency
|
174
174
|
name: graphql-batch
|
175
175
|
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
|