singleton-client-test 0.7.0.24 → 0.7.0.28
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: d56e992042fd4e5633b41c3de989fd805a44978c696dd7b9692da4191e22b4d4
|
4
|
+
data.tar.gz: 99bcb2f0d4e6e502f88c90a5ae27a12349e2af35ff8a2356d781e97e57b8af74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f84668bb050779955dbafbb37dd5e2e41a4d793c18552f3c1a51725e906db03e7a13f098329d36596f71adebedf90159d5cc0a85344f8f0bd3c1bd46ca555c9
|
7
|
+
data.tar.gz: 4e5f2b2a430b96ca92bd67c9381bfd043f8808a800da6950e5f2e855f860560e96e43ea6f80ef0f9651138026cda0cf7f6ae1f1b84a77b4ea1d0d5de05c0215d
|
@@ -7,7 +7,7 @@ module SgtnClient
|
|
7
7
|
|
8
8
|
def self.getSource(component, key, locale)
|
9
9
|
cache_key = SgtnClient::CacheUtil.get_cachekey(component, locale)
|
10
|
-
items = SgtnClient::CacheUtil.get_cache(cache_key)
|
10
|
+
expired, items = SgtnClient::CacheUtil.get_cache(cache_key)
|
11
11
|
if items.nil?
|
12
12
|
items = getBundle(component, locale)
|
13
13
|
SgtnClient.logger.debug "Putting sources items into cache with key: " + cache_key
|
@@ -15,7 +15,7 @@ module SgtnClient
|
|
15
15
|
else
|
16
16
|
SgtnClient.logger.debug "Getting sources from cache with key: " + cache_key
|
17
17
|
end
|
18
|
-
s = items[locale][key]
|
18
|
+
s = items.nil?? nil : items[locale][key]
|
19
19
|
if items.nil? || s.nil?
|
20
20
|
SgtnClient.logger.debug "Source not found, return key: " + key
|
21
21
|
#return key
|
@@ -27,8 +27,8 @@ module SgtnClient
|
|
27
27
|
|
28
28
|
def self.getSources(component, locale)
|
29
29
|
cache_key = SgtnClient::CacheUtil.get_cachekey(component, locale)
|
30
|
-
items = SgtnClient::CacheUtil.get_cache(cache_key)
|
31
|
-
if items.nil?
|
30
|
+
expired, items = SgtnClient::CacheUtil.get_cache(cache_key)
|
31
|
+
if items.nil? || expired
|
32
32
|
items = getBundle(component, locale)
|
33
33
|
SgtnClient.logger.debug "Putting sources items into cache with key: " + cache_key
|
34
34
|
SgtnClient::CacheUtil.write_cache(cache_key, items)
|
@@ -15,6 +15,9 @@ module SgtnClient
|
|
15
15
|
str = getTranslation(component, key, locale)
|
16
16
|
if str.nil?
|
17
17
|
str = SgtnClient::Source.getSource(component, key, SgtnClient::Config.configurations.default)
|
18
|
+
if str.nil?
|
19
|
+
SgtnClient.logger.error "Can't find the key " + key + " in source path!"
|
20
|
+
end
|
18
21
|
end
|
19
22
|
str
|
20
23
|
end
|
@@ -23,6 +26,10 @@ module SgtnClient
|
|
23
26
|
str = getTranslation(component, key, locale)
|
24
27
|
if str.nil?
|
25
28
|
str = SgtnClient::Source.getSource(component, key, SgtnClient::Config.configurations.default)
|
29
|
+
if str.nil?
|
30
|
+
SgtnClient.logger.error "Can't find the key " + key + " in source path!"
|
31
|
+
return nil
|
32
|
+
end
|
26
33
|
str.to_plural_s(:en, plural_args)
|
27
34
|
else
|
28
35
|
str.to_plural_s(locale, plural_args)
|
@@ -31,6 +38,9 @@ module SgtnClient
|
|
31
38
|
|
32
39
|
def self.getString_f(component, key, args, locale, *optionals)
|
33
40
|
s = getString(component, key, locale, *optionals)
|
41
|
+
if s.nil?
|
42
|
+
return nil
|
43
|
+
end
|
34
44
|
if args.is_a?(Hash)
|
35
45
|
args.each do |source, arg|
|
36
46
|
s.gsub! "{#{source}}", arg
|
@@ -42,24 +52,19 @@ module SgtnClient
|
|
42
52
|
end
|
43
53
|
|
44
54
|
def self.getStrings(component, locale)
|
45
|
-
|
46
|
-
cache_key = SgtnClient::CacheUtil.get_cachekey(component, flocale)
|
47
|
-
items = SgtnClient::CacheUtil.get_cache(cache_key)
|
48
|
-
if items.nil?
|
49
|
-
items = getTranslations(component, flocale)
|
50
|
-
SgtnClient::CacheUtil.write_cache(cache_key, items)
|
51
|
-
else
|
52
|
-
SgtnClient.logger.debug "Getting translations from cache with key: " + cache_key
|
53
|
-
end
|
54
|
-
|
55
|
+
items = get_cs(component, locale)
|
55
56
|
default = SgtnClient::Config.configurations.default
|
56
57
|
if items.nil? || items["messages"] == nil
|
57
58
|
items = {}
|
58
59
|
s = SgtnClient::Source.getSources(component, default)
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
60
|
+
if s.nil?
|
61
|
+
SgtnClient.logger.error "Can't find the component " + component + " in source path!"
|
62
|
+
else
|
63
|
+
default_component, value = s.first
|
64
|
+
items["component"] = component
|
65
|
+
items["messages"] = value
|
66
|
+
items["locale"] = 'source'
|
67
|
+
end
|
63
68
|
end
|
64
69
|
return items
|
65
70
|
end
|
@@ -68,33 +73,44 @@ module SgtnClient
|
|
68
73
|
private
|
69
74
|
|
70
75
|
def self.getTranslation(component, key, locale)
|
71
|
-
|
72
|
-
cache_key = SgtnClient::CacheUtil.get_cachekey(component, flocale)
|
73
|
-
items = SgtnClient::CacheUtil.get_cache(cache_key)
|
74
|
-
if items.nil?
|
75
|
-
items = getTranslations(component, flocale)
|
76
|
-
SgtnClient::CacheUtil.write_cache(cache_key, items)
|
77
|
-
else
|
78
|
-
SgtnClient.logger.debug "Getting translations from cache with key: " + cache_key
|
79
|
-
end
|
76
|
+
items = get_cs(component, locale)
|
80
77
|
if items.nil? || items["messages"] == nil
|
81
78
|
nil
|
82
79
|
else
|
83
80
|
items["messages"][key]
|
84
81
|
end
|
85
82
|
end
|
86
|
-
|
87
|
-
def self.
|
83
|
+
|
84
|
+
def self.get_cs(component, locale)
|
85
|
+
flocale = SgtnClient::LocaleUtil.fallback(locale)
|
86
|
+
cache_key = SgtnClient::CacheUtil.get_cachekey(component, flocale)
|
87
|
+
expired, items = SgtnClient::CacheUtil.get_cache(cache_key)
|
88
|
+
if items.nil? || expired
|
89
|
+
items = load(component, flocale)
|
90
|
+
if items.nil?
|
91
|
+
items = SgtnClient::Source.getSources(component, SgtnClient::Config.configurations.default)
|
92
|
+
SgtnClient::Core::Cache.put(cache_key, items, 60)
|
93
|
+
else
|
94
|
+
SgtnClient::CacheUtil.write_cache(cache_key, items)
|
95
|
+
end
|
96
|
+
else
|
97
|
+
SgtnClient.logger.debug "Getting translations from cache with key: " + cache_key
|
98
|
+
end
|
99
|
+
|
100
|
+
return items
|
101
|
+
end
|
102
|
+
|
103
|
+
def self.load(component, locale)
|
88
104
|
env = SgtnClient::Config.default_environment
|
89
105
|
mode = SgtnClient::Config.configurations[env]["bundle_mode"]
|
90
106
|
if mode == 'offline'
|
91
|
-
return
|
107
|
+
return load_o(component, locale)
|
92
108
|
else
|
93
|
-
return
|
109
|
+
return load_s(component, locale)
|
94
110
|
end
|
95
111
|
end
|
96
112
|
|
97
|
-
def self.
|
113
|
+
def self.load_o(component, locale)
|
98
114
|
env = SgtnClient::Config.default_environment
|
99
115
|
product_name = SgtnClient::Config.configurations[env]["product_name"]
|
100
116
|
version = SgtnClient::Config.configurations[env]["version"].to_s
|
@@ -104,7 +120,7 @@ module SgtnClient
|
|
104
120
|
SgtnClient::FileUtil.read_json(bundlepath)
|
105
121
|
end
|
106
122
|
|
107
|
-
def self.
|
123
|
+
def self.load_s(component, locale)
|
108
124
|
env = SgtnClient::Config.default_environment
|
109
125
|
product_name = SgtnClient::Config.configurations[env]["product_name"]
|
110
126
|
vip_server = SgtnClient::Config.configurations[env]["vip_server"]
|
@@ -5,86 +5,95 @@ module SgtnClient::Core
|
|
5
5
|
Entry = Struct.new(:expiry, :value)
|
6
6
|
|
7
7
|
def self.initialize(disabled=false, opts={})
|
8
|
-
|
8
|
+
@@opts = opts
|
9
9
|
@mutex = Mutex.new
|
10
10
|
SgtnClient.logger.debug "Initialize cache......"
|
11
11
|
if disabled == false
|
12
|
-
|
12
|
+
@@data = Hash.new
|
13
13
|
SgtnClient.logger.debug "Cache is enabled!"
|
14
14
|
else
|
15
|
+
@@data = nil
|
15
16
|
SgtnClient.logger.debug "Cache is disabled!"
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
19
20
|
def self.keys
|
20
|
-
if
|
21
|
+
if @@data == nil
|
21
22
|
return nil
|
22
23
|
end
|
23
24
|
SgtnClient.logger.debug "Get cache keys"
|
24
|
-
|
25
|
+
@@data.keys
|
25
26
|
end
|
26
27
|
|
27
28
|
def self.get(key)
|
28
|
-
if
|
29
|
-
return nil
|
29
|
+
if @@data == nil
|
30
|
+
return nil, nil
|
30
31
|
end
|
31
32
|
SgtnClient.logger.debug "Get cache for key: " + key
|
32
|
-
invalidate
|
33
|
-
$data[key][:value] if has(key)
|
33
|
+
invalidate(key)
|
34
34
|
end
|
35
35
|
|
36
36
|
def self.has(key)
|
37
|
-
if
|
37
|
+
if @@data == nil
|
38
38
|
return nil
|
39
39
|
end
|
40
40
|
SgtnClient.logger.debug "Has cache for key: " + key
|
41
|
-
|
41
|
+
@@data.has_key? key
|
42
42
|
end
|
43
43
|
|
44
44
|
def self.put(key, value, ttl=nil)
|
45
45
|
@mutex.synchronize do
|
46
|
-
if
|
46
|
+
if @@data == nil
|
47
47
|
return nil
|
48
48
|
end
|
49
|
-
ttl ||=
|
49
|
+
ttl ||= @@opts[:ttl]
|
50
50
|
# hours from new
|
51
51
|
SgtnClient.logger.debug "Put cache for key '" + key + "' with expired time at'" + (Time.now + ttl*60).to_s
|
52
|
-
|
52
|
+
@@data[key] = Entry.new(Time.now + ttl*60, value)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
56
|
def self.delete(key)
|
57
57
|
@mutex.synchronize do
|
58
|
-
if
|
58
|
+
if @@data == nil
|
59
59
|
return nil
|
60
60
|
end
|
61
61
|
SgtnClient.logger.debug "Delete cache for key: " + key
|
62
|
-
|
62
|
+
@@data.delete key
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
66
|
def self.clear
|
67
67
|
@mutex.synchronize do
|
68
|
-
if
|
68
|
+
if @@data == nil
|
69
69
|
return nil
|
70
70
|
end
|
71
71
|
SgtnClient.logger.debug "Clear cache!"
|
72
|
-
|
72
|
+
@@data = Hash.new
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
-
def self.invalidate
|
76
|
+
def self.invalidate(key)
|
77
77
|
@mutex.synchronize do
|
78
|
-
if
|
79
|
-
return nil
|
78
|
+
if @@data == nil
|
79
|
+
return nil, nil
|
80
80
|
end
|
81
81
|
SgtnClient.logger.debug "Invalidating expired cache......"
|
82
82
|
now = Time.now
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
}
|
87
|
-
|
83
|
+
if has(key)
|
84
|
+
v = @@data[key]
|
85
|
+
expired = false
|
86
|
+
SgtnClient.logger.debug "Checking cache: key=#{key}, expiredtime=#{v[:expiry]}, now=#{now}, expired=#{(v[:expiry] < now)}"
|
87
|
+
if v[:expiry] < now
|
88
|
+
SgtnClient.logger.debug "Before deleting the cache: data=#{@@data}"
|
89
|
+
@@data.delete(key)
|
90
|
+
SgtnClient.logger.debug "After deleting the cache: data=#{@@data}"
|
91
|
+
expired = true
|
92
|
+
end
|
93
|
+
return expired, v[:value]
|
94
|
+
else
|
95
|
+
return nil, nil
|
96
|
+
end
|
88
97
|
end
|
89
98
|
end
|
90
99
|
end
|
@@ -40,7 +40,7 @@ module SgtnClient
|
|
40
40
|
:rest_endpoint, :rest_token_endpoint, :client_id, :client_secret,
|
41
41
|
:openid_endpoint, :openid_redirect_uri, :openid_client_id, :openid_client_secret,
|
42
42
|
:verbose_logging, :product_name, :version, :vip_server, :bundle_mode,
|
43
|
-
:translation_bundle, :source_bundle, :cache_expiry_period, :disable_cache
|
43
|
+
:translation_bundle, :source_bundle, :cache_expiry_period, :disable_cache, :default_language
|
44
44
|
|
45
45
|
|
46
46
|
# Create Config object
|
@@ -4,7 +4,11 @@ require 'multi_json'
|
|
4
4
|
module SgtnClient::Core
|
5
5
|
class Request
|
6
6
|
def self.get(url)
|
7
|
-
res = RestClient.get(url)
|
7
|
+
#res = RestClient.get(url)
|
8
|
+
res = RestClient::Resource.new(
|
9
|
+
url,
|
10
|
+
:verify_ssl => false
|
11
|
+
).get
|
8
12
|
begin
|
9
13
|
obj = MultiJson.load(res)
|
10
14
|
rescue MultiJson::ParseError => exception
|
@@ -10,8 +10,8 @@ module SgtnClient
|
|
10
10
|
class CacheUtil
|
11
11
|
|
12
12
|
def self.get_cache(cache_key)
|
13
|
-
items = SgtnClient::Core::Cache.get(cache_key)
|
14
|
-
return items
|
13
|
+
expired, items = SgtnClient::Core::Cache.get(cache_key)
|
14
|
+
return expired, items
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.clear_cache()
|
@@ -32,7 +32,12 @@ module SgtnClient
|
|
32
32
|
env = SgtnClient::Config.default_environment
|
33
33
|
product_name = SgtnClient::Config.configurations[env]["product_name"]
|
34
34
|
version = SgtnClient::Config.configurations[env]["version"].to_s
|
35
|
-
|
35
|
+
default_l = SgtnClient::Config.configurations[env]["default_language"]
|
36
|
+
if default_l == nil
|
37
|
+
default_l = 'en'
|
38
|
+
end
|
39
|
+
lc = locale == default_l ? SgtnClient::Config.configurations.default: locale
|
40
|
+
return product_name + "_" + version + "_" + component + "_" + lc
|
36
41
|
end
|
37
42
|
end
|
38
43
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: singleton-client-test
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.0.
|
4
|
+
version: 0.7.0.28
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- VMware G11n Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-01-
|
11
|
+
date: 2022-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|