singleton-client-test 0.7.0.26 → 0.7.0.30

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a0d174f65d5ce5b87ead4f4c61bc57070bc051ab51bc65343c7ca50a0fd0b68
4
- data.tar.gz: eaf356bee612ecf0f512083e029964de5307acd3dc05555c710ce386384346ea
3
+ metadata.gz: 8bbeb4b91e49f392f67d86832ba947550035c57e5d95ed8a9ba3f7018bea1933
4
+ data.tar.gz: 2f42e96d26b18919eca9dde3673b9b9ae20af3f627bf06fd21ebac63ce496e55
5
5
  SHA512:
6
- metadata.gz: 512573410bae6caa91cf0b893f27e95a0864a0374e75bd601a55a2f471ca75ed69c6f537aeb24ca7b9202a6bc59c231a838c3d5a167fdc56f130c8ab844a32e5
7
- data.tar.gz: 6a2f2f82f806b564ede5218c7cda2123e528515f5089bb4ea3658451598174d140006e9d075ed68e4b1ae3c04b78b4dc3892a00bc26e447387edb282a8f35c9b
6
+ metadata.gz: 19ea390e3e040215ea4dd38d38ae4e36452c217a2e82e22bf638ac08798dda63797be2b346fd3bde89a9c6e5ff5aa415c02a21b0094518a3b698ebb3864ff383
7
+ data.tar.gz: dfc215e21a95bf65a7b25799e13f80fc026fdc13e5b0566ab478a4977c5f73041c6754fc88ba8bef48ee2c0e26ee3721c887032614bd350ba125397f489fe35f
@@ -6,18 +6,18 @@ module SgtnClient
6
6
  class Source
7
7
 
8
8
  def self.getSource(component, key, locale)
9
+ SgtnClient.logger.debug "[Source][getSource]component=#{component}, key=#{key}, locale=#{locale}"
9
10
  cache_key = SgtnClient::CacheUtil.get_cachekey(component, locale)
10
- items = SgtnClient::CacheUtil.get_cache(cache_key)
11
+ expired, items = SgtnClient::CacheUtil.get_cache(cache_key)
11
12
  if items.nil?
12
- items = getBundle(component, locale)
13
- SgtnClient.logger.debug "Putting sources items into cache with key: " + cache_key
13
+ items = getBundle(component, locale)
14
14
  SgtnClient::CacheUtil.write_cache(cache_key, items)
15
15
  else
16
- SgtnClient.logger.debug "Getting sources from cache with key: " + cache_key
16
+ SgtnClient.logger.debug "[Source][getSource]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
- SgtnClient.logger.debug "Source not found, return key: " + key
20
+ SgtnClient.logger.debug "[Source][getSource]source not found, return key: " + key
21
21
  #return key
22
22
  return nil
23
23
  else
@@ -26,23 +26,23 @@ module SgtnClient
26
26
  end
27
27
 
28
28
  def self.getSources(component, locale)
29
+ SgtnClient.logger.debug "[Source][getSources]component=#{component}, locale=#{locale}"
29
30
  cache_key = SgtnClient::CacheUtil.get_cachekey(component, locale)
30
- items = SgtnClient::CacheUtil.get_cache(cache_key)
31
- if items.nil?
31
+ expired, items = SgtnClient::CacheUtil.get_cache(cache_key)
32
+ if items.nil? || expired
32
33
  items = getBundle(component, locale)
33
- SgtnClient.logger.debug "Putting sources items into cache with key: " + cache_key
34
34
  SgtnClient::CacheUtil.write_cache(cache_key, items)
35
35
  else
36
- SgtnClient.logger.debug "Getting sources from cache with key: " + cache_key
36
+ SgtnClient.logger.debug "[Source][getSources]getting sources from cache with key: " + cache_key
37
37
  end
38
38
  return items
39
39
  end
40
40
 
41
41
  def self.loadBundles(locale)
42
+ SgtnClient.logger.debug "[Source][loadBundles]locale=#{locale}"
42
43
  env = SgtnClient::Config.default_environment
43
44
  SgtnClient::Config.configurations.default = locale
44
45
  source_bundle = SgtnClient::Config.configurations[env]["source_bundle"]
45
- SgtnClient.logger.debug "Loading [" + locale + "] source bundles from path: " + source_bundle
46
46
  Dir.foreach(source_bundle) do |component|
47
47
  next if component == '.' || component == '..'
