foreman_rh_cloud 13.2.11 → 13.2.12
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '02381fe754515035b984e0c7a5a8b8c3b84f6a9ec086bae66ca4c5edf6109c53'
|
|
4
|
+
data.tar.gz: 239b22edd6071beadb3a32377f8560ea3a0f3079b00a486b2bc12733d77f3d3d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0eb11bb0ff17fc1ae0a6e7ac2c43a2f91adf6b6f0299f5570ba6d58fa2a8dd7045f35a7dbe380e98f5debda30d41e3aff5898125f0498672117914fcffbbb9c1
|
|
7
|
+
data.tar.gz: b0341e69c8718e61f1695a5c9ecca09064cab6927f163249bf774e3dc770bac599e15fce4798b1c56ea4d13671961089774d25756dfb00e5ac3bfa0fd6bbf5ce
|
|
@@ -5,6 +5,7 @@ module ForemanRhCloud
|
|
|
5
5
|
TAG_NAMESPACE = 'sat_iam'.freeze
|
|
6
6
|
TAG_SHORT_NAME = 'scope'.freeze
|
|
7
7
|
TAG_NAME = "#{TAG_NAMESPACE}/#{TAG_SHORT_NAME}".freeze
|
|
8
|
+
SYNC_CACHE_TTL = 10.seconds
|
|
8
9
|
|
|
9
10
|
def self.auth_tag_for(user, org, loc)
|
|
10
11
|
new(user, org, loc, nil).auth_tag
|
|
@@ -20,20 +21,28 @@ module ForemanRhCloud
|
|
|
20
21
|
end
|
|
21
22
|
|
|
22
23
|
def update_tag
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
cached = Rails.cache.read(sync_identity)
|
|
25
|
+
return cached if cached
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
Foreman::AdvisoryLockManager.with_session_lock(sync_identity) do
|
|
28
|
+
Rails.cache.fetch(sync_identity, expires_in: SYNC_CACHE_TTL) do
|
|
29
|
+
loc_name = location_name_for_tag
|
|
30
|
+
logger.debug("Updating tags for user: #{@user}, org: #{@org.name}, loc: #{loc_name}")
|
|
31
|
+
|
|
32
|
+
payload = tags_query_payload
|
|
33
|
+
params = {
|
|
34
|
+
organization: @org,
|
|
35
|
+
method: :post,
|
|
36
|
+
url: "#{InsightsCloud.gateway_url}/tags",
|
|
37
|
+
headers: {
|
|
38
|
+
content_type: :json,
|
|
39
|
+
},
|
|
40
|
+
payload: payload.to_json,
|
|
41
|
+
}
|
|
42
|
+
execute_cloud_request(params) unless payload[:host_id_list].empty?
|
|
43
|
+
true
|
|
44
|
+
end
|
|
45
|
+
end
|
|
37
46
|
end
|
|
38
47
|
|
|
39
48
|
def allowed_hosts
|
|
@@ -63,5 +72,11 @@ module ForemanRhCloud
|
|
|
63
72
|
def location_name_for_tag
|
|
64
73
|
@loc ? @loc.name : '*'
|
|
65
74
|
end
|
|
75
|
+
|
|
76
|
+
# Single identity string reused as BOTH the advisory-lock name and the
|
|
77
|
+
# Rails.cache key, so the lock and the cached entry always correspond 1:1.
|
|
78
|
+
def sync_identity
|
|
79
|
+
"rh_cloud_tags_auth_sync_#{tag_value}"
|
|
80
|
+
end
|
|
66
81
|
end
|
|
67
82
|
end
|
data/package.json
CHANGED
|
@@ -3,6 +3,7 @@ require 'json'
|
|
|
3
3
|
|
|
4
4
|
class TagsAuthTest < ActiveSupport::TestCase
|
|
5
5
|
setup do
|
|
6
|
+
Rails.cache.clear
|
|
6
7
|
@user = FactoryBot.build(:user)
|
|
7
8
|
@logger = Logger.new(IO::NULL)
|
|
8
9
|
@org = FactoryBot.build(:organization)
|
|
@@ -41,6 +42,31 @@ class TagsAuthTest < ActiveSupport::TestCase
|
|
|
41
42
|
@auth.update_tag
|
|
42
43
|
end
|
|
43
44
|
|
|
45
|
+
test 'Does not repeat cloud request for the same user/org/location within the sync TTL' do
|
|
46
|
+
@auth.stubs(:allowed_hosts).returns(['test_uuid1'])
|
|
47
|
+
@auth.expects(:execute_cloud_request).once
|
|
48
|
+
|
|
49
|
+
@auth.update_tag
|
|
50
|
+
@auth.update_tag
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
test 'Serializes sync through an advisory lock on a cold cache miss' do
|
|
54
|
+
@auth.stubs(:allowed_hosts).returns(['test_uuid1'])
|
|
55
|
+
@auth.stubs(:execute_cloud_request)
|
|
56
|
+
Foreman::AdvisoryLockManager.expects(:with_session_lock).yields
|
|
57
|
+
|
|
58
|
+
@auth.update_tag
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
test 'Skips the advisory lock entirely on a warm cache hit' do
|
|
62
|
+
@auth.stubs(:allowed_hosts).returns(['test_uuid1'])
|
|
63
|
+
@auth.stubs(:execute_cloud_request)
|
|
64
|
+
@auth.update_tag
|
|
65
|
+
|
|
66
|
+
Foreman::AdvisoryLockManager.expects(:with_session_lock).never
|
|
67
|
+
@auth.update_tag
|
|
68
|
+
end
|
|
69
|
+
|
|
44
70
|
test 'Generates tags with wildcard location when location is nil' do
|
|
45
71
|
auth_with_nil_loc = ::ForemanRhCloud::TagsAuth.new(@user, @org, nil, @logger)
|
|
46
72
|
uuid1 = 'test_uuid1'
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: foreman_rh_cloud
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 13.2.
|
|
4
|
+
version: 13.2.12
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Foreman Red Hat Cloud team
|
|
@@ -639,7 +639,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
639
639
|
- !ruby/object:Gem::Version
|
|
640
640
|
version: '0'
|
|
641
641
|
requirements: []
|
|
642
|
-
rubygems_version: 4.0.
|
|
642
|
+
rubygems_version: 4.0.20
|
|
643
643
|
specification_version: 4
|
|
644
644
|
summary: Summary of ForemanRhCloud.
|
|
645
645
|
test_files:
|