gloo 4.6.1 → 5.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 (69) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/gloo.gemspec +22 -11
  4. data/lib/VERSION +1 -1
  5. data/lib/VERSION_NOTES +12 -0
  6. data/lib/gloo/app/engine.rb +8 -1
  7. data/lib/gloo/app/running_app.rb +13 -0
  8. data/lib/gloo/app/settings.rb +5 -1
  9. data/lib/gloo/core/dictionary.rb +15 -2
  10. data/lib/gloo/objs/ctrl/each.rb +2 -2
  11. data/lib/gloo/plugin/base.rb +19 -0
  12. data/lib/gloo/plugin/callback.rb +33 -0
  13. data/lib/gloo/plugin/ext_manager.rb +90 -0
  14. data/lib/gloo/plugin/lib_manager.rb +97 -0
  15. data/lib/gloo/verbs/exists.rb +75 -0
  16. data/lib/gloo/verbs/help.rb +58 -1
  17. data/lib/gloo/verbs/load.rb +49 -5
  18. data/lib/gloo/verbs/redirect.rb +2 -1
  19. metadata +38 -166
  20. data/lib/gloo/objs/cli/colorize.rb +0 -73
  21. data/lib/gloo/objs/cli/confirm.rb +0 -96
  22. data/lib/gloo/objs/cli/menu.rb +0 -370
  23. data/lib/gloo/objs/cli/menu_item.rb +0 -95
  24. data/lib/gloo/objs/cli/prompt.rb +0 -110
  25. data/lib/gloo/objs/cli/select.rb +0 -127
  26. data/lib/gloo/objs/ctrl/each_repo.rb +0 -84
  27. data/lib/gloo/objs/data/markdown.rb +0 -133
  28. data/lib/gloo/objs/data/markdown_ext.rb +0 -260
  29. data/lib/gloo/objs/data/mysql.rb +0 -254
  30. data/lib/gloo/objs/data/pg.rb +0 -216
  31. data/lib/gloo/objs/data/query.rb +0 -269
  32. data/lib/gloo/objs/data/query_result.rb +0 -158
  33. data/lib/gloo/objs/data/sqlite.rb +0 -174
  34. data/lib/gloo/objs/data/table.rb +0 -267
  35. data/lib/gloo/objs/dev/git.rb +0 -140
  36. data/lib/gloo/objs/dev/stats.rb +0 -123
  37. data/lib/gloo/objs/system/ssh_exec.rb +0 -126
  38. data/lib/gloo/objs/web/slack.rb +0 -130
  39. data/lib/gloo/objs/web/teams.rb +0 -117
  40. data/lib/gloo/objs/web_svr/element.rb +0 -254
  41. data/lib/gloo/objs/web_svr/field.rb +0 -429
  42. data/lib/gloo/objs/web_svr/form.rb +0 -271
  43. data/lib/gloo/objs/web_svr/page.rb +0 -562
  44. data/lib/gloo/objs/web_svr/partial.rb +0 -210
  45. data/lib/gloo/objs/web_svr/svr.rb +0 -713
  46. data/lib/gloo/utils/stats.rb +0 -206
  47. data/lib/gloo/verbs/alert.rb +0 -79
  48. data/lib/gloo/verbs/beep.rb +0 -40
  49. data/lib/gloo/web_svr/asset.rb +0 -407
  50. data/lib/gloo/web_svr/asset_info.rb +0 -116
  51. data/lib/gloo/web_svr/config.rb +0 -56
  52. data/lib/gloo/web_svr/embedded_renderer.rb +0 -154
  53. data/lib/gloo/web_svr/handler.rb +0 -154
  54. data/lib/gloo/web_svr/request.rb +0 -143
  55. data/lib/gloo/web_svr/request_params.rb +0 -181
  56. data/lib/gloo/web_svr/response.rb +0 -177
  57. data/lib/gloo/web_svr/response_code.rb +0 -69
  58. data/lib/gloo/web_svr/routing/resource_router.rb +0 -47
  59. data/lib/gloo/web_svr/routing/router.rb +0 -232
  60. data/lib/gloo/web_svr/routing/show_routes.rb +0 -94
  61. data/lib/gloo/web_svr/server.rb +0 -105
  62. data/lib/gloo/web_svr/session.rb +0 -215
  63. data/lib/gloo/web_svr/table_renderer.rb +0 -151
  64. data/lib/gloo/web_svr/web_method.rb +0 -54
  65. /data/lib/gloo/objs/{security → str_utils}/cipher.rb +0 -0
  66. /data/lib/gloo/objs/{security → str_utils}/csrf_token.rb +0 -0
  67. /data/lib/gloo/objs/{security → str_utils}/password.rb +0 -0
  68. /data/lib/gloo/objs/{ror → system}/erb.rb +0 -0
  69. /data/lib/gloo/objs/{ror → system}/eval.rb +0 -0