48
48
  yamlfile = File.join(source_bundle, component + "/" + locale + ".yml")
@@ -54,10 +54,10 @@ module SgtnClient
54
54
 
55
55
  private
56
56
  def self.getBundle(component, locale)
57
+ SgtnClient.logger.debug "[Source][getBundle]component=#{component}, locale=#{locale}"
57
58
  env = SgtnClient::Config.default_environment
58
59
  source_bundle = SgtnClient::Config.configurations[env]["source_bundle"]
59
60
  bundlepath = source_bundle + "/" + component + "/" + locale + ".yml"
60
- SgtnClient.logger.debug "Getting source from bundle: " + bundlepath
61
61
  begin
62
62
  bundle = SgtnClient::FileUtil.read_yml(bundlepath)
63
63
  rescue => exception
@@ -12,17 +12,26 @@ module SgtnClient
12
12
  class Translation
13
13
 
14
14
  def self.getString(component, key, locale)
15
+ SgtnClient.logger.debug "[Translation.getString]component: #{component}, key: #{key}, locale: #{locale}"
15
16
  str = getTranslation(component, key, locale)
16
17
  if str.nil?
17
18
  str = SgtnClient::Source.getSource(component, key, SgtnClient::Config.configurations.default)
19
+ if str.nil?
20
+ SgtnClient.logger.debug "[Translation][getString] Missing source string with key: #{key}, component: #{component}, locale: #{locale}"
21
+ end
18
22
  end
19
23
  str
20
24
  end
21
25
 
22
26
  def self.getString_p(component, key, plural_args, locale)
27
+ SgtnClient.logger.debug "[Translation][getString_p]component=#{component}, key=#{key}, locale=#{locale}"
23
28
  str = getTranslation(component, key, locale)
24
29
  if str.nil?
25
30
  str = SgtnClient::Source.getSource(component, key, SgtnClient::Config.configurations.default)
31
+ if str.nil?
32
+ SgtnClient.logger.debug "[Translation][getString_p] Missing source string with key: #{key}, component: #{component}, locale: #{locale}"
33
+ return nil
34
+ end
26
35
  str.to_plural_s(:en, plural_args)
27
36
  else
28
37
  str.to_plural_s(locale, plural_args)
@@ -30,7 +39,11 @@ module SgtnClient
30
39
  end
31
40
 
32
41
  def self.getString_f(component, key, args, locale, *optionals)
42
+ SgtnClient.logger.debug "[Translation][getString_f]component=#{component}, key=#{key}, locale=#{locale}"
33
43
  s = getString(component, key, locale, *optionals)
44
+ if s.nil?
45
+ return nil
46
+ end
34
47
  if args.is_a?(Hash)
35
48
  args.each do |source, arg|
36
49
  s.gsub! "{#{source}}", arg
@@ -42,24 +55,20 @@ module SgtnClient
42
55
  end
43
56
 
44
57
  def self.getStrings(component, locale)
45
- flocale = SgtnClient::LocaleUtil.fallback(locale)
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
-
58
+ SgtnClient.logger.debug "[Translation][getStrings]component=#{component}, locale=#{locale}"
59
+ items = get_cs(component, locale)
55
60
  default = SgtnClient::Config.configurations.default
56
61
  if items.nil? || items["messages"] == nil
57
62
  items = {}
58
63
  s = SgtnClient::Source.getSources(component, default)
59
- default_component, value = s.first
60
- items["component"] = component
61
- items["messages"] = value
62
- items["locale"] = 'source'
64
+ if s.nil?
65
+ SgtnClient.logger.error "[Translation][getStrings] Missing component: #{component}, locale: #{locale}"
66
+ else
67
+ default_component, value = s.first
68
+ items["component"] = component
69
+ items["messages"] = value
70
+ items["locale"] = 'source'
71
+ end
63
72
  end
64
73
  return items
65
74
  end
@@ -68,11 +77,21 @@ module SgtnClient
68
77
  private
69
78
 
70
79
  def self.getTranslation(component, key, locale)
80
+ items = get_cs(component, locale)
81
+ if items.nil? || items["messages"] == nil
82
+ nil
83
+ else
84
+ items["messages"][key]
85
+ end
86
+ end
87
+
88
+ def self.get_cs(component, locale)
71
89
  flocale = SgtnClient::LocaleUtil.fallback(locale)
72
90
  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)
