carioca 2.0.12 → 2.1.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.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/main.yml +7 -1
  3. data/Gemfile +1 -0
  4. data/Gemfile.lock +10 -1
  5. data/LICENSE.txt +21 -0
  6. data/README.md +562 -9
  7. data/Rakefile +5 -0
  8. data/VERSION +1 -1
  9. data/assets/images/carioca_output_emoji_colors.PNG +0 -0
  10. data/assets/images/carioca_output_emoji_no_colors.PNG +0 -0
  11. data/assets/images/carioca_output_no_emoji_colors.PNG +0 -0
  12. data/assets/images/carioca_output_no_emoji_no_colors.PNG +0 -0
  13. data/assets/images/description_carioca.png +0 -0
  14. data/assets/images/description_configuration_carioca.png +0 -0
  15. data/assets/images/description_container_carioca.png +0 -0
  16. data/assets/images/description_registry_carioca.png +0 -0
  17. data/assets/images/description_services_carioca.png +0 -0
  18. data/assets/images/logo_carioca_full_large.png +0 -0
  19. data/assets/images/logo_carioca_full_small.png +0 -0
  20. data/assets/images/logo_carioca_light_small.png +0 -0
  21. data/carioca.gemspec +2 -0
  22. data/config/locales/en.yml +34 -0
  23. data/config/locales/fr.yml +35 -1
  24. data/lib/carioca/configuration.rb +6 -2
  25. data/lib/carioca/constants.rb +38 -1
  26. data/lib/carioca/dependencies.rb +13 -0
  27. data/lib/carioca/services/config.rb +1 -1
  28. data/lib/carioca/services/finisher.rb +121 -0
  29. data/lib/carioca/services/sanitycheck.rb +140 -0
  30. data/lib/carioca/services/securestore.rb +81 -0
  31. data/lib/carioca/services/setup.rb +83 -0
  32. data/lib/carioca/services/toolbox.rb +104 -0
  33. data/samples/config/carioca.registry +0 -15
  34. data/samples/config/locales/en.yml +2 -1
  35. data/samples/config/settings.yml +29 -6
  36. data/samples/test.rb +111 -11
  37. metadata +48 -2
@@ -0,0 +1,104 @@
1
+ # coding: utf-8
2
+
3
+ # base Carioca namespace
4
+ module Carioca
5
+
6
+ module Services
7
+
8
+ # Exiter namespace
9
+ class Toolbox
10
+
11
+ def self.describe
12
+ result = {}
13
+ self.methods(false).each do |meth|
14
+ next if meth == :describe
15
+ result[meth] = self.send meth, **{describe: true}
16
+ end
17
+ return result
18
+ end
19
+
20
+ # return the 'root' name
21
+ # @return [String] name
22
+ def self.user_root(description: "Get the local system root username ", describe: false)
23
+ return description if describe
24
+ return Etc.getpwuid(0).name
25
+ end
26
+
27
+ # return the 'root' group name : root or wheel
28
+ # @return [String] name
29
+ def self.group_root(description: "Get the local system root groupname ", describe: false)
30
+ return description if describe
31
+ return Etc.getgrgid(0).name
32
+ end
33
+
34
+ # facility for retreiving PID from process query
35
+ # @option [String] :pattern a regexp to search
36
+ # @option [Array] :patterns an array of regexp to search
37
+ # @option [Bool] :full flag to retrieve all process data not only PID
38
+ # @return [String|Array] PID or data structure
39
+ def self.get_processes(patterns: [], pattern: nil, full: false, description: "Get the list of running processus", describe: false)
40
+ return description if describe
41
+ patterns << pattern if pattern
42
+ res = ::PS.get_all_processes
43
+ patterns.each do |item|
44
+ res = res.find_processes item
45
+ end
46
+ if full then
47
+ return res
48
+ else
49
+ return res.pick_attr('PID')
50
+ end
51
+ end
52
+
53
+
54
+ # facility to find a file in gem path
55
+ # @param [String] _gem a Gem name
56
+ # @param [String] _file a file relative path in the gem
57
+ # @return [String] the path of the file, if found.
58
+ # @return [False] if not found
59
+ def self.search_file_in_gem(_gem=nil,_file=nil, description: "Retrieve absolute path of a file in a specific gem", describe: false)
60
+ return description if describe
61
+ if Gem::Specification.respond_to?(:find_by_name)
62
+ begin
63
+ spec = Gem::Specification.find_by_name(_gem)
64
+ rescue LoadError
65
+ spec = nil
66
+ end
67
+ else
68
+ spec = Gem.searcher.find(_gem)
69
+ end
70
+ if spec then
71
+ if Gem::Specification.respond_to?(:find_by_name)
72
+ res = spec.lib_dirs_glob.split('/')
73
+ else
74
+ res = Gem.searcher.lib_dirs_for(spec).split('/')
75
+ end
76
+ res.pop
77
+ services_path = res.join('/').concat("/#{_file}")
78
+ return services_path if File::exist?(services_path)
79
+ return false
80
+ else
81
+ return false
82
+ end
83
+ end
84
+
85
+
86
+
87
+ # facility to verifying if the active process run as root
88
+ # @return [Bool] status
89
+ def self.is_root?(description: "Verify if active current processus is running as root", describe: false)
90
+ return description if describe
91
+ return Process.uid == 0
92
+ end
93
+
94
+ # check if unicode must be used with term ENV
95
+ # @return [Boolean]
96
+ def self.check_unicode_term(description: "Check if terminal support unicode", describe: false)
97
+ return description if describe
98
+ return false unless ENV.include? "TERM"
99
+ return (ENV.values_at("LC_ALL","LC_CTYPE","LANG").compact.include?("UTF-8") and ENV.values_at('TERM').include? "xterm")
100
+ end
101
+
102
+ end
103
+ end
104
+ end
@@ -1,19 +1,4 @@
1
1
  ---
