gloo 0.7.5 → 0.7.6

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.
@@ -0,0 +1,126 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # An object that can post JSON to a URI.
5
+ #
6
+ require 'net/ssh'
7
+
8
+ module Gloo
9
+ module Objs
10
+ class SshExec < Gloo::Core::Obj
11
+
12
+ KEYWORD = 'ssh_exec'.freeze
13
+ KEYWORD_SHORT = 'ssh'.freeze
14
+ HOST = 'host'.freeze
15
+ DEFAULT_HOST = 'localhost'.freeze
16
+ CMD = 'cmd'.freeze
17
+ RESULT = 'result'.freeze
18
+ HOST_REQUIRED_ERR = 'The host is required!'.freeze
19
+
20
+ #
21
+ # The name of the object type.
22
+ #
23
+ def self.typename
24
+ return KEYWORD
25
+ end
26
+
27
+ #
28
+ # The short name of the object type.
29
+ #
30
+ def self.short_typename
31
+ return KEYWORD_SHORT
32
+ end
33
+
34
+ # ---------------------------------------------------------------------
35
+ # Children
36
+ # ---------------------------------------------------------------------
37
+
38
+ #
39
+ # Does this object have children to add when an object
40
+ # is created in interactive mode?
41
+ # This does not apply during obj load, etc.
42
+ #
43
+ def add_children_on_create?
44
+ return true
45
+ end
46
+
47
+ #
48
+ # Add children to this object.
49
+ # This is used by containers to add children needed
50
+ # for default configurations.
51
+ #
52
+ def add_default_children
53
+ fac = $engine.factory
54
+ fac.create_string HOST, DEFAULT_HOST, self
55
+ fac.create_string CMD, nil, self
56
+ fac.create_string RESULT, nil, self
57
+ end
58
+
59
+ # ---------------------------------------------------------------------
60
+ # Messages
61
+ # ---------------------------------------------------------------------
62
+
63
+ #
64
+ # Get a list of message names that this object receives.
65
+ #
66
+ def self.messages
67
+ return super + [ 'run' ]
68
+ end
69
+
70
+ #
71
+ # SSH to the host and execute the command, then update result.
72
+ #
73
+ def msg_run
74
+ h = host_value
75
+ unless h
76
+ $engine.err HOST_REQUIRED_ERR
77
+ return
78
+ end
79
+
80
+ Net::SSH.start( h ) do |ssh|
81
+ result = ssh.exec!( cmd_value )
82
+ update_result result
83
+ end
84
+ end
85
+
86
+ # ---------------------------------------------------------------------
87
+ # Private functions
88
+ # ---------------------------------------------------------------------
89
+
90
+ private
91
+
92
+ #
93
+ # Get the host from the child object.
94
+ # Returns nil if there is none.
95
+ #
96
+ def host_value
97
+ o = find_child HOST
98
+ return nil unless o
99
+
100
+ return o.value
101
+ end
102
+
103
+ #
104
+ # Get the command from the child object.
105
+ # Returns nil if there is none.
106
+ #
107
+ def cmd_value
108
+ o = find_child CMD
109
+ return nil unless o
110
+
111
+ return o.value
112
+ end
113
+
114
+ #
115
+ # Set the result of the API call.
116
+ #
117
+ def update_result( data )
118
+ r = find_child RESULT
119
+ return nil unless r
120
+
121
+ r.set_value data
122
+ end
123
+
124
+ end
125
+ end
126
+ end
@@ -16,6 +16,7 @@ module Gloo
16
16
  URL = 'uri'.freeze
17
17
  BODY = 'body'.freeze
18
18
  RESULT = 'result'.freeze
19
+ SKIP_SSL_VERIFY = 'skip_ssl_verify'.freeze
19
20
 
20
21
  #
21
22
  # The name of the object type.
@@ -113,8 +114,7 @@ module Gloo
113
114
  $log.debug "posting to: #{uri}"
114
115
  body = self.body_as_json
115
116
  $log.debug "posting body: #{body}"
116
- use_ssl = uri.downcase.start_with?( 'https' )
117
- data = Gloo::Objs::HttpPost.post_json uri, body, use_ssl
117
+ data = Gloo::Objs::HttpPost.post_json( uri, body, skip_ssl_verify? )
118
118
  self.update_result data
119
119
  end
120
120
 
@@ -125,20 +125,57 @@ module Gloo
125
125
  #
126
126
  # Post the content to the endpoint.
127
127
  #