91
+ SgtnClient.logger.debug "[Translation][get_cs]cache_key=#{cache_key}"
92
+ expired, items = SgtnClient::CacheUtil.get_cache(cache_key)
93
+ if items.nil? || expired
94
+ items = load(component, flocale)
76
95
  if items.nil?
77
96
  items = SgtnClient::Source.getSources(component, SgtnClient::Config.configurations.default)
78
97
  SgtnClient::Core::Cache.put(cache_key, items, 60)
@@ -80,43 +99,38 @@ module SgtnClient
80
99
  SgtnClient::CacheUtil.write_cache(cache_key, items)
81
100
  end
82
101
  else
83
- SgtnClient.logger.debug "Getting translations from cache with key: " + cache_key
102
+ SgtnClient.logger.debug "[Translation]get translations from cache with key: " + cache_key
84
103
  end
85
- if items.nil? || items["messages"] == nil
86
- nil
87
- else
88
- items["messages"][key]
89
- end
90
- end
91
-
92
- def self.getTranslations(component, locale)
104
+
105
+ return items
106
+ end
107
+
108
+ def self.load(component, locale)
93
109
  env = SgtnClient::Config.default_environment
94
110
  mode = SgtnClient::Config.configurations[env]["bundle_mode"]
111
+ SgtnClient.logger.debug "[Translation][load]mode=#{mode}"
95
112
  if mode == 'offline'
96
- return get_offbundle(component, locale)
113
+ return load_o(component, locale)
97
114
  else
98
- return get_server(component, locale)
115
+ return load_s(component, locale)
99
116
  end
100
117
  end
101
118
 
102
- def self.get_offbundle(component, locale)
119
+ def self.load_o(component, locale)
103
120
  env = SgtnClient::Config.default_environment
104
121
  product_name = SgtnClient::Config.configurations[env]["product_name"]
105
122
  version = SgtnClient::Config.configurations[env]["version"].to_s
106
123
  translation_bundle = SgtnClient::Config.configurations[env]["translation_bundle"]
107
124
  bundlepath = translation_bundle + "/" + product_name + "/" + version + "/" + component + "/messages_" + locale + ".json"
108
- SgtnClient.logger.debug "Getting translations from offline bundle: " + bundlepath
109
125
  SgtnClient::FileUtil.read_json(bundlepath)
110
126
  end
111
127
 
112
- def self.get_server(component, locale)
128
+ def self.load_s(component, locale)
113
129
  env = SgtnClient::Config.default_environment
114
130
  product_name = SgtnClient::Config.configurations[env]["product_name"]
115
131
  vip_server = SgtnClient::Config.configurations[env]["vip_server"]
116
- SgtnClient.logger.debug "Getting translations from server: " + vip_server
117
132
  version = SgtnClient::Config.configurations[env]["version"].to_s
118
133
  url = vip_server + "/i18n/api/v2/translation/products/" + product_name + "/versions/" + version + "/locales/" + locale + "/components/" + component+ "?checkTranslationStatus=false&machineTranslation=false&pseudo=false"
119
- SgtnClient.logger.debug url
120
134
  begin
121
135
  obj = SgtnClient::Core::Request.get(url)
122
136
  rescue => exception
@@ -7,12 +7,12 @@ module SgtnClient::Core
7
7
  def self.initialize(disabled=false, opts={})
8
8
  @@opts = opts
9
9
  @mutex = Mutex.new
10
- SgtnClient.logger.debug "Initialize cache......"
11
10
  if disabled == false
12
11
  @@data = Hash.new
13
- SgtnClient.logger.debug "Cache is enabled!"
12
+ SgtnClient.logger.debug "[Cache][initialize]cache is enabled!"
14
13
  else
15
- SgtnClient.logger.debug "Cache is disabled!"
14
+ @@data = nil
15
+ SgtnClient.logger.debug "[Cache][initialize]cache is disabled!"
16
16
  end
17
17
  end
18
18
 
@@ -20,35 +20,34 @@ module SgtnClient::Core
20
20
  if @@data == nil
21
21
  return nil
22
22
  end
23
- SgtnClient.logger.debug "Get cache keys"
23
+ SgtnClient.logger.debug "[Cache][keys]get cache keys"
24
24
  @@data.keys
25
25
  end
26
26
 
27
27
  def self.get(key)
28
28
  if @@data == nil
29
- return nil
29
+ return nil, nil
30
30
  end