@@ -1,105 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 2024 Eric Crane. All rights reserved.
3
- #
4
- # Starting work on web server inside gloo.
5
- #
6
- # UNDER CONSTRUCTION!
7
- #
8
- # Simple tests:
9
- # > curl http://localhost:8087/test/
10
- # > curl http://localhost:8087/web/
11
- # > curl http://localhost:8087/test/1
12
- # > curl http://localhost:8087/test?param=123
13
- #
14
- # Run in loop:
15
- # for i in {1..99}; do curl http://localhost:8087/; done
16
- #
17
- # Links:
18
- # https://github.com/rack/rack
19
- # https://github.com/rack/rack/blob/main/lib/rack/builder.rb
20
- # https://thoughtbot.com/blog/ruby-rack-tutorial
21
- # https://www.rubydoc.info/gems/rack/1.5.5/Rack/Runtime
22
- #
23
-
24
- require 'rack'
25
-
26
- module Gloo
27
- module WebSvr
28
- class Server
29
-
30
- # ---------------------------------------------------------------------
31
- # Initialization
32
- # ---------------------------------------------------------------------
33
-
34
- #
35
- # Set up the web server.
36
- #
37
- def initialize( engine, handler, config = nil, ssl_config = nil )
38
- @config = config ? config : Gloo::WebSvr::Config.new
39
- @ssl_config = ssl_config
40
- @engine = engine
41
- @log = @engine.log
42
- @handler = handler
43
-
44
- @log.debug 'Gloo web server intialized…'
45
- end
46
-
47
-
48
- # ---------------------------------------------------------------------
49
- # Start and Stop the server.
50
- # ---------------------------------------------------------------------
51
-
52
- #
53
- # Start the web server.
54
- #
55
- def start
56
- opts = {
57
- :Port => @config.port,
58
- :Host => @config.host
59
- }
60
- Thread.abort_on_exception = true
61
- @server_thread = Thread.new {
62
- Rack::Handler::Thin.run( self, **options=opts ) do |server|
63
- if @ssl_config
64
- server.ssl = true
65
- server.ssl_options = @ssl_config
66
- end
67
- end
68
- }
69
- @log.debug 'Web server has started.'
70
- end
71
-
72
- #
73
- # Stop the web server
74
- #
75
- def stop
76
- @log.debug 'Stopping the web server…'
77
-
78
- @server_thread.kill
79
-
80
- @log.debug 'The web server has been stopped.'
81
- end
82
-
83
-
84
- # ---------------------------------------------------------------------
85
- # Handle events
86
- # ---------------------------------------------------------------------
87
-
88
- #
89
- # Handle a request for a resource.
90
- #
91
- def call( env )
92
- request = Gloo::WebSvr::Request.new( @engine, @handler, env )
93
- request.log
94
-
95
- response = request.process
96
- response.log if response
97
-
98
- return response ? response.result : nil
99
- end
100
-
101
-
102
- end
103
- end
104
- end
105
-
@@ -1,215 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 2024 Eric Crane. All rights reserved.
3
- #
4
- # Helpers for getting and setting session data.
5
- #
6
- # Resources:
7
- # https://www.rubydoc.info/gems/rack/1.5.5/Rack/Request#cookies-instance_method
8
- # https://rubydoc.info/github/rack/rack/Rack/Utils#set_cookie_header-class_method
9
- # https://en.wikipedia.org/wiki/HTTP_cookie
10
- #
11
- require 'base64'
12
-
13
- module Gloo
14
- module WebSvr
15
- class Session
16
-
17
- SESSION_CONTAINER = 'session'.freeze
18
- SESSION_ID_NAME = 'session_id'.freeze
19
-
20
-
21
- # ---------------------------------------------------------------------
22
- # Initialization
23
- # ---------------------------------------------------------------------
24
-
25
- #
26
- # Set up the web server.
27
- #
28
- def initialize( engine, server_obj )
29
- @engine = engine
30
- @log = @engine.log
31
-
32
- @server_obj = server_obj
33
- @include_in_response = false
34
- @clearing_session = false
35
- end
36
-
37
-
38
- # ---------------------------------------------------------------------
39
- # Set Session Data for Request
40
- # ---------------------------------------------------------------------
41
-
42
- #
43
- # Get the session data from the encrypted cookie.
44
- # Add it to the session container.
45
- #
46
- def set_session_data_for_request( env )
47
- begin
48
- cookie_hash = Rack::Utils.parse_cookies( env )
49
-
50
- # Are we using sessions?
51
- if @server_obj.use_session?
52
- data = cookie_hash[ session_name ]
53
-
54
- if data
55
- data = decode_decrypt( data )
56
- return unless data
57
-
58
- @session_id = data[ SESSION_ID_NAME ]
59
-
60
- data.each do |key, value|
61
- unless key == SESSION_ID_NAME
62
- @server_obj.set_session_var( key, value )
63
- end
64
- end
65
- end
66
- end
67
- rescue => e
68
- @engine.log_exception e
69
- end
70
- end
71
-
72
-
73
- # ---------------------------------------------------------------------
74
- # Set Session Data for Response
75
- # ---------------------------------------------------------------------
76
-
77
- #
78
- # Temporarily set the flag to add the session data to the response.
79
- # Once this is done, the flag will be cleared and it will not
80
- # be added to the next request unless specifically set.
81
- #
82
- def add_session_to_response
83
- @include_in_response = true
84
- end
85
-
86
- def init_session_id
87
- @session_id = Gloo::Objs::CsrfToken.generate_csrf_token
88
- return @session_id
89
- end
90
-
91
- #
92
- # Initialize the session id and add it to the data.
93
- # Use the current session ID if it is there.
94
- #
95
- def get_session_id
96
- if @clearing_session
97
- @clearing_session = false
98
- return nil
99
- end
100
-
101
- init_session_id if @session_id.blank?
102
-
103
- return @session_id
104
- end
105
-
106
- #
107
- # Clear out the session Id.
108
- # Set the flag to add the session data to the response.
109
- #
110
- def clear_session_data
111
- @session_id = nil
112
- @clearing_session = true
113
- add_session_to_response
114
- end
115
-
116
- #
117
- # If there is session data, encrypt and add it to the response.
118
- # Once done, clear out the session data.
119
- #
120
- def add_session_for_response( headers )
121
- # Are we using sessions?
122
- if @server_obj.use_session? && @include_in_response
123
- # Reset the flag because we are adding to the session data now
124
- @include_in_response = false
125
-
126
- # Build and add encrypted session data
127
- data = @server_obj.get_session_data
128
- data[ SESSION_ID_NAME ] = get_session_id
129
-
130
- unless data.empty?
131
- data = encrypt_encode( data )
132
- session_hash = {
133
- value: data,
134
- path: cookie_path,
135
- expires: cookie_expires,
136
- http_only: true }
137
-
138
- if secure_cookie?
139
- session_hash[ :secure ] = true
140
- end
141
-
142
- Rack::Utils.set_cookie_header!( headers, session_name, session_hash )
143
- end
144
- end
145
-
146
- return headers
147
- end
148
-
149
-
150
- # ---------------------------------------------------------------------
151
- # Helper functions
152
- # ---------------------------------------------------------------------
153
-
154
- #
155
- # Encrypt and encode the session data.
156
- #
157
- def encrypt_encode( data )
158
- return Gloo::Objs::Cipher.encrypt( data.to_json, key, iv )
159
- end
160
-
161
- #
162
- # Decode and decrypt the session data.
163
- #
164
- def decode_decrypt( data )
165
- return nil unless data && key && iv
166
-
167
- data = Gloo::Objs::Cipher.decrypt( data, key, iv )
168
- return JSON.parse( data )
169
- end
170
-
171
- #
172
- # Get the session cookie name.
173
- #
174
- def session_name
175
- return @server_obj.session_name
176
- end
177
-
178
- #
179
- # Get the key for the encryption cipher.
180
- #
181
- def key
182
- return @server_obj.encryption_key
183
- end
184
-
185
- #
186
- # Get the initialization vector for the cipher.
187
- #
188
- def iv
189
- return @server_obj.encryption_iv
190
- end
191
-
192
- #
193
- # Get the path for the session cookie.
194
- #
195
- def cookie_path
196
- return @server_obj.session_cookie_path
197
- end
198
-
199
- #
200
- # Get the expiration time for the session cookie.
201
- #
202
- def cookie_expires
203
- return @server_obj.session_cookie_expires
204
- end
205
-
206
- #
207
- # Should the session cookie be secure?
208
- #
209
- def secure_cookie?
210
- return @server_obj.session_cookie_secure
211
- end
212
-
213
- end
214
- end
215
- end
@@ -1,151 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 2024 Eric Crane. All rights reserved.
3
- #
4
- # A helper class used to render HTML tables.
5
- #
6
-
7
- module Gloo
8
- module WebSvr
9
- class TableRenderer
10
-
11
- TABLE = 'table'.freeze
12
- THEAD = 'thead'.freeze
13
- HEAD_CELL = 'head_cell'.freeze
14
- ROW = 'row'.freeze
15
- CELL = 'cell'.freeze
16
-
17
- NO_DATA_FOUND = "<p>No data found.</p>".freeze
18
-
19
- # ---------------------------------------------------------------------
20
- # Initialization
21
- # ---------------------------------------------------------------------
22
-
23
- #
24
- # Set up the web server.
25
- #
26
- def initialize( engine )
27
- @engine = engine
28
- @log = @engine.log
29
- end
30
-
31
-
32
- # ---------------------------------------------------------------------
33
- # Container Renderer
34
- # ---------------------------------------------------------------------
35
-
36
- #
37
- # Render the query result set to an HTML table.
38
- #
39
- # params = {
40
- # head: head,
41
- # cols: result[0],
42
- # rows: rows,
43
- # styles: self.styles,
44
- # cell_renderers: self.cell_renderers
45
- # }
46
- #
47
- def data_to_table params
48
- data = params[ :rows ]
49
- return NO_DATA_FOUND if data.nil? || ( data.length == 0 )
50
-
51
- single_row = true if ( data.length == 1 )
52
- single_row = false if params[ :always_rows ]
53
-
54
- if single_row
55
- return data_to_single_row_table( params )
56
- else
57
- return data_to_table_rows( params )
58
- end
59
- end
60
-
61
- #
62
- # Show in single-row (form) format.
63
- #
64
- def data_to_single_row_table( params )
65
- styles = params[ :styles ]
66
- str = "<table class='#{styles[ TABLE ]}'> <tbody>"
67
- row = params[ :rows ].first
68
-
69
- params[ :columns ].each do |head|
70
- next unless head[ :visible ]
71
- cell = row[ head[ :data_index ] ]
72
-
73
- if head[ :cell_renderer ]
74
- cell_value = render_cell( row, head, params[ :columns ] )
75
- else
76
- cell_value = cell
77
- end
78
-
79
- str += "<tr class='#{styles[ ROW ]}'>"
80
- str += "<th class='#{styles[ HEAD_CELL ]}'>#{head[ :title ]}</th>"
81
- str += "<td class='#{styles[ CELL ]}'>#{cell_value}</td>"
82
- str += "</tr>"
83
- end
84
-
85
- str += "</tbody></table>"
86
- return str
87
- end
88
-
89
- #
90
- # Show in normal, multi-row format.
91
- #
92
- def data_to_table_rows( params )
93
- styles = params[ :styles ]
94
- # headers = params[ :head ]
95
-
96
- str = "<table class='#{styles[ TABLE ]}'>"
97
- str << "<thead class='#{styles[ THEAD ]}'><tr>"
98
-
99
- params[ :columns ].each do |head|
100
- next unless head[ :visible ]
101
- str += "<th class='#{styles[ HEAD_CELL ]}'>#{head[ :title ]}</th>"
102
- end
103
- str << "</tr></thead><tbody>"
104
-
105
- params[ :rows ].each do |row|
106
- str += "<tr class='#{styles[ ROW ]}'>"
107
-
108
- # row.each_with_index do |cell, i|
109
- params[ :columns ].each do |head|
110
- next unless head[ :visible ]
111
-
112
- cell = row[ head[ :data_index ] ]
113
- this_col_name = head[ :name ]
114
-
115
- if head[ :cell_renderer ]
116
- cell_value = render_cell( row, head, params[ :columns ] )
117
- else
118
- cell_value = cell
119
- end
120
- str += "<td class='#{styles[ CELL ]}'>#{cell_value}</td>"
121
- end
122
- str += "</tr>"
123
- end
124
- str += "</tbody></table>"
125
-
126
- return str
127
- end
128
-
129
- #
130
- # Render a cell using the cell renderer and the given
131
- # context data (the row's values).
132
- #
133
- def render_cell row, col, cols
134
- params = {}
135
-
136
- cols.each_with_index do |c, i|
137
- params[ c[ :name ] ] = row[ c[ :data_index ] ]
138
- end
139
-
140
- content = col[ :cell_renderer ]
141
- content = @engine.running_app.obj.embedded_renderer.render content, params
142
-
143
- # renderer = ERB.new( col[ :cell_renderer ] )
144
- # content = renderer.result_with_hash( params )
145
-
146
- return content
147
- end
148
- end
149
-
150
- end
151
- end
@@ -1,54 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 2024 Eric Crane. All rights reserved.
3
- #
4
- # A helper class for Web Methods.
5
- #
6
-
7
- module Gloo
8
- module WebSvr
9
- class WebMethod
10
-
11
- GET = 'GET'.freeze
12
- POST = 'POST'.freeze
13
- PUT = 'PUT'.freeze
14
- DELETE = 'DELETE'.freeze
15
- PATCH = 'PATCH'.freeze
16
-
17
- #
18
- # Is the method a GET?
19
- #
20
- def self.is_get?( method )
21
- return method.upcase == GET
22
- end
23
-
24
- #
25
- # Is the method a POST?
26
- #
27
- def self.is_post?( method )
28
- return method.upcase == POST
29
- end
30
-
31
- #
32
- # Is the method a PUT?
33
- #
34
- def self.is_put?( method )
35
- return method.upcase == PUT
36
- end
37
-
38
- #
39
- # Is the method a PATCH?
40
- #
41
- def self.is_patch?( method )
42
- return method.upcase == PATCH
43
- end
44
-
45
- #
46
- # Is the method a DELETE?
47
- #
48
- def self.is_delete?( method )
49
- return method.upcase == DELETE
50
- end
51
-
52
- end
53
- end
54
- end
File without changes
File without changes
File without changes
File without changes