128
- def self.post_json( url, body, use_ssl = true )
129
- # Structure the request
130
- uri = URI.parse( url )
131
- request = Net::HTTP::Post.new( uri.path )
132
- request.content_type = 'application/json'
133
- request.body = body
134
- n = Net::HTTP.new( uri.host, uri.port )
135
- n.use_ssl = use_ssl
136
-
137
- # Send the payload to the endpoint.
138
- result = n.start { |http| http.request( request ) }
139
- $log.debug result.code
140
- $log.debug result.message
141
- return result.body
128
+ def self.post_json( url, body, skip_ssl_verify = false )
129
+ uri = URI( url )
130
+ params = { use_ssl: uri.scheme == 'https' }
131
+ params[ :verify_mode ] = ::OpenSSL::SSL::VERIFY_NONE if skip_ssl_verify
132
+
133
+ Net::HTTP.start( uri.host, uri.port, params ) do |http|
134
+ request = Net::HTTP::Post.new uri
135
+ request.content_type = 'application/json'
136
+ request.body = body
137
+
138
+ result = http.request request # Net::HTTPResponse object
139
+ $log.debug result.code
140
+ $log.debug result.message
141
+ return result.body
142
+ end
143
+ end
144
+
145
+ # #
146
+ # # Post the content to the endpoint.
147
+ # #
148
+ # def self.post_json_1( url, body, use_ssl = true )
149
+ # # Structure the request
150
+ # uri = URI.parse( url )
151
+ #
152
+ # request = Net::HTTP::Post.new( uri.path )
153
+ # request.content_type = 'application/json'
154
+ # request.body = body
155
+ # n = Net::HTTP.new( uri.host, uri.port )
156
+ # n.use_ssl = use_ssl
157
+ #
158
+ # # Send the payload to the endpoint.
159
+ # result = n.start { |http| http.request( request ) }
160
+ # $log.debug result.code
161
+ # $log.debug result.message
162
+ # return result.body
163
+ # end
164
+
165
+ # ---------------------------------------------------------------------
166
+ # Private functions
167
+ # ---------------------------------------------------------------------
168
+
169
+ private
170
+
171
+ #
172
+ # Should we skip SSL verification during the request?
173
+ #
174
+ def skip_ssl_verify?
175
+ skip = find_child SKIP_SSL_VERIFY
176
+ return false unless skip
177
+
178
+ return skip.value
142
179
  end
143
180
 
144
181
  end
@@ -38,7 +38,7 @@ module Gloo
38
38
  # Initially only true for scripts.
39
39
  #
40
40
  def multiline_value?
41
- return true
41
+ return false
42
42
  end
43
43
 
44
44
  #
@@ -122,7 +122,7 @@ module Gloo
122
122
  uri = uri_value
123
123
  return unless uri
124
124
 
125
- Gloo::Objs::HttpPost.post_json uri, body_as_json, true
125
+ Gloo::Objs::HttpPost.post_json uri, body_as_json
126
126
  end
127
127
 
128
128
  end
@@ -109,7 +109,7 @@ module Gloo
109
109
  uri = uri_value
110
110
  return unless uri
111
111
 
112
- Gloo::Objs::HttpPost.post_json uri, body_as_json, true
112
+ Gloo::Objs::HttpPost.post_json uri, body_as_json
113
113
  end
114
114
 
115
115
  end
@@ -4,6 +4,8 @@
4
4
  # A URI (URL).
5
5
  #
6
6
  require 'uri'
7
+ require 'net/http'
8
+ require 'openssl'
7
9
 
8
10
  module Gloo
9
11
  module Objs
@@ -51,10 +53,25 @@ module Gloo
51
53
  def self.messages
52
54
  basic = %w[open]
53
55
  gets = %w[get_scheme get_host get_path]
54
- more = %w[get_query get_fragment]
56
+ more = %w[get_query get_fragment get_cert_expires]
55
57
  return super + basic + gets + more
56
58
  end
57
59
 
60
+ #
61
+ # Get the expiration date for the certificate.
62
+ #
63
+ def msg_get_cert_expires
64
+ return unless value
65
+ o = value
66
+ uri = URI( value )
67
+ response = Net::HTTP.start( uri.host, uri.port, :use_ssl => true )
68
+ cert = response.peer_cert
69
+ o = cert.not_after
70
+
71
+ $engine.heap.it.set_to o
72
+ return o
73
+ end
74
+
58
75
  #
59
76
  # Get the URI fragment that comes after the '#'
60
77
  # in the URL. Might be used to scroll down in the page.
@@ -36,6 +36,8 @@ module Gloo
36
36
  $log.error "File '#{@pn}' does not exist."
37
37
  return
38
38
  end
39
+
40
+ $log.debug "Loading file '#{@pn}'"
39
41
  @tabs = 0