31
- SgtnClient.logger.debug "Get cache for key: " + key
32
- invalidate
33
- @@data[key][:value] if has(key)
31
+ SgtnClient.logger.debug "[Cache][get]get cache for key: " + key
32
+ invalidate(key)
34
33
  end
35
34
 
36
35
  def self.has(key)
37
36
  if @@data == nil
38
37
  return nil
39
38
  end
40
- SgtnClient.logger.debug "Has cache for key: " + key
39
+ SgtnClient.logger.debug "[Cache][has]check if the cache has key: #{(@@data.has_key? key)}"
41
40
  @@data.has_key? key
42
41
  end
43
42
 
44
43
  def self.put(key, value, ttl=nil)
45
44
  @mutex.synchronize do
46
- if @@data == nil
45
+ if @@data == nil || value == nil
47
46
  return nil
48
47
  end
49
48
  ttl ||= @@opts[:ttl]
50
49
  # hours from new
51
- SgtnClient.logger.debug "Put cache for key '" + key + "' with expired time at'" + (Time.now + ttl*60).to_s
50
+ SgtnClient.logger.debug "[Cache][put]put cache for key '" + key + "' with expired time at'" + (Time.now + ttl*60).to_s
52
51
  @@data[key] = Entry.new(Time.now + ttl*60, value)
53
52
  end
54
53
  end
@@ -58,7 +57,7 @@ module SgtnClient::Core
58
57
  if @@data == nil
59
58
  return nil
60
59
  end
61
- SgtnClient.logger.debug "Delete cache for key: " + key
60
+ SgtnClient.logger.debug "[Cache][delete]delete cache for key: " + key
62
61
  @@data.delete key
63
62
  end
64
63
  end
@@ -68,23 +67,32 @@ module SgtnClient::Core
68
67
  if @@data == nil
69
68
  return nil
70
69
  end
71
- SgtnClient.logger.debug "Clear cache!"
70
+ SgtnClient.logger.debug "[Cache][clear]clear cache!"
72
71
  @@data = Hash.new
73
72
  end
74
73
  end
75
74
 
76
- def self.invalidate
75
+ def self.invalidate(key)
77
76
  @mutex.synchronize do
78
77
  if @@data == nil
79
- return nil
78
+ return nil, nil
80
79
  end
81
- SgtnClient.logger.debug "Invalidating expired cache......"
80
+ SgtnClient.logger.debug "[Cache][invalidate]invalidate expired cache......"
82
81
  now = Time.now
83
- @@data.each {
84
- |k, v|
85
- SgtnClient.logger.debug "Checking cache: key=#{k}, expiredtime=#{v[:expiry]}, now=#{now}, expired=#{(v[:expiry] < now)}"
86
- }
87
- @@data.delete_if {|k, v| v[:expiry] < now}
82
+ if has(key)
83
+ v = @@data[key]
84
+ expired = false
85
+ SgtnClient.logger.debug "[Cache][invalidate]check cache: key=#{key}, expiredtime=#{v[:expiry]}, now=#{now}, expired=#{(v[:expiry] < now)}"
86
+ if v[:expiry] < now
87
+ SgtnClient.logger.debug "[Cache][invalidate]before deleting the cache: data=#{@@data}"
88
+ @@data.delete(key)
89
+ SgtnClient.logger.debug "[Cache][invalidate]after deleting the cache: data=#{@@data}"
90
+ expired = true
91
+ end
92
+ return expired, v[:value]
93
+ else
94
+ return nil, nil
95
+ end
88
96
  end
89
97
  end
90
98
  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,7 @@ require 'multi_json'
4
4
  module SgtnClient::Core
5
5
  class Request
6
6
  def self.get(url)
