gloo 3.3.0 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/gloo.gemspec +8 -3
  4. data/lib/VERSION +1 -1
  5. data/lib/VERSION_NOTES +7 -0
  6. data/lib/gloo/app/engine.rb +1 -1
  7. data/lib/gloo/app/log.rb +15 -16
  8. data/lib/gloo/app/platform.rb +11 -90
  9. data/lib/gloo/app/prompt.rb +90 -0
  10. data/lib/gloo/app/table.rb +51 -0
  11. data/lib/gloo/core/gloo_system.rb +7 -14
  12. data/lib/gloo/objs/basic/container.rb +1 -2
  13. data/lib/gloo/objs/basic/integer.rb +23 -1
  14. data/lib/gloo/objs/basic/string.rb +116 -1
  15. data/lib/gloo/objs/basic/string_generator.rb +49 -0
  16. data/lib/gloo/objs/basic/text.rb +1 -17
  17. data/lib/gloo/objs/cli/menu.rb +5 -4
  18. data/lib/gloo/objs/cli/select.rb +3 -2
  19. data/lib/gloo/objs/data/markdown.rb +25 -30
  20. data/lib/gloo/objs/data/mysql.rb +39 -27
  21. data/lib/gloo/objs/data/pg.rb +1 -1
  22. data/lib/gloo/objs/data/query_result.rb +4 -9
  23. data/lib/gloo/objs/data/table.rb +1 -1
  24. data/lib/gloo/objs/security/cipher.rb +193 -0
  25. data/lib/gloo/objs/security/password.rb +167 -0
  26. data/lib/gloo/objs/system/file_handle.rb +1 -3
  27. data/lib/gloo/objs/web/json.rb +3 -0
  28. data/lib/gloo/objs/web_svr/page.rb +24 -8
  29. data/lib/gloo/objs/web_svr/partial.rb +7 -6
  30. data/lib/gloo/objs/web_svr/svr.rb +267 -14
  31. data/lib/gloo/verbs/version.rb +1 -1
  32. data/lib/gloo/web_svr/asset.rb +34 -13
  33. data/lib/gloo/web_svr/config.rb +1 -1
  34. data/lib/gloo/web_svr/embedded_renderer.rb +1 -1
  35. data/lib/gloo/web_svr/handler.rb +6 -4
  36. data/lib/gloo/web_svr/request.rb +34 -8
  37. data/lib/gloo/web_svr/response.rb +14 -2
  38. data/lib/gloo/web_svr/response_code.rb +1 -1
  39. data/lib/gloo/web_svr/routing/router.rb +1 -2
  40. data/lib/gloo/web_svr/routing/show_routes.rb +4 -7
  41. data/lib/gloo/web_svr/server.rb +1 -1
  42. data/lib/gloo/web_svr/session.rb +161 -0
  43. data/lib/gloo/web_svr/table_renderer.rb +1 -1
  44. metadata +58 -25
  45. data/lib/gloo/objs/cli/banner.rb +0 -118
  46. data/lib/gloo/objs/cli/bar.rb +0 -133
  47. data/lib/gloo/objs/cli/pastel.rb +0 -104