40
42
  @parent_stack = []
41
43
  @parent = $engine.heap.root
@@ -0,0 +1,21 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # Formatting utilities
5
+ #
6
+
7
+ module Gloo
8
+ module Utils
9
+ class Format
10
+
11
+ #
12
+ # Format number, adding comma separators.
13
+ # Ex: 1000 -> 1,000
14
+ #
15
+ def self.number( num )
16
+ return num.to_s.reverse.scan( /.{1,3}/ ).join( ',' ).reverse
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,205 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # Utilities related to words (strings).
5
+ #
6
+
7
+ module Gloo
8
+ module Utils
9
+ class Stats
10
+
11
+ DIR_NOT_FOUND_ERR = 'The folder was not found!'.freeze
12
+
13
+ # ---------------------------------------------------------------------
14
+ # Setup
15
+ # ---------------------------------------------------------------------
16
+
17
+ #
18
+ # Create a stats utility class for the given directory.
19
+ #
20
+ def initialize( dir, types, skip = [] )
21
+ @dir = dir
22
+ setup_loc types
23
+ @skip = skip
24
+ end
25
+
26
+ # ---------------------------------------------------------------------
27
+ # Public Functions
28
+ # ---------------------------------------------------------------------
29
+
30
+ #
31
+ # Is the stats utility valid?
32
+ # Does it have a valid root directory.
33
+ #
34
+ def valid?
35
+ return true if @dir && File.directory?( @dir )
36
+
37
+ $engine.err DIR_NOT_FOUND_ERR
38
+ $engine.heap.it.set_to false
39
+
40
+ return false
41
+ end
42
+
43
+ #
44
+ # Show all stat data for the project.
45
+ #
46
+ def show_all
47
+ return unless valid?
48
+
49
+ generate
50
+ puts "Showing All stats for #{@dir}".white
51
+ puts "\n ** #{@dir_cnt} Total Folders ** "
52
+ puts " ** #{@file_cnt} Total Files ** "
53
+
54
+ busy_folders( 7 )
55
+ file_types
56
+ loc
57
+ end
58
+
59
+ #
60
+ # Get a list of the busiest folders.
61
+ # Count is how many results we want.
62
+ #
63
+ def busy_folders( count = 17 )
64
+ return unless valid?
65
+
66
+ generate
67
+ puts "\nBusy Folders:".yellow
68
+
69
+ @folders.sort! { |a, b| a[ :cnt ] <=> b[ :cnt ] }
70
+ @folders.reverse!
71
+ @folders[ 0..count ].each do |f|
72
+ puts " #{f[ :cnt ]} - #{f[ :name ]}"
73
+ end
74
+ end
75
+
76
+ #
77
+ # Show file types and how many of each there are.
78
+ #
79
+ def file_types
80
+ return unless valid?
81
+
82
+ generate
83
+ puts "\nFiles by Type:".yellow
84
+
85
+ @types = @types.sort_by( &:last )
86
+ @types.reverse!
87
+ @types.each do |o|
88
+ puts " #{o[ 1 ]} - #{o[ 0 ]}" unless o[ 0 ].empty?
89
+ end
90
+ end
91
+
92
+ #
93
+ # Show Lines of Code
94
+ #
95
+ def loc
96
+ return unless valid?
97
+
98
+ generate
99
+ total = 0
100
+
101
+ @loc.each do |k, v|
102
+ puts "\n #{k} Lines of Code".yellow
103
+ total += v[ :lines ]
104
+ formatted = Gloo::Utils::Format.number( v[ :lines ] )
105
+ puts " ** #{formatted} in #{v[ :files ].count} #{k} files ** "
106
+
107
+ puts "\n Busy #{k} files:".yellow
108
+ files = v[ :files ].sort! { |a, b| a[ :lines ] <=> b[ :lines ] }
109
+ files.reverse!
110
+ files[ 0..12 ].each do |f|
111
+ puts " #{f[ :lines ]} - #{f[ :file ]}"
112
+ end
113
+ end
114
+
115
+ formatted = Gloo::Utils::Format.number( total )
116
+ puts "\n #{formatted} Total Lines of Code".white
117
+ end
118
+
119
+ # ---------------------------------------------------------------------
120
+ # Private Functions
121
+ # ---------------------------------------------------------------------
122
+
123
+ #
124
+ # Setup counters for lines of code by file type.
125
+ def setup_loc( types )
126
+ @loc = {}
127
+
128
+ types.split( ' ' ).each do |t|
129
+ @loc[ t ] = { lines: 0, files: [] }
130
+ end
131
+ end
132
+
133
+ #
134
+ # Generate stat data unless we've already done so.
135
+ #
136
+ def generate
137
+ return if @folders
138
+
139
+ $log.debug 'Generating...'
140
+ @folders = []
141
+ @types = {}
142
+ @file_cnt = 0
143
+ @dir_cnt = 0
144
+
145
+ generate_for Pathname.new( @dir )
146
+ end
147
+
148
+ #
149
+ # Generate data for the given path.
150
+ # NOTE: this is a recursive function.
151
+ # It traverses all sub-direcctories.
152
+ #
153
+ def generate_for( path )
154
+ return if @skip.include?( File.basename( path ) )
155
+
156
+ cnt = 0
157
+ path.children.each do |f|
158
+ if f.directory?
159
+ @dir_cnt += 1
160
+ generate_for( f )
161
+ else
162
+ @file_cnt += 1
163
+ cnt += 1
164
+ handle_file( f )
165
+ inc_type( File.extname( f ) )
166
+ end
167
+ end
168
+ @folders << { name: path, cnt: cnt }
169
+ end
170
+
171
+ #
172
+ # Increment the file count.
173
+ #
174
+ def inc_type( type )
175
+ if @types[ type ]
176
+ @types[ type ] += 1
177
+ else
178
+ @types[ type ] = 1
179
+ end
180
+ end
181
+
182
+ #
183
+ # Consider code file types.
184
+ #
185
+ def handle_file( file )
186
+ ext = File.extname( file )
187
+ return unless ext
188
+
189
+ ext = ext[ 1..-1 ]
190
+ return unless @loc.key?( ext )
191
+
192
+ lines = count_lines( file )
193
+ @loc[ ext ][ :lines ] += lines
194
+ @loc[ ext ][ :files ] << { lines: lines, file: file }
195
+ end
196
+
197
+ #
198
+ # Count lines of code in file.
199
+ def count_lines( file )
200
+ return `wc -l #{file}`.split.first.to_i
201
+ end
202
+
203
+ end
204
+ end
205
+ end
data/lib/gloo.rb CHANGED
@@ -3,6 +3,8 @@
3
3
  #