7
- #res = RestClient.get(url)
7
+ SgtnClient.logger.debug "[Request][get]url=#{url}"
8
8
  res = RestClient::Resource.new(
9
9
  url,
10
10
  :verify_ssl => false
@@ -38,6 +38,7 @@ module SgtnClient
38
38
 
39
39
  # create log file
40
40
  file = './sgtnclient_d.log'
41
+ SgtnClient.logger.debug "[Client][load]create log file=#{file}"
41
42
  if args[2] != nil
42
43
  file = args[2]
43
44
  end
@@ -48,7 +49,7 @@ module SgtnClient
48
49
  # Set log level for sandbox mode
49
50
  env = SgtnClient::Config.default_environment
50
51
  mode = SgtnClient::Config.configurations[env]["mode"]
51
- SgtnClient.logger.info "Current mode is: " + mode
52
+ SgtnClient.logger.debug "[Client][load]set log level, mode=#{mode}"
52
53
  if mode == 'sandbox'
53
54
  SgtnClient.logger.level = Logger::DEBUG
54
55
  else
@@ -57,6 +58,7 @@ module SgtnClient
57
58
 
58
59
  # initialize cache
59
60
  disable_cache = SgtnClient::Config.configurations[env]["disable_cache"]
61
+ SgtnClient.logger.debug "[Client][load]cache initialize, disable_cache=#{disable_cache}"
60
62
  if disable_cache != nil
61
63
  SgtnClient::Core::Cache.initialize(disable_cache)
62
64
  else
@@ -10,21 +10,27 @@ 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
+ SgtnClient.logger.debug "[CacheUtil]get cache with key #{cache_key}, expired #{expired}"
15
+ return expired, items
15
16
  end
16
17
 
17
18
  def self.clear_cache()
18
19
  SgtnClient::Core::Cache.clear()
20
+ SgtnClient.logger.debug "[CacheUtil]clear cache"
19
21
  end
20
22
 
21
23
  def self.write_cache(cache_key, items)
24
+ if items.nil?
25
+ return nil
26
+ end
22
27
  env = SgtnClient::Config.default_environment
23
28
  cache_expiry_period = SgtnClient::Config.configurations[env]["cache_expiry_period"]
24
29
  # expired after 24 hours
25
30
  if cache_expiry_period == nil
26
31
  cache_expiry_period = 24*60
27
32
  end
33
+ SgtnClient.logger.debug "[CacheUtil]write cache with key #{cache_key}, cache_expiry_period #{cache_expiry_period}, itmes #{items}"
28
34
  SgtnClient::Core::Cache.put(cache_key, items, cache_expiry_period)
29
35
  end
30
36
 
@@ -32,7 +38,13 @@ module SgtnClient
32
38
  env = SgtnClient::Config.default_environment
33
39
  product_name = SgtnClient::Config.configurations[env]["product_name"]
34
40
  version = SgtnClient::Config.configurations[env]["version"].to_s
35
- return product_name + "_" + version + "_" + component + "_" + locale
41
+ default_l = SgtnClient::Config.configurations[env]["default_language"]
42
+ if default_l == nil
43
+ default_l = 'en'
44
+ end
45
+ lc = locale == default_l ? SgtnClient::Config.configurations.default: locale
46
+ SgtnClient.logger.debug "[CacheUtil]get cache key: #{lc}"
47
+ return product_name + "_" + version + "_" + component + "_" + lc
36
48
  end
37
49
  end
38
50
 
@@ -8,6 +8,7 @@ module SgtnClient
8
8
  @mutex = Mutex.new
9
9
 
10
10
  def self.read_json(bundlepath)
11
+ SgtnClient.logger.debug "[FileUtil]read json file from: " + bundlepath
11
12
  @mutex.synchronize do
12
13
  data_hash = nil
13
14
  begin
@@ -21,6 +22,7 @@ module SgtnClient
21
22
  end
22
23
 
23
24
  def self.read_yml(file_name)
25
+ SgtnClient.logger.debug "[FileUtil]read yml file from: " + file_name
24
26
  @mutex.synchronize do
25
27
  erb = ERB.new(File.read(file_name))
26
28
  erb.filename = file_name
@@ -4,8 +4,8 @@ module SgtnClient
4
4
  class ValidateUtil
5
5
 
6
6
  def self.validate_config()
7
- SgtnClient.logger.debug "-----------Start to validate configuration's setting itmes-----------"
8
7
  env = SgtnClient::Config.default_environment
8
+ SgtnClient.logger.debug "[ValidateUtil][validate_config] env = #{env}"
9
9
  messages = "\n"
10
10
 
11
11
  mode = SgtnClient::Config.configurations[env]["mode"]
@@ -36,7 +36,6 @@ module SgtnClient
36
36
  if messages != "\n"
37
37
  raise SgtnClient::Exceptions::MissingConfig.new(messages)
38
38
  end
39
- SgtnClient.logger.debug "-----------End to validate configuration's setting itmes-----------"
40
39
  end
41
40
 
42
41
  end
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.26
4
+ version: 0.7.0.30
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-25 00:00:00.000000000 Z
11
+ date: 2022-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client