insights-api-common 4.0.1 → 4.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: da2ebb5e76ab8009c3a4afda352c91ebcaee7eaa293b1fcc7c55bcd7711f2e6b
4
- data.tar.gz: 2a772f8bc79d01d48f2ca637ba9adcf0a1fa67c1aefda8bb414d45f5111b4558
3
+ metadata.gz: 4a38805baee23f75e802e915bc9bfff80b758d424248a9a0a859d72a28b7d96c
4
+ data.tar.gz: 6e23b3830ae021373b9849a80425b84b3c9b61af0c46812f25827366b39cc745
5
5
  SHA512:
6
- metadata.gz: d174ee5da9f78f4c7312ef570c0e3563d059c7332a1e43ad58ac17d7ec9051a4a8ebda04f7f1afa9b4f0179c0c4751204f25dae81d21eded96186336c6ed61a3
7
- data.tar.gz: e46f808117d0c742c89cc0b477308b8ddfff3e68f72ee36dbd57cc886df1fec97f8070836609c80164457fe98f2982f0a1f25919eee1ffe3aae08400a40696f4
6
+ metadata.gz: 0adc64a561b7539930ede0a335c9e499e763f041bfb517691a5ba8d827d73ee308157a2ec304fceade1b8f4daeb6721d77b9fbfc252e3da819085a5a043b6bb9
7
+ data.tar.gz: '0915bedf1ab6c791d8d9ec5aebb634935826ef0269a76ffbd2e74ac7f83d76b2c4a52dafecc464e59287bd82c6c2ac3bdf4d15a10d948d209e4576ea516338bd'
@@ -48,6 +48,7 @@ module Insights
48
48
  ENV['APP_NAME'] = app_name
49
49
  ENV['PATH_PREFIX'] = app_prefix
50
50
  Rails.application.reload_routes!
51
+ @operation_id_hash = {}
51
52
  end
52
53
 
53
54
  def server_base_path
@@ -117,8 +118,8 @@ module Insights
117
118
  "type" => "object",
118
119
  "properties" => {
119
120
  "status" => {
120
- "type" => "integer",
121
- "example" => 404
121
+ "type" => "string",
122
+ "example" => "404"
122
123
  },
123
124
  "detail" => {
124
125
  "type" => "string",
@@ -200,7 +201,7 @@ module Insights
200
201
  sub_collection = (primary_collection != klass_name)
201
202
  {
202
203
  "summary" => "List #{klass_name.pluralize}#{" for #{primary_collection}" if sub_collection}",
203
- "operationId" => "list#{primary_collection if sub_collection}#{klass_name.pluralize}",
204
+ "operationId" => operation_id(klass_name, primary_collection, sub_collection),
204
205
  "description" => "Returns an array of #{klass_name} objects",
205
206
  "parameters" => [
206
207
  { "$ref" => "##{PARAMETERS_PATH}/QueryLimit" },
@@ -562,6 +563,24 @@ module Insights
562
563
  def schema_overrides
563
564
  {}
564
565
  end
566
+
567
+ def validate_operation_id(name, klass_name)
568
+ if @operation_id_hash.key?(name)
569
+ raise ArgumentError, "operation id cannot be duplicates, #{name} in class #{klass_name} has already been used in class #{@operation_id_hash[name]}"
570
+ end
571
+ @operation_id_hash[name] = klass_name
572
+ end
573
+
574
+ def operation_id(klass_name, primary_collection, sub_collection)
575
+ klass = klass_name.constantize
576
+ name = if klass.respond_to?(:list_operation_id)
577
+ klass.send(:list_operation_id)
578
+ else
579
+ "list#{primary_collection if sub_collection}#{klass_name.pluralize}"
580
+ end
581
+ validate_operation_id(name, klass_name)
582
+ name
583
+ end
565
584
  end
566
585
  end
567
586
  end
@@ -2,7 +2,7 @@ module Insights
2
2
  module API
3
3
  module Common
4
4
  module RBAC
5
- require 'rbac-api-client'
5
+ require 'insights-rbac-api-client'
6
6
 
7
7
  class Seed
8
8
  def initialize(seed_file, user_file = nil)
@@ -2,7 +2,7 @@ module Insights
2
2
  module API
3
3
  module Common
4
4
  module RBAC
5
- require 'rbac-api-client'
5
+ require 'insights-rbac-api-client'
6
6
 
7
7
  class NetworkError < StandardError; end
8
8
  class TimedOutError < StandardError; end
@@ -25,6 +25,14 @@ module Insights
25
25
  Thread.current[:current_request]
26
26
  end
27
27
 
28
+ def self.current_request_id
29
+ Thread.current[:request_id]
30
+ end
31
+
32
+ def self.current_request_id=(id)
33
+ Thread.current[:request_id] = id
34
+ end
35
+
28
36
  def self.current!
29
37
  current || raise(RequestNotSet)
30
38
  end
@@ -45,10 +53,13 @@ module Insights
45
53
 
46
54
  def self.with_request(request)
47
55
  saved = current
56
+ saved_request_id = current&.request_id
48
57
  self.current = request
58
+ self.current_request_id = current&.request_id
49
59
  yield current
50
60
  ensure
51
61
  self.current = saved
62
+ self.current_request_id = saved_request_id
52
63
  end
53
64
 
54
65
  def self.current_forwardable
@@ -1,7 +1,7 @@
1
1
  module Insights
2
2
  module API
3
3
  module Common
4
- VERSION = "4.0.1".freeze
4
+ VERSION = "4.0.2".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.0.1
4
+ version: 4.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: 2020-04-27 00:00:00.000000000 Z
11
+ date: 2020-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: acts_as_tenant
@@ -142,6 +142,20 @@ dependencies:
142
142
  - - "~>"
143
143
  - !ruby/object:Gem::Version
144
144
  version: 0.10.0
145
+ - !ruby/object:Gem::Dependency
146
+ name: insights-rbac-api-client
147
+ requirement: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - "~>"
150
+ - !ruby/object:Gem::Version
151
+ version: '1.0'
152
+ type: :runtime
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - "~>"
157
+ - !ruby/object:Gem::Version
158
+ version: '1.0'
145
159
  - !ruby/object:Gem::Dependency
146
160
  name: graphql
147
161
  requirement: !ruby/object:Gem::Requirement
@@ -399,7 +413,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
399
413
  - !ruby/object:Gem::Version
400
414
  version: '0'
401
415
  requirements: []
402
- rubygems_version: 3.0.3
416
+ rubygems_version: 3.0.8
403
417
  signing_key:
404
418
  specification_version: 4
405
419
  summary: Common Utilites for Insights microservices