4
4
  # Start the Engine.
5
5
  #
6
+ require 'gloo/core/baseo'
7
+ require 'gloo/core/obj'
6
8
 
7
9
  path = File.dirname( File.absolute_path( __FILE__ ) )
8
10
  root = File.join( path, 'gloo', '**/*.rb' )
data/lib/run.rb CHANGED
@@ -4,6 +4,9 @@
4
4
  #
5
5
  # From the /lib/ directory: ruby run.rb
6
6
  #
7
+ require 'gloo/core/baseo'
8
+ require 'gloo/core/obj'
9
+
7
10
  path = File.dirname( File.absolute_path( __FILE__ ) )
8
11
  root = File.join( path, 'gloo', '**/*.rb' )
9
12
  Dir.glob( root ) { |ruby_file| require ruby_file }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gloo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.5
4
+ version: 0.7.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Crane
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-14 00:00:00.000000000 Z
11
+ date: 2022-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -178,6 +178,66 @@ dependencies:
178
178
  - - ">="
179
179
  - !ruby/object:Gem::Version
180
180
  version: 2.1.0
181
+ - !ruby/object:Gem::Dependency
182
+ name: net-ssh
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: '6.1'
188
+ - - ">="
189
+ - !ruby/object:Gem::Version
190
+ version: 6.1.0
191
+ type: :runtime
192
+ prerelease: false
193
+ version_requirements: !ruby/object:Gem::Requirement
194
+ requirements:
195
+ - - "~>"
196
+ - !ruby/object:Gem::Version
197
+ version: '6.1'
198
+ - - ">="
199
+ - !ruby/object:Gem::Version
200
+ version: 6.1.0
201
+ - !ruby/object:Gem::Dependency
202
+ name: mysql2
203
+ requirement: !ruby/object:Gem::Requirement
204
+ requirements:
205
+ - - "~>"
206
+ - !ruby/object:Gem::Version
207
+ version: '0.5'
208
+ - - ">="
209
+ - !ruby/object:Gem::Version
210
+ version: 0.5.3
211
+ type: :runtime
212
+ prerelease: false
213
+ version_requirements: !ruby/object:Gem::Requirement
214
+ requirements:
215
+ - - "~>"
216
+ - !ruby/object:Gem::Version
217
+ version: '0.5'
218
+ - - ">="
219
+ - !ruby/object:Gem::Version
220
+ version: 0.5.3
221
+ - !ruby/object:Gem::Dependency
222
+ name: sqlite3
223
+ requirement: !ruby/object:Gem::Requirement
224
+ requirements:
225
+ - - "~>"
226
+ - !ruby/object:Gem::Version
227
+ version: '1.4'
228
+ - - ">="
229
+ - !ruby/object:Gem::Version
230
+ version: 1.4.2
231
+ type: :runtime
232
+ prerelease: false
233
+ version_requirements: !ruby/object:Gem::Requirement
234
+ requirements:
235
+ - - "~>"
236
+ - !ruby/object:Gem::Version
237
+ version: '1.4'
238
+ - - ">="
239
+ - !ruby/object:Gem::Version
240
+ version: 1.4.2
181
241
  description: A scripting languge to keep it all together.