2
- :toto:
3
- :type: :gem
4
- :description: The toto service
5
- :service: Toto
6
- :resource: toto
7
- :depends:
8
- - :configuration
9
- :sqdqd:
10
- :type: :internal
11
- :description: The sqdqd service
12
- :service: SQP::new('titi')
13
- :depends:
14
- - :configuration
15
- - :logger
16
- - :toto
17
2
  :uuid:
18
3
  :type: :gem
19
4
  :description: The uuid service
@@ -1,2 +1,3 @@
1
1
  en:
2
- test: 'english'
2
+ test: 'english'
3
+ fallback: "english fallback"
@@ -1,5 +1,5 @@
1
1
  ---
2
- :monappli:
2
+ :myappli:
3
3
  :production: {}
4
4
  :staging:
5
5
  :onstaging: staging
@@ -12,13 +12,36 @@
12
12
  :trunk2:
13
13
  :branch3: leaf3
14
14
  :branch4: leaf4
15
- :branch5: [ "toto","titi","tata" ]
15
+ :branch5: [ "val1","val2","val3" ]
16
16
  :default:
17
- :toto: 'titi'
17
+ :default_value: 'value'
18
18
  :treeA:
19
19
  :trunk1:
20
20
  :branch2: leaf2
21
21
  :trunk2:
22
- :branch5: ["tutu"]
23
-
24
-
22
+ :branch5: ["value"]
23
+ :setup:
24
+ :rules:
25
+ - :action: :install_file
26
+ :source: "samples/config/settings.yml"
27
+ :target: "/tmp/settings.yml"
28
+ - :action: :install_file
29
+ :source: "samples/config/carioca.registry"
30
+ :target: "/tmp/carioca.registry"
31
+ :mode: "755"
32
+ - :action: :make_folder
33
+ :path: /tmp/toto
34
+ :mode: "755"
35
+ - :action: :make_link
36
+ :source: /tmp/settings.yml
37
+ :link: /tmp/application.yml
38
+ :sanitycheck:
39
+ :rules:
40
+ - :test: :verify_file
41
+ :name: "/tmp/carioca.registry"
42
+ :mode: "644"
43
+ - :test: :verify_folder
44
+ :name: "/tmp/toto"
45
+ :mode: "755"
46
+ - :test: :verify_link
47
+ :name: "/tmp/application.yml"
data/samples/test.rb CHANGED
@@ -3,33 +3,36 @@
3
3
  require 'rubygems'
4
4
  require 'carioca'
5
5
 
6
+ # Configuration of Carioca
6
7
  Carioca::Registry.configure do |spec|
7
8
  spec.filename = './config/carioca.registry'
8
- spec.debug = true
9
+ spec.debug = false
9
10
  spec.init_from_file = true
10
- # spec.log_file = '/tmp/test.rge'
11
+ spec.log_file = '/tmp/test.rge'
11
12
  spec.config_file = './config/settings.yml'
12
- spec.config_root = :monappli
13
+ spec.config_root = :myappli
13
14
  spec.environment = :development
14
15
  spec.default_locale = :fr
15
16
  spec.log_level = :debug
16
- spec.output_mode = :mono
17
+ spec.output_mode = :dual
17
18
  spec.output_emoji = true
18
19
  spec.output_colors = true
19
20
  spec.locales_load_path << Dir["#{File.expand_path('./config/locales')}/*.yml"]
20
21
  spec.debugger_tracer = :output
21
22
  end
22
23
 
24
+ # test fo internal specific service
23
25
  class MyService
24
26
  extend Carioca::Injector
25
27
  inject service: :logger
28
+ inject service: :output
26
29
 
27
30
  def initialize
28
31
  logger.warn(self.class.to_s) { 'Init service' }
