insights-api-common 3.4.2 → 3.5.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.
- checksums.yaml +4 -4
- data/app/models/concerns/insights/api/common/act_as_taggable_on.rb +66 -0
- data/lib/insights/api/common/engine.rb +1 -0
- data/lib/insights/api/common/open_api/docs/doc_v3.rb +3 -3
- data/lib/insights/api/common/open_api/generator.rb +4 -4
- data/lib/insights/api/common/request.rb +12 -0
- data/lib/insights/api/common/system.rb +19 -0
- data/lib/insights/api/common/tenant.rb +21 -0
- data/lib/insights/api/common/user.rb +1 -0
- data/lib/insights/api/common/version.rb +1 -1
- data/spec/support/user_header_spec_helper.rb +54 -3
- metadata +5 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f7c6702af3cef107f81d349b3995a33cb1fb29b1384bfa9c76ea18e997e9c418
|
|
4
|
+
data.tar.gz: 42a9b71481b07c97bbb8d327c98b21d9008786e5ebd8886cfc88dc498ec34f98
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 327d4de25378b3fc553af5989d8e922f07a8085dc9f0f73793154648bd93312144f10ccbe7c0b3ed9544febc14d3643c9e2dbd0a873abf085576299c71af7138
|
|
7
|
+
data.tar.gz: 3b79d627f4848aa40010e341fd77c3a828b2ca0d23c624f31a01fe6359cbdf6b46b0a1b96600da80df07a6518862102437e84fa1bde389b17ecb0525f2f933e5
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
module Insights
|
|
2
|
+
module API
|
|
3
|
+
module Common
|
|
4
|
+
module ActAsTaggableOn
|
|
5
|
+
def acts_as_taggable_on
|
|
6
|
+
class_eval do
|
|
7
|
+
def self.tagging_relation_name
|
|
8
|
+
"#{name.underscore}_tags".to_sym
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
has_many tagging_relation_name
|
|
12
|
+
has_many :tags, :through => tagging_relation_name
|
|
13
|
+
|
|
14
|
+
def self.taggable?
|
|
15
|
+
true
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def tag_list
|
|
19
|
+
tags.pluck(:name)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def tag_add(tag_list, options = {})
|
|
23
|
+
Tag.transaction do
|
|
24
|
+
model_tag_class.transaction do
|
|
25
|
+
Array(tag_list).each do |tag_name|
|
|
26
|
+
next if tagged_with?(tag_name, options)
|
|
27
|
+
tag_params = {:name => tag_name, :tenant_id => tenant.id}
|
|
28
|
+
tag_params.merge!(options)
|
|
29
|
+
tag = Tag.find_or_create_by(tag_params)
|
|
30
|
+
tagging_params = {self.class.name.underscore.to_sym => self, :tag_id => tag.id}
|
|
31
|
+
public_send(self.class.tagging_relation_name).create(tagging_params)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def tagged_with?(tag_name, options = {})
|
|
38
|
+
options[:value] ||= ""
|
|
39
|
+
options[:namespace] ||= ""
|
|
40
|
+
model_tag_class.joins(:tag)
|
|
41
|
+
.exists?(:tags => {:name => tag_name, :namespace => options[:namespace], :value => options[:value]}, self.class.name.underscore.to_sym => self)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def tag_remove(tag_list, options = {})
|
|
45
|
+
options[:value] ||= ""
|
|
46
|
+
options[:namespace] ||= ""
|
|
47
|
+
Tag.joins(self.class.tagging_relation_name)
|
|
48
|
+
.where(:name => Array(tag_list), :namespace => options[:namespace], :value => options[:value], self.class.tagging_relation_name => {self.class.name.underscore.to_sym => self})
|
|
49
|
+
.destroy_all
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def model_tag_class
|
|
53
|
+
self.class.tagging_relation_name.to_s.classify.constantize
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def tagged_with(tag_name, options = {})
|
|
59
|
+
options[:value] ||= ""
|
|
60
|
+
options[:namespace] ||= ""
|
|
61
|
+
joins(tagging_relation_name => :tag).where(:tags => {:name => tag_name, :namespace => options[:namespace], :value => options[:value]})
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -66,8 +66,8 @@ module Insights
|
|
|
66
66
|
end
|
|
67
67
|
end
|
|
68
68
|
|
|
69
|
-
def
|
|
70
|
-
@
|
|
69
|
+
def server_base_path
|
|
70
|
+
@server_base_path ||= @content.fetch_path("servers", 0, "variables", "basePath", "default")
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
def paths
|
|
@@ -82,7 +82,7 @@ module Insights
|
|
|
82
82
|
@routes ||= begin
|
|
83
83
|
paths.flat_map do |path, hash|
|
|
84
84
|
hash.collect do |verb, _details|
|
|
85
|
-
p = File.join(
|
|
85
|
+
p = File.join(server_base_path, path).gsub(/{\w*}/, ":id")
|
|
86
86
|
{:path => p, :verb => verb.upcase}
|
|
87
87
|
end
|
|
88
88
|
end
|
|
@@ -44,18 +44,18 @@ module Insights
|
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
def initialize
|
|
47
|
-
app_prefix, app_name =
|
|
47
|
+
app_prefix, app_name = server_base_path.match(/\A(.*)\/(.*)\/v\d+.\d+\z/).captures
|
|
48
48
|
ENV['APP_NAME'] = app_name
|
|
49
49
|
ENV['PATH_PREFIX'] = app_prefix
|
|
50
50
|
Rails.application.reload_routes!
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
-
def
|
|
53
|
+
def server_base_path
|
|
54
54
|
openapi_contents["servers"].first["variables"]["basePath"]["default"]
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
def applicable_rails_routes
|
|
58
|
-
rails_routes.select { |i| i.path.start_with?(
|
|
58
|
+
rails_routes.select { |i| i.path.start_with?(server_base_path) }
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
def schemas
|
|
@@ -520,7 +520,7 @@ module Insights
|
|
|
520
520
|
def build_paths
|
|
521
521
|
applicable_rails_routes.each_with_object({}) do |route, expected_paths|
|
|
522
522
|
without_format = route.path.split("(.:format)").first
|
|
523
|
-
sub_path = without_format.split(
|
|
523
|
+
sub_path = without_format.split(server_base_path).last.sub(/:[_a-z]*id/, "{id}")
|
|
524
524
|
route_destination = route.controller.split("/").last.camelize
|
|
525
525
|
controller = "Api::V#{api_version.sub(".", "x")}::#{route_destination}Controller".safe_constantize
|
|
526
526
|
klass_name = controller.try(:presentation_name) || route_destination.singularize
|
|
@@ -72,10 +72,22 @@ module Insights
|
|
|
72
72
|
raise IdentityError, "x-rh-identity not found"
|
|
73
73
|
end
|
|
74
74
|
|
|
75
|
+
def tenant
|
|
76
|
+
@tenant ||= Insights::API::Common::Tenant.new(identity).tenant
|
|
77
|
+
end
|
|
78
|
+
|
|
75
79
|
def user
|
|
76
80
|
@user ||= User.new(identity)
|
|
77
81
|
end
|
|
78
82
|
|
|
83
|
+
def system
|
|
84
|
+
@system ||= System.new(identity) if identity.dig("identity", "system").present?
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def auth_type
|
|
88
|
+
identity.dig("identity", "auth_type")
|
|
89
|
+
end
|
|
90
|
+
|
|
79
91
|
def entitlement
|
|
80
92
|
@entitlement ||= Entitlement.new(identity)
|
|
81
93
|
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Insights
|
|
2
|
+
module API
|
|
3
|
+
module Common
|
|
4
|
+
class Tenant
|
|
5
|
+
def initialize(identity)
|
|
6
|
+
@identity = identity["identity"]
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def tenant
|
|
10
|
+
result = identity&.dig("account_number")
|
|
11
|
+
raise IdentityError, "Tenant key doesn't exist" if result.nil?
|
|
12
|
+
result
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
attr_reader :identity
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -23,7 +23,8 @@ module UserHeaderSpecHelper
|
|
|
23
23
|
"identity" => {
|
|
24
24
|
"account_number" => "0369233",
|
|
25
25
|
"type" => "User",
|
|
26
|
-
"
|
|
26
|
+
"auth_type" => "basic-auth",
|
|
27
|
+
"user" => {
|
|
27
28
|
"username" => "jdoe",
|
|
28
29
|
"email" => "jdoe@acme.com",
|
|
29
30
|
"first_name" => "John",
|
|
@@ -33,9 +34,43 @@ module UserHeaderSpecHelper
|
|
|
33
34
|
"is_internal" => false,
|
|
34
35
|
"locale" => "en_US"
|
|
35
36
|
},
|
|
36
|
-
"internal"
|
|
37
|
+
"internal" => {
|
|
38
|
+
"org_id" => "3340851",
|
|
39
|
+
"auth_time" => 6300
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}.freeze
|
|
43
|
+
|
|
44
|
+
DEFAULT_SYSTEM = {
|
|
45
|
+
"entitlements" => {
|
|
46
|
+
"ansible" => {
|
|
47
|
+
"is_entitled" => true
|
|
48
|
+
},
|
|
49
|
+
"hybrid_cloud" => {
|
|
50
|
+
"is_entitled" => true
|
|
51
|
+
},
|
|
52
|
+
"insights" => {
|
|
53
|
+
"is_entitled" => true
|
|
54
|
+
},
|
|
55
|
+
"migrations" => {
|
|
56
|
+
"is_entitled" => true
|
|
57
|
+
},
|
|
58
|
+
"openshift" => {
|
|
59
|
+
"is_entitled" => true
|
|
60
|
+
},
|
|
61
|
+
"smart_management" => {
|
|
62
|
+
"is_entitled" => true
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"identity" => {
|
|
66
|
+
"account_number" => "0369233",
|
|
67
|
+
"type" => "System",
|
|
68
|
+
"auth_type" => "cert-auth",
|
|
69
|
+
"system" => {
|
|
70
|
+
"cn" => "certificate"
|
|
71
|
+
},
|
|
72
|
+
"internal" => {
|
|
37
73
|
"org_id" => "3340851",
|
|
38
|
-
"auth_type" => "basic-auth",
|
|
39
74
|
"auth_time" => 6300
|
|
40
75
|
}
|
|
41
76
|
}
|
|
@@ -49,6 +84,14 @@ module UserHeaderSpecHelper
|
|
|
49
84
|
default_user_hash["identity"]["user"]["username"]
|
|
50
85
|
end
|
|
51
86
|
|
|
87
|
+
def default_auth_type
|
|
88
|
+
default_user_hash["identity"]["auth_type"]
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def default_system_cn
|
|
92
|
+
default_system_hash["identity"]["system"]["cn"]
|
|
93
|
+
end
|
|
94
|
+
|
|
52
95
|
def encode(val)
|
|
53
96
|
if val.kind_of?(Hash)
|
|
54
97
|
hashed = val.stringify_keys
|
|
@@ -62,7 +105,15 @@ module UserHeaderSpecHelper
|
|
|
62
105
|
encode(hash || DEFAULT_USER)
|
|
63
106
|
end
|
|
64
107
|
|
|
108
|
+
def encoded_system_hash(hash = nil)
|
|
109
|
+
encode(hash || DEFAULT_SYSTEM)
|
|
110
|
+
end
|
|
111
|
+
|
|
65
112
|
def default_user_hash
|
|
66
113
|
Marshal.load(Marshal.dump(DEFAULT_USER))
|
|
67
114
|
end
|
|
115
|
+
|
|
116
|
+
def default_system_hash
|
|
117
|
+
Marshal.load(Marshal.dump(DEFAULT_SYSTEM))
|
|
118
|
+
end
|
|
68
119
|
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: 3.
|
|
4
|
+
version: 3.5.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-02-
|
|
11
|
+
date: 2020-02-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: acts_as_tenant
|
|
@@ -315,6 +315,7 @@ files:
|
|
|
315
315
|
- app/controllers/concerns/insights/api/common/tagging_methods.rb
|
|
316
316
|
- app/models/authentication.rb
|
|
317
317
|
- app/models/concerns/encryption_concern.rb
|
|
318
|
+
- app/models/concerns/insights/api/common/act_as_taggable_on.rb
|
|
318
319
|
- app/models/encryption.rb
|
|
319
320
|
- lib/generators/shared_utilities/migration_generator.rb
|
|
320
321
|
- lib/generators/shared_utilities/orm_helper.rb
|
|
@@ -367,6 +368,8 @@ files:
|
|
|
367
368
|
- lib/insights/api/common/request.rb
|
|
368
369
|
- lib/insights/api/common/routing.rb
|
|
369
370
|
- lib/insights/api/common/status.rb
|
|
371
|
+
- lib/insights/api/common/system.rb
|
|
372
|
+
- lib/insights/api/common/tenant.rb
|
|
370
373
|
- lib/insights/api/common/user.rb
|
|
371
374
|
- lib/insights/api/common/version.rb
|
|
372
375
|
- lib/tasks/insights/api/common_tasks.rake
|