182
242
  email:
183
243
  - eric.crane@mac.com
@@ -280,8 +340,12 @@ files:
280
340
  - lib/gloo/help/objs/ctrl/each.txt
281
341
  - lib/gloo/help/objs/ctrl/repeat.txt
282
342
  - lib/gloo/help/objs/data/markdown.txt
343
+ - lib/gloo/help/objs/data/mysql.txt
344
+ - lib/gloo/help/objs/data/query.txt
345
+ - lib/gloo/help/objs/data/sqlite.txt
283
346
  - lib/gloo/help/objs/data/table.txt
284
347
  - lib/gloo/help/objs/dev/git_repo.txt
348
+ - lib/gloo/help/objs/dev/stats.txt
285
349
  - lib/gloo/help/objs/dt/date.txt
286
350
  - lib/gloo/help/objs/dt/datetime.txt
287
351
  - lib/gloo/help/objs/dt/time.txt
@@ -290,6 +354,7 @@ files:
290
354
  - lib/gloo/help/objs/snd/play.txt
291
355
  - lib/gloo/help/objs/snd/say.txt
292
356
  - lib/gloo/help/objs/system/file.txt
357
+ - lib/gloo/help/objs/system/ssh_exec.txt
293
358
  - lib/gloo/help/objs/system/system.txt
294
359
  - lib/gloo/help/objs/web/http_get.txt
295
360
  - lib/gloo/help/objs/web/http_post.txt
@@ -338,8 +403,12 @@ files:
338
403
  - lib/gloo/objs/ctrl/each.rb
339
404
  - lib/gloo/objs/ctrl/repeat.rb
340
405
  - lib/gloo/objs/data/markdown.rb
406
+ - lib/gloo/objs/data/mysql.rb
407
+ - lib/gloo/objs/data/query.rb
408
+ - lib/gloo/objs/data/sqlite.rb
341
409
  - lib/gloo/objs/data/table.rb
342
410
  - lib/gloo/objs/dev/git.rb
411
+ - lib/gloo/objs/dev/stats.rb
343
412
  - lib/gloo/objs/dt/date.rb
344
413
  - lib/gloo/objs/dt/datetime.rb
345
414
  - lib/gloo/objs/dt/time.rb
@@ -348,6 +417,7 @@ files:
348
417
  - lib/gloo/objs/snd/play.rb
349
418
  - lib/gloo/objs/snd/say.rb
350
419
  - lib/gloo/objs/system/file_handle.rb
420
+ - lib/gloo/objs/system/ssh_exec.rb
351
421
  - lib/gloo/objs/system/system.rb
352
422
  - lib/gloo/objs/web/http_get.rb
353
423
  - lib/gloo/objs/web/http_post.rb
@@ -360,6 +430,8 @@ files:
360
430
  - lib/gloo/persist/file_storage.rb
361
431
  - lib/gloo/persist/line_splitter.rb
362
432
  - lib/gloo/persist/persist_man.rb
433
+ - lib/gloo/utils/format.rb
434
+ - lib/gloo/utils/stats.rb
363
435
  - lib/gloo/utils/words.rb
364
436
  - lib/gloo/verbs/alert.rb
365
437
  - lib/gloo/verbs/beep.rb
@@ -386,7 +458,7 @@ homepage: http://github.com/ecrane/gloo
386
458
  licenses:
387
459
  - MIT
388
460
  metadata: {}
389
- post_install_message:
461
+ post_install_message:
390
462
  rdoc_options: []
391
463
  require_paths:
392
464
  - lib
@@ -401,9 +473,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
401
473
  - !ruby/object:Gem::Version
402
474
  version: '0'
403
475
  requirements: []
404
- rubyforge_project:
405
- rubygems_version: 2.7.7
406
- signing_key:
476
+ rubygems_version: 3.2.22
477
+ signing_key:
407
478
  specification_version: 4
408
479
  summary: Gloo scripting language. A scripting language built on ruby.
409
480
  test_files: []