29
32
  end
30
33
 
31
34
  def hello
32
- logger.info(self.class.to_s) { 'Hello World' }
35
+ output.info 'Hello World'
33
36
  end
34
37
 
35
38
  def method_test(_titi, tutu:)
@@ -44,21 +47,42 @@ spec = {
44
47
  type: :internal
45
48
  }
46
49
 
50
+
51
+ puts "\nTest 1 : access to registry : adding a internal service MyService"
47
52
  Carioca::Registry.init.add service: :myservice, definition: spec
48
53
 
54
+ puts "\nTest 2 : list of avaible services : MyService include"
49
55
  logger = Carioca::Registry.get.get_service name: :logger
56
+ logger.info(to_s) { "Available services : #{Carioca::Registry.get.services.keys} " }
57
+
58
+
59
+ puts "\nTest 3 : using MyService "
60
+ myservice = Carioca::Registry.get.get_service name: :myservice
61
+ myservice.hello
62
+
63
+
50
64
 
51
- logger.info(to_s) { "avaible services : #{Carioca::Registry.get.services.keys} " }
65
+ puts "\nTest 4 : Service I18n test :es, :fr, come back :en vi service output"
52
66
  i18n = Carioca::Registry.get.get_service name: :i18n
67
+ output = Carioca::Registry.get.get_service name: :output
68
+ [:es,:fr,:en].each do |locale|
69
+ i18n.locale = locale
70
+ output.item i18n.t(:test)
71
+ end
72
+
73
+ puts "\nTest 5 : Service I18n test fallback :en on local :es for missing :es locale"
53
74
  i18n.locale = :es
54
- p i18n.t(:test)
75
+ output.item i18n.t(:fallback)
76
+ i18n.locale = :en
55
77
 
78
+ puts "\nTest 5 : Service Configuration test merge runtime form config file"
56
79
  config = Carioca::Registry.get.get_service name: :configuration
80
+ pp config.settings.to_h
57
81
  config.settings.newkey = 'value'
58
82
 
59
- logger.info(to_s) { config.settings }
60
83
 
61
- class MonAppli < Carioca::Container
84
+ # template override sample
85
+ class MyAppli < Carioca::Container
62
86
  def test
63
87
  myservice.hello
64
88
  logger.warn(self.class.to_s) { uuid.generate }
@@ -74,17 +98,21 @@ class MonAppli < Carioca::Container
74
98
  def test2
75
99
  cycle = %i[unknown fatal error ko warn info item arrow scheduling trigger sending calling receive
76
100
  ok success debug flat]
101
+ puts "*** color and Emoji"
77
102
  cycle.each do |verb|
78
103
  output.send verb, verb.to_s
79
104
  end
105
+ puts "*** no-color and Emoji"
80
106
  output.color = false
81
107
  cycle.each do |verb|
82
108
  output.send verb, verb.to_s
83
109
  end
110
+ puts "*** no-color and no-Emoji"
84
111
  output.emoji = false
85
112
  cycle.each do |verb|
86
113
  output.send verb, verb.to_s
87
114
  end
115
+ puts "*** color and no-Emoji"
88
116
  output.color = true
89
117
  cycle.each do |verb|
90
118
  output.send verb, verb.to_s
@@ -99,7 +127,79 @@ class MonAppli < Carioca::Container
99
127
  end
100
128
  end
101
129
 
102
- appli = MonAppli.new
130
+ appli = MyAppli.new
131
+ puts "\nTest 6 : Carioca::Container template and registry file service defined usage (UUID) from gem"
103
132
  appli.test
104
- # appli.test2
133
+ puts "\nTest 7 : Service output display mode on STDOUT"
134
+ appli.test2
135
+ puts "\nTest 8 : Service debugger display mode on STDOUT"
105
136
  appli.test3