@@ -0,0 +1,167 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2024 Eric Crane. All rights reserved.
3
+ #
4
+ # A hashed password (with salt).
5
+ #
6
+ # BCrypt is used to hash the password.
7
+ # https://www.rubydoc.info/gems/bcrypt-ruby
8
+ # https://github.com/bcrypt-ruby/bcrypt-ruby/blob/master/lib/bcrypt/password.rb
9
+ #
10
+ require 'bcrypt'
11
+
12
+ module Gloo
13
+ module Objs
14
+ class Password < Gloo::Core::Obj
15
+
16
+ KEYWORD = 'password'.freeze
17
+ KEYWORD_SHORT = 'hash'.freeze
18
+
19
+ SALT = 'salt'.freeze
20
+ PASSWORD = 'password'.freeze
21
+ HASH = 'hash'.freeze
22
+
23
+ #
24
+ # The name of the object type.
25
+ #
26
+ def self.typename
27
+ return KEYWORD
28
+ end
29
+
30
+ #
31
+ # The short name of the object type.
32
+ #
33
+ def self.short_typename
34
+ return KEYWORD_SHORT
35
+ end
36
+
37
+ #
38
+ # Get the password salt.
39
+ # Returns nil if there is none.
40
+ #
41
+ def salt
42
+ o = find_child SALT
43
+ return o&.value
44
+ end
45
+
46
+ #
47
+ # Get the password value.
48
+ # Returns nil if there is none.
49
+ #
50
+ def password
51
+ o = find_child PASSWORD
52
+ return o&.value
53
+ end
54
+
55
+ #
56
+ # Update the password value.
57
+ #
58
+ def update_password( new_pwd )
59
+ o = find_child PASSWORD
60
+ return unless o
61
+
62
+ o.set_value new_pwd
63
+ end
64
+
65
+ #
66
+ # Get the salted password.
67
+ #
68
+ def salt_pwd
69
+ return "#{salt}#{password}"
70
+ end
71
+
72
+ #
73
+ # Get the hashed password value.
74
+ # Returns nil if there is none.
75
+ #
76
+ def hash
77
+ o = find_child HASH
78
+ return o&.value
79
+ end
80
+
81
+ #
82
+ # Update the hashed password value.
83
+ #
84
+ def update_hash( new_hash )
85
+ o = find_child HASH
86
+ return unless o
87
+
88
+ o.set_value new_hash
89
+ end
90
+
91
+ # ---------------------------------------------------------------------
92
+ # Children
93
+ # ---------------------------------------------------------------------
94
+
95
+ #
96
+ # Does this object have children to add when an object
97
+ # is created in interactive mode?
98
+ # This does not apply during obj load, etc.
99
+ #
100
+ def add_children_on_create?
101
+ return true
102
+ end
103
+
104
+ #
105
+ # Add children to this object.
106
+ # This is used by containers to add children needed
107
+ # for default configurations.
108
+ #
109
+ def add_default_children
110
+ fac = @engine.factory
111
+ fac.create_string SALT, '', self
112
+ fac.create_string PASSWORD, '', self
113
+ fac.create_string HASH, '', self
114
+ end
115
+
116
+ # ---------------------------------------------------------------------
117
+ # Messages
118
+ # ---------------------------------------------------------------------
119
+
120
+ #
121
+ # Get a list of message names that this object receives.
122
+ #
123
+ def self.messages
124
+ return super + %w[hash check generate]
125
+ end
126
+
127
+ #
128
+ # Generate a random alphanumeric password.
129
+ # By default the length is 7 characters.
130
+ # Set the length with an optional parameter.
131
+ #
132
+ def msg_generate
133
+ len = 7
134
+ if @params&.token_count&.positive?
135
+ expr = Gloo::Expr::Expression.new( @engine, @params.tokens )
136
+ data = expr.evaluate
137
+ len = data.to_i
138
+ end
139
+
140
+ s = StringGenerator.alphanumeric( len )
141
+ update_password s
142
+ @engine.heap.it.set_to s
143
+ return s
144
+ end
145
+
146
+ #
147
+ # Hash the password with the salt.
148
+ # Uses the salt and the password to create a hash.
149
+ #
150
+ def msg_hash
151
+ hashed_pwd = BCrypt::Password.create( salt_pwd )
152
+ update_hash hashed_pwd
153
+ end
154
+
155
+ #
156
+ # Check the password against the hash.
157
+ # Uses the salt and the hash to check the password.
158
+ #
159
+ def msg_check
160
+ hashed_pwd = BCrypt::Password.new( hash )
161
+ result = ( hashed_pwd == salt_pwd )
162
+ @engine.heap.it.set_to result
163
+ end
164
+
165
+ end
166
+ end
167
+ end
@@ -3,7 +3,6 @@
3
3
  #
4
4
  # An object that points to a file in the system.
5
5
  #
6
- require 'tty-pager'
7
6
 
8
7
  module Gloo
9
8
  module Objs
@@ -58,8 +57,7 @@ module Gloo
58
57
  def msg_page
59
58
  return unless value && File.file?( value )
60
59
 
61
- pager = TTY::Pager.new
62
- pager.page( path: value )
60
+ system "less #{value}"
63
61
  end
64
62
 
65
63
  #
@@ -66,6 +66,9 @@ module Gloo
66
66
  return unless self.value
67
67
 
68
68
  json = JSON.parse( self.value )
69
+ if self.value.start_with?( '"{' )
70
+ json = JSON.parse( json )
71
+ end
69
72
  pretty = JSON.pretty_generate( json )
70
73
  set_value pretty
71
74
  end
@@ -13,7 +13,8 @@ module Gloo
13
13
 
14
14
  # Events
15
15
  ON_RENDER = 'on_render'.freeze
16
- ON_RENDERED = 'on_rendered'.freeze
16
+ ON_PRERENDER = 'on_prerender'.freeze
17
+ AFTER_RENDER = 'after_render'.freeze
17
18
 
18
19
  # Parameters used during render.
19
20
  PARAMS = 'params'.freeze
@@ -189,6 +190,18 @@ module Gloo
189
190
  # Events
190
191
  # ---------------------------------------------------------------------
191
192
 
193
+ #
194
+ # Run the on prerender script if there is one.
195
+ #
196
+ def run_on_prerender
197
+ o = find_child ON_PRERENDER
198
+ return unless o
199
+
200
+ @engine.log.debug "running on_prerender for page"
201
+
202
+ Gloo::Exec::Dispatch.message( @engine, 'run', o )
203
+ end
204
+
192
205
  #
193
206
  # Run the on render script if there is one.
194
207
  #
@@ -204,11 +217,11 @@ module Gloo
204
217
  #
205
218
  # Run the on rendered script if there is one.
206
219
  #
207
- def run_on_rendered
208
- o = find_child ON_RENDERED
220
+ def run_after_render
221
+ o = find_child AFTER_RENDER
209
222
  return unless o
210
223
 
211
- @engine.log.debug "running on_rendered for page"
224
+ @engine.log.debug "running after_render for page"
212
225
 
213
226
  Gloo::Exec::Dispatch.message( @engine, 'run', o )
214
227
  end
@@ -236,7 +249,7 @@ module Gloo
236
249
  fac = @engine.factory
237
250
 
238
251
  fac.create_script ON_RENDER, '', self
239
- fac.create_script ON_RENDERED, '', self
252
+ fac.create_script AFTER_RENDER, '', self
240
253
  fac.create_can PARAMS, self
241
254
 
242
255
  params = { :name => HEAD,
@@ -325,12 +338,15 @@ module Gloo
325
338
  @request = request
326
339
  set_id if @request
327
340
 
328
- run_on_render
329
- return nil if redirect_set?
341
+ # Run the on prerender script
342
+ run_on_prerender
330
343
 
331
344
  # Set Params before running on render
332
345
  params = params_hash
333
346
 
347
+ run_on_render
348
+ return nil if redirect_set?
349
+
334
350
  if is_html?
335
351
  contents = render_html params
336
352
  elsif is_json?
@@ -342,7 +358,7 @@ module Gloo
342
358
  return nil
343
359
  end
344
360
 
345
- run_on_rendered
361
+ run_after_render
346
362
  @request = nil
347
363
  return nil if redirect_set?
348
364
 
@@ -13,7 +13,7 @@ module Gloo
13
13
 
14
14
  # Events
15
15
  ON_RENDER = 'on_render'.freeze
16
- ON_RENDERED = 'on_rendered'.freeze
16
+ AFTER_RENDER = 'after_render'.freeze
17
17
 
18
18
  # Parameters used during render.
19
19
  PARAMS = 'params'.freeze
@@ -92,8 +92,8 @@ module Gloo
92
92
  #
93
93
  # Run the on rendered script if there is one.
94
94
  #
95
- def run_on_rendered
96
- o = find_child ON_RENDERED
95
+ def run_after_render
96
+ o = find_child AFTER_RENDER
97
97
  return unless o
98
98
 
99
99
  Gloo::Exec::Dispatch.message( @engine, 'run', o )
@@ -122,7 +122,7 @@ module Gloo
122
122
  fac = @engine.factory
123
123
 
124
124
  fac.create_script ON_RENDER, '', self
125
- fac.create_script ON_RENDERED, '', self
125
+ fac.create_script AFTER_RENDER, '', self
126
126
 
127
127
  fac.create_can PARAMS, self
128
128
  fac.create_can CONTENT, self
@@ -149,6 +149,7 @@ module Gloo
149
149
  return part_content
150
150
  end
151
151
 
152
+
152
153
  # ---------------------------------------------------------------------
153
154
  # Render
154
155
  # ---------------------------------------------------------------------
@@ -173,7 +174,7 @@ module Gloo
173
174
  # part_content = Page.render_params part_content, params_hash
174
175
  part_content = @engine.running_app.obj.embedded_renderer.render part_content, params_hash
175
176
 
176
- run_on_rendered
177
+ run_after_render
177
178
  return part_content
178
179
  end
179
180
 
@@ -200,7 +201,7 @@ module Gloo
200
201
  # part_content = Page.render_params part_content, params
201
202
  part_content = @engine.running_app.obj.embedded_renderer.render part_content, params
202
203
 
203
- run_on_rendered
204
+ run_after_render
204
205
  return part_content
205
206
  end
206
207