137
+
138
+ output.emoji = true
139
+ output.color = true
140
+
141
+ puts "\nTest 9 : Service toolbox list of avaibles methodes"
142
+ toolbox = Carioca::Registry.get.get_service name: :toolbox
143
+ pp toolbox.describe
144
+
145
+ puts "\nTest 10 : Service toolbox test of simple methode : :user_root"
146
+ pp toolbox.user_root
147
+
148
+ puts "\nTest 11 : Service toolbox test of simple methode : :search_file_in_gem"
149
+ pp toolbox.search_file_in_gem('carioca','config/locales/en.yml')
150
+
151
+ puts "\nTest 12 : Service setup execute setup schema from configuration"
152
+ setup = Carioca::Registry.get.get_service name: :setup
153
+ setup.execute!
154
+
155
+ puts "\nTest 13 : Service sanitycheck run checking schema from configuration"
156
+ sanitycheck = Carioca::Registry.get.get_service name: :sanitycheck
157
+ sanitycheck.run
158
+
159
+ puts "\nTest 14 : Service SecureStore init or access"
160
+ securestore = Carioca::Registry.get.get_service name: :securestore
161
+
162
+
163
+ puts "\nTest 15 : Service SecureStore getting previous data"
164
+ res = (securestore.data.empty?)? "first time" : securestore.data.to_s
165
+ output.info res
166
+
167
+ puts "\nTest 16 : Service SecureStore setting new data"
168
+ securestore.data[:time] = Time.now
169
+ securestore.save!
170
+
171
+ puts "\nTest 17 : Service finisher : test all cases"
172
+ output.item "flat api return, no-json, no-structured"
173
+ finisher = Carioca::Registry.get.get_service name: :finisher
174
+ test = finisher.secure_api_return(return_case: :status_ok, structured: false, json: false) do
175
+ "test"
176
+ end
177
+ puts test
178
+
179
+ output.item "api return, no-json, no-structured but with secure_raise"
180
+ test = finisher.secure_api_return(return_case: :status_ok, structured: false, json: false) do
181
+ finisher.secure_raise message: "error !", error_case: :status_ko
182
+ "test"
183
+ end
184
+ puts test
185
+
186
+ output.item "api return, json, structured but with secure_raise"
187
+ test = finisher.secure_api_return(return_case: :status_ok, structured: true, json: true) do
188
+ finisher.secure_raise message: "error !", error_case: :status_ko
189
+ "test"
190
+ end
191
+ puts test
192
+
193
+ output.item "api return, json, structured"
194
+ test = finisher.secure_api_return(return_case: :status_ok, structured: true, json: true) do
195
+ "test"
196
+ end
197
+ puts test
198
+
199
+ puts "\nTest 18 : Service finisher : exit case in success"
200
+ i18n.locale = :fr
201
+ finisher.secure_execute! exit_case: :success_exit do
202
+ puts 'finishing action'
203
+ #finisher.secure_raise message: "error !", error_case: :status_ko
204
+ 'message'
205
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carioca
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.12
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Romain GEORGES
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-05-24 00:00:00.000000000 Z
11
+ date: 2023-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deep_merge
@@ -164,6 +164,20 @@ dependencies:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0.1'
167
+ - !ruby/object:Gem::Dependency
168
+ name: bundle-audit
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: 0.1.0
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: 0.1.0
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: version
169
183
  requirement: !ruby/object:Gem::Requirement
@@ -178,6 +192,20 @@ dependencies:
178
192
  - - "~>"
179
193
  - !ruby/object:Gem::Version
180
194
  version: '1.1'
195
+ - !ruby/object:Gem::Dependency
196
+ name: ps-ruby
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: 0.0.4
202
+ type: :runtime
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: 0.0.4
181
209
  description: 'Carioca 2: is a complete rewrite who provide a full IoC/DI light Container
182
210
  and a services registry, build with logs, config and Internationalization facilities
183
211
  for designing your applications'
@@ -193,10 +221,23 @@ files:
193
221
  - ".rubocop.yml"
194
222
  - Gemfile
195
223
  - Gemfile.lock
224
+ - LICENSE.txt
196
225
  - README.md
197
226
  - Rakefile
198
227
  - VERSION
228
+ - assets/images/carioca_output_emoji_colors.PNG
229
+ - assets/images/carioca_output_emoji_no_colors.PNG
230
+ - assets/images/carioca_output_no_emoji_colors.PNG
231
+ - assets/images/carioca_output_no_emoji_no_colors.PNG
232
+ - assets/images/description_carioca.png
233
+ - assets/images/description_configuration_carioca.png
234
+ - assets/images/description_container_carioca.png
235
+ - assets/images/description_registry_carioca.png
236
+ - assets/images/description_services_carioca.png
199
237
  - assets/images/logo_carioca.png
238
+ - assets/images/logo_carioca_full_large.png
239
+ - assets/images/logo_carioca_full_small.png
240
+ - assets/images/logo_carioca_light_small.png
200
241
  - bin/console
201
242
  - bin/setup
202
243
  - carioca.gemspec
@@ -217,9 +258,14 @@ files:
217
258
  - lib/carioca/registry_file.rb
218
259
  - lib/carioca/services/config.rb
219
260
  - lib/carioca/services/debug.rb
261
+ - lib/carioca/services/finisher.rb
220
262
  - lib/carioca/services/i18n.rb
221
263
  - lib/carioca/services/init.rb
222
264
  - lib/carioca/services/output.rb
265
+ - lib/carioca/services/sanitycheck.rb
266
+ - lib/carioca/services/securestore.rb
267
+ - lib/carioca/services/setup.rb
268
+ - lib/carioca/services/toolbox.rb
223
269
  - lib/carioca/validator.rb
224
270
  - lib/carioca/version.rb
225
271
  - samples/Rakefile