gloo 1.4.2 → 2.0.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.
- checksums.yaml +4 -4
- data/.DS_Store +0 -0
- data/.gitignore +1 -0
- data/gloo.gemspec +0 -2
- data/lib/VERSION +1 -1
- data/lib/dependencies.rb +4 -4
- data/lib/gloo/app/args.rb +112 -0
- data/lib/gloo/app/engine.rb +247 -0
- data/lib/gloo/app/engine_context.rb +25 -0
- data/lib/gloo/app/info.rb +20 -3
- data/lib/gloo/app/log.rb +73 -1
- data/lib/gloo/app/mode.rb +27 -0
- data/lib/gloo/app/platform.rb +8 -1
- data/lib/gloo/app/settings.rb +202 -0
- data/lib/gloo/convert/converter.rb +42 -0
- data/lib/gloo/convert/string_to_date.rb +21 -0
- data/lib/gloo/convert/string_to_datetime.rb +21 -0
- data/lib/gloo/convert/string_to_decimal.rb +20 -0
- data/lib/gloo/convert/string_to_integer.rb +20 -0
- data/lib/gloo/convert/string_to_time.rb +21 -0
- data/lib/gloo/core/baseo.rb +31 -0
- data/lib/gloo/core/dictionary.rb +245 -0
- data/lib/gloo/core/error.rb +61 -0
- data/lib/gloo/core/event_manager.rb +45 -0
- data/lib/gloo/core/factory.rb +211 -0
- data/lib/gloo/core/gloo_system.rb +267 -0
- data/lib/gloo/core/heap.rb +53 -0
- data/lib/gloo/core/here.rb +36 -0
- data/lib/gloo/core/it.rb +36 -0
- data/lib/gloo/core/literal.rb +30 -0
- data/lib/gloo/core/obj.rb +318 -0
- data/lib/gloo/core/obj_finder.rb +30 -0
- data/lib/gloo/core/op.rb +40 -0
- data/lib/gloo/core/parser.rb +60 -0
- data/lib/gloo/core/pn.rb +212 -0
- data/lib/gloo/core/tokens.rb +165 -0
- data/lib/gloo/core/verb.rb +87 -0
- data/lib/gloo/exec/action.rb +48 -0
- data/lib/gloo/exec/dispatch.rb +40 -0
- data/lib/gloo/exec/exec_env.rb +75 -0
- data/lib/gloo/exec/runner.rb +45 -0
- data/lib/gloo/exec/script.rb +50 -0
- data/lib/gloo/exec/stack.rb +79 -0
- data/lib/gloo/expr/expression.rb +119 -0
- data/lib/gloo/expr/l_boolean.rb +36 -0
- data/lib/gloo/expr/l_decimal.rb +39 -0
- data/lib/gloo/expr/l_integer.rb +37 -0
- data/lib/gloo/expr/l_string.rb +58 -0
- data/lib/gloo/expr/op_div.rb +22 -0
- data/lib/gloo/expr/op_minus.rb +22 -0
- data/lib/gloo/expr/op_mult.rb +22 -0
- data/lib/gloo/expr/op_plus.rb +24 -0
- data/lib/gloo/objs/basic/alias.rb +78 -0
- data/lib/gloo/objs/basic/boolean.rb +120 -0
- data/lib/gloo/objs/basic/container.rb +65 -0
- data/lib/gloo/objs/basic/decimal.rb +76 -0
- data/lib/gloo/objs/basic/integer.rb +73 -0
- data/lib/gloo/objs/basic/script.rb +99 -0
- data/lib/gloo/objs/basic/string.rb +77 -0
- data/lib/gloo/objs/basic/text.rb +79 -0
- data/lib/gloo/objs/basic/untyped.rb +41 -0
- data/lib/gloo/objs/cli/banner.rb +1 -1
- data/lib/gloo/objs/cli/bar.rb +3 -3
- data/lib/gloo/objs/cli/colorize.rb +1 -1
- data/lib/gloo/objs/cli/confirm.rb +1 -1
- data/lib/gloo/objs/cli/menu.rb +6 -6
- data/lib/gloo/objs/cli/menu_item.rb +1 -1
- data/lib/gloo/objs/cli/pastel.rb +1 -1
- data/lib/gloo/objs/cli/prompt.rb +1 -1
- data/lib/gloo/objs/cli/select.rb +2 -2
- data/lib/gloo/objs/ctrl/each.rb +279 -0
- data/lib/gloo/objs/ctrl/repeat.rb +108 -0
- data/lib/gloo/objs/data/markdown.rb +79 -0
- data/lib/gloo/objs/data/mysql.rb +5 -5
- data/lib/gloo/objs/data/query.rb +4 -4
- data/lib/gloo/objs/data/sqlite.rb +1 -1
- data/lib/gloo/objs/data/table.rb +112 -0
- data/lib/gloo/objs/dev/git.rb +2 -2
- data/lib/gloo/objs/dev/stats.rb +4 -4
- data/lib/gloo/objs/dt/date.rb +65 -0
- data/lib/gloo/objs/dt/datetime.rb +120 -0
- data/lib/gloo/objs/dt/dt_tools.rb +100 -0
- data/lib/gloo/objs/dt/time.rb +65 -0
- data/lib/gloo/objs/ror/erb.rb +116 -0
- data/lib/gloo/objs/ror/eval.rb +107 -0
- data/lib/gloo/objs/snd/play.rb +1 -1
- data/lib/gloo/objs/snd/say.rb +1 -1
- data/lib/gloo/objs/system/file_handle.rb +4 -4
- data/lib/gloo/objs/system/ssh_exec.rb +1 -1
- data/lib/gloo/objs/system/system.rb +1 -1
- data/lib/gloo/objs/web/http_get.rb +159 -0
- data/lib/gloo/objs/web/http_post.rb +183 -0
- data/lib/gloo/objs/web/json.rb +135 -0
- data/lib/gloo/objs/web/slack.rb +130 -0
- data/lib/gloo/objs/web/teams.rb +117 -0
- data/lib/gloo/objs/web/uri.rb +148 -0
- data/lib/gloo/persist/disc_mech.rb +87 -0
- data/lib/gloo/persist/file_loader.rb +193 -0
- data/lib/gloo/persist/file_saver.rb +51 -0
- data/lib/gloo/persist/file_storage.rb +46 -0
- data/lib/gloo/persist/line_splitter.rb +81 -0
- data/lib/gloo/persist/persist_man.rb +153 -0
- data/lib/gloo/utils/format.rb +21 -0
- data/lib/gloo/utils/stats.rb +206 -0
- data/lib/gloo/utils/words.rb +19 -0
- data/lib/gloo/verbs/alert.rb +2 -2
- data/lib/gloo/verbs/beep.rb +1 -1
- data/lib/gloo/verbs/cls.rb +1 -1
- data/lib/gloo/verbs/context.rb +62 -0
- data/lib/gloo/verbs/create.rb +68 -0
- data/lib/gloo/verbs/execute.rb +56 -0
- data/lib/gloo/verbs/files.rb +49 -0
- data/lib/gloo/verbs/help.rb +1 -1
- data/lib/gloo/verbs/if.rb +92 -0
- data/lib/gloo/verbs/list.rb +98 -0
- data/lib/gloo/verbs/load.rb +45 -0
- data/lib/gloo/verbs/move.rb +89 -0
- data/lib/gloo/verbs/put.rb +94 -0
- data/lib/gloo/verbs/quit.rb +40 -0
- data/lib/gloo/verbs/reload.rb +43 -0
- data/lib/gloo/verbs/run.rb +75 -0
- data/lib/gloo/verbs/save.rb +39 -0
- data/lib/gloo/verbs/show.rb +63 -0
- data/lib/gloo/verbs/tell.rb +80 -0
- data/lib/gloo/verbs/unless.rb +92 -0
- data/lib/gloo/verbs/unload.rb +46 -0
- data/lib/gloo/verbs/version.rb +3 -3
- data/lib/gloo/verbs/wait.rb +42 -0
- data/lib/gloo.rb +2 -2
- data/lib/run.rb +2 -2
- metadata +97 -22
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
|
2
|
+
# Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# An object that can post JSON to a URI.
|
|
5
|
+
#
|
|
6
|
+
require 'net/http'
|
|
7
|
+
require 'uri'
|
|
8
|
+
require 'json'
|
|
9
|
+
require 'openssl'
|
|
10
|
+
|
|
11
|
+
module Gloo
|
|
12
|
+
module Objs
|
|
13
|
+
class HttpGet < Gloo::Core::Obj
|
|
14
|
+
|
|
15
|
+
KEYWORD = 'http_get'.freeze
|
|
16
|
+
KEYWORD_SHORT = 'get'.freeze
|
|
17
|
+
URL = 'uri'.freeze
|
|
18
|
+
DEFAULT_URL = 'https://web.site/'.freeze
|
|
19
|
+
PARAMS = 'params'.freeze
|
|
20
|
+
RESULT = 'result'.freeze
|
|
21
|
+
SKIP_SSL_VERIFY = 'skip_ssl_verify'.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
|
+
# Children
|
|
39
|
+
# ---------------------------------------------------------------------
|
|
40
|
+
|
|
41
|
+
#
|
|
42
|
+
# Does this object have children to add when an object
|
|
43
|
+
# is created in interactive mode?
|
|
44
|
+
# This does not apply during obj load, etc.
|
|
45
|
+
#
|
|
46
|
+
def add_children_on_create?
|
|
47
|
+
return true
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
#
|
|
51
|
+
# Add children to this object.
|
|
52
|
+
# This is used by containers to add children needed
|
|
53
|
+
# for default configurations.
|
|
54
|
+
#
|
|
55
|
+
def add_default_children
|
|
56
|
+
fac = @engine.factory
|
|
57
|
+
fac.create_string URL, DEFAULT_URL, self
|
|
58
|
+
fac.create_can PARAMS, self
|
|
59
|
+
fac.create_string RESULT, nil, self
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# ---------------------------------------------------------------------
|
|
63
|
+
# Messages
|
|
64
|
+
# ---------------------------------------------------------------------
|
|
65
|
+
|
|
66
|
+
#
|
|
67
|
+
# Get a list of message names that this object receives.
|
|
68
|
+
#
|
|
69
|
+
def self.messages
|
|
70
|
+
return super + [ 'run' ]
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
#
|
|
74
|
+
# Post the content to the endpoint.
|
|
75
|
+
#
|
|
76
|
+
def msg_run
|
|
77
|
+
url = full_url_value
|
|
78
|
+
@engine.log.debug url
|
|
79
|
+
r = Gloo::Objs::HttpGet.invoke_request( url, skip_ssl_verify? )
|
|
80
|
+
update_result r
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# ---------------------------------------------------------------------
|
|
84
|
+
# Static functions
|
|
85
|
+
# ---------------------------------------------------------------------
|
|
86
|
+
|
|
87
|
+
#
|
|
88
|
+
# Post the content to the endpoint.
|
|
89
|
+
#
|
|
90
|
+
def self.invoke_request( url, skip_ssl_verify = false )
|
|
91
|
+
uri = URI( url )
|
|
92
|
+
params = { use_ssl: uri.scheme == 'https' }
|
|
93
|
+
|
|
94
|
+
params[ :verify_mode ] = ::OpenSSL::SSL::VERIFY_NONE if skip_ssl_verify
|
|
95
|
+
|
|
96
|
+
Net::HTTP.start( uri.host, uri.port, params ) do |http|
|
|
97
|
+
request = Net::HTTP::Get.new uri
|
|
98
|
+
response = http.request request # Net::HTTPResponse object
|
|
99
|
+
return response.body
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# ---------------------------------------------------------------------
|
|
104
|
+
# Private functions
|
|
105
|
+
# ---------------------------------------------------------------------
|
|
106
|
+
|
|
107
|
+
private
|
|
108
|
+
|
|
109
|
+
#
|
|
110
|
+
# Get the URI from the child object.
|
|
111
|
+
# Returns nil if there is none.
|
|
112
|
+
#
|
|
113
|
+
def uri_value
|
|
114
|
+
uri = find_child URL
|
|
115
|
+
return nil unless uri
|
|
116
|
+
|
|
117
|
+
return uri.value
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
#
|
|
121
|
+
# Should we skip SSL verification during the request?
|
|
122
|
+
#
|
|
123
|
+
def skip_ssl_verify?
|
|
124
|
+
skip = find_child SKIP_SSL_VERIFY
|
|
125
|
+
return false unless skip
|
|
126
|
+
|
|
127
|
+
return skip.value
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
#
|
|
131
|
+
# Set the result of the API call.
|
|
132
|
+
#
|
|
133
|
+
def update_result( data )
|
|
134
|
+
r = find_child RESULT
|
|
135
|
+
return nil unless r
|
|
136
|
+
|
|
137
|
+
r.set_value data
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
#
|
|
141
|
+
# Get the URL for the service including all URL params.
|
|
142
|
+
#
|
|
143
|
+
def full_url_value
|
|
144
|
+
p = ''
|
|
145
|
+
params = find_child PARAMS
|
|
146
|
+
params.children.each do |child|
|
|
147
|
+
p << ( p.empty? ? '?' : '&' )
|
|
148
|
+
|
|
149
|
+
child = Gloo::Objs::Alias.resolve_alias( @engine, child )
|
|
150
|
+
|
|
151
|
+
# TODO: Quote URL params for safety
|
|
152
|
+
p << "#{child.name}=#{child.value}"
|
|
153
|
+
end
|
|
154
|
+
return "#{uri_value}#{p}"
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
end
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
|
2
|
+
# Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# An object that can post JSON to a URI.
|
|
5
|
+
#
|
|
6
|
+
require 'net/http'
|
|
7
|
+
require 'uri'
|
|
8
|
+
require 'json'
|
|
9
|
+
|
|
10
|
+
module Gloo
|
|
11
|
+
module Objs
|
|
12
|
+
class HttpPost < Gloo::Core::Obj
|
|
13
|
+
|
|
14
|
+
KEYWORD = 'http_post'.freeze
|
|
15
|
+
KEYWORD_SHORT = 'post'.freeze
|
|
16
|
+
URL = 'uri'.freeze
|
|
17
|
+
BODY = 'body'.freeze
|
|
18
|
+
RESULT = 'result'.freeze
|
|
19
|
+
SKIP_SSL_VERIFY = 'skip_ssl_verify'.freeze
|
|
20
|
+
|
|
21
|
+
#
|
|
22
|
+
# The name of the object type.
|
|
23
|
+
#
|
|
24
|
+
def self.typename
|
|
25
|
+
return KEYWORD
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
#
|
|
29
|
+
# The short name of the object type.
|
|
30
|
+
#
|
|
31
|
+
def self.short_typename
|
|
32
|
+
return KEYWORD_SHORT
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
#
|
|
36
|
+
# Get the URI from the child object.
|
|
37
|
+
# Returns nil if there is none.
|
|
38
|
+
#
|
|
39
|
+
def uri_value
|
|
40
|
+
uri = find_child URL
|
|
41
|
+
return nil unless uri
|
|
42
|
+
|
|
43
|
+
return uri.value
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
#
|
|
47
|
+
# Get all the children of the body container and
|
|
48
|
+
# convert to JSON that will be sent in the HTTP body.
|
|
49
|
+
#
|
|
50
|
+
def body_as_json
|
|
51
|
+
h = {}
|
|
52
|
+
|
|
53
|
+
body = find_child BODY
|
|
54
|
+
body.children.each do |child|
|
|
55
|
+
child_val = Gloo::Objs::Alias.resolve_alias( @engine, child )
|
|
56
|
+
h[ child.name ] = child_val.value
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
return h.to_json
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
#
|
|
63
|
+
# Set the result of the API call.
|
|
64
|
+
#
|
|
65
|
+
def update_result( data )
|
|
66
|
+
r = find_child RESULT
|
|
67
|
+
return nil unless r
|
|
68
|
+
|
|
69
|
+
r.set_value data
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# ---------------------------------------------------------------------
|
|
73
|
+
# Children
|
|
74
|
+
# ---------------------------------------------------------------------
|
|
75
|
+
|
|
76
|
+
#
|
|
77
|
+
# Does this object have children to add when an object
|
|
78
|
+
# is created in interactive mode?
|
|
79
|
+
# This does not apply during obj load, etc.
|
|
80
|
+
#
|
|
81
|
+
def add_children_on_create?
|
|
82
|
+
return true
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
#
|
|
86
|
+
# Add children to this object.
|
|
87
|
+
# This is used by containers to add children needed
|
|
88
|
+
# for default configurations.
|
|
89
|
+
#
|
|
90
|
+
def add_default_children
|
|
91
|
+
fac = @engine.factory
|
|
92
|
+
fac.create_string URL, 'https://web.site/', self
|
|
93
|
+
fac.create_can BODY, self
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# ---------------------------------------------------------------------
|
|
97
|
+
# Messages
|
|
98
|
+
# ---------------------------------------------------------------------
|
|
99
|
+
|
|
100
|
+
#
|
|
101
|
+
# Get a list of message names that this object receives.
|
|
102
|
+
#
|
|
103
|
+
def self.messages
|
|
104
|
+
return super + [ 'run' ]
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
#
|
|
108
|
+
# Post the content to the endpoint.
|
|
109
|
+
#
|
|
110
|
+
def msg_run
|
|
111
|
+
uri = uri_value
|
|
112
|
+
return unless uri
|
|
113
|
+
|
|
114
|
+
@engine.log.debug "posting to: #{uri}"
|
|
115
|
+
body = self.body_as_json
|
|
116
|
+
@engine.log.debug "posting body: #{body}"
|
|
117
|
+
result = Gloo::Objs::HttpPost.post_json( uri, body, skip_ssl_verify? )
|
|
118
|
+
@engine.log.debug result.code
|
|
119
|
+
@engine.log.debug result.message
|
|
120
|
+
|
|
121
|
+
self.update_result result.body
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# ---------------------------------------------------------------------
|
|
125
|
+
# Static functions
|
|
126
|
+
# ---------------------------------------------------------------------
|
|
127
|
+
|
|
128
|
+
#
|
|
129
|
+
# Post the content to the endpoint.
|
|
130
|
+
#
|
|
131
|
+
def self.post_json( url, body, skip_ssl_verify = false )
|
|
132
|
+
uri = URI( url )
|
|
133
|
+
params = { use_ssl: uri.scheme == 'https' }
|
|
134
|
+
params[ :verify_mode ] = ::OpenSSL::SSL::VERIFY_NONE if skip_ssl_verify
|
|
135
|
+
|
|
136
|
+
Net::HTTP.start( uri.host, uri.port, params ) do |http|
|
|
137
|
+
request = Net::HTTP::Post.new uri
|
|
138
|
+
request.content_type = 'application/json'
|
|
139
|
+
request.body = body
|
|
140
|
+
|
|
141
|
+
return http.request( request ) # returns Net::HTTPResponse object
|
|
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
|
+
# @engine.log.debug result.code
|
|
161
|
+
# @engine.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
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
end
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
|
2
|
+
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# JSON data.
|
|
5
|
+
#
|
|
6
|
+
require 'json'
|
|
7
|
+
|
|
8
|
+
module Gloo
|
|
9
|
+
module Objs
|
|
10
|
+
class Json < Gloo::Core::Obj
|
|
11
|
+
|
|
12
|
+
KEYWORD = 'json'.freeze
|
|
13
|
+
KEYWORD_SHORT = 'json'.freeze
|
|
14
|
+
|
|
15
|
+
#
|
|
16
|
+
# The name of the object type.
|
|
17
|
+
#
|
|
18
|
+
def self.typename
|
|
19
|
+
return KEYWORD
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
#
|
|
23
|
+
# The short name of the object type.
|
|
24
|
+
#
|
|
25
|
+
def self.short_typename
|
|
26
|
+
return KEYWORD_SHORT
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
#
|
|
30
|
+
# Set the value with any necessary type conversions.
|
|
31
|
+
#
|
|
32
|
+
def set_value( new_value )
|
|
33
|
+
self.value = new_value.to_s
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
#
|
|
37
|
+
# Does this object support multi-line values?
|
|
38
|
+
# Initially only true for scripts.
|
|
39
|
+
#
|
|
40
|
+
def multiline_value?
|
|
41
|
+
return false
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
#
|
|
45
|
+
# Get the number of lines of text.
|
|
46
|
+
#
|
|
47
|
+
def line_count
|
|
48
|
+
return value.split( "\n" ).count
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# ---------------------------------------------------------------------
|
|
52
|
+
# Messages
|
|
53
|
+
# ---------------------------------------------------------------------
|
|
54
|
+
|
|
55
|
+
#
|
|
56
|
+
# Get a list of message names that this object receives.
|
|
57
|
+
#
|
|
58
|
+
def self.messages
|
|
59
|
+
return super + %w[get parse pretty]
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
#
|
|
63
|
+
# Make the JSON pretty.
|
|
64
|
+
#
|
|
65
|
+
def msg_pretty
|
|
66
|
+
pretty = JSON.pretty_generate( self.value )
|
|
67
|
+
puts pretty
|
|
68
|
+
set_value pretty
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
#
|
|
72
|
+
# Get a value from the JSON data.
|
|
73
|
+
# The additional parameter is the path to the value.
|
|
74
|
+
#
|
|
75
|
+
def msg_get
|
|
76
|
+
if @params&.token_count&.positive?
|
|
77
|
+
expr = Gloo::Expr::Expression.new( @engine, @params.tokens )
|
|
78
|
+
data = expr.evaluate
|
|
79
|
+
end
|
|
80
|
+
return unless data
|
|
81
|
+
|
|
82
|
+
h = JSON.parse( self.value )
|
|
83
|
+
field = h[ data ]
|
|
84
|
+
@engine.heap.it.set_to field
|
|
85
|
+
return field
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
#
|
|
89
|
+
# Parse the JSON data and put it in objects.
|
|
90
|
+
# The additional parameter is the path to the destination
|
|
91
|
+
# for the parsed objects.
|
|
92
|
+
#
|
|
93
|
+
def msg_parse
|
|
94
|
+
if @params&.token_count&.positive?
|
|
95
|
+
pn = Gloo::Core::Pn.new( @engine, @params.tokens.first )
|
|
96
|
+
unless pn&.exists?
|
|
97
|
+
@engine.err 'Destination path for parsed objects does not exist'
|
|
98
|
+
return
|
|
99
|
+
end
|
|
100
|
+
else
|
|
101
|
+
@engine.err 'Destination path for parsed objects is required'
|
|
102
|
+
return
|
|
103
|
+
end
|
|
104
|
+
parent = pn.resolve
|
|
105
|
+
|
|
106
|
+
json = JSON.parse( self.value )
|
|
107
|
+
self.handle_json( json, parent )
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
#
|
|
111
|
+
# Handle JSON, creating objects and setting values.
|
|
112
|
+
# Note that this is a recursive function.
|
|
113
|
+
#
|
|
114
|
+
def handle_json( json, parent )
|
|
115
|
+
if json.class == Hash
|
|
116
|
+
json.each do |k, v|
|
|
117
|
+
if v.class == Array
|
|
118
|
+
o = parent.find_add_child( k, 'can' )
|
|
119
|
+
handle_json( v, o )
|
|
120
|
+
else
|
|
121
|
+
o = parent.find_add_child( k, 'untyped' )
|
|
122
|
+
o.set_value v
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
elsif json.class == Array
|
|
126
|
+
json.each_with_index do |o, index|
|
|
127
|
+
child = parent.find_add_child( index.to_s, 'can' )
|
|
128
|
+
handle_json( o, child )
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
|
2
|
+
# Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# An object that can send a message to a slack channel.
|
|
5
|
+
#
|
|
6
|
+
require 'net/http'
|
|
7
|
+
require 'uri'
|
|
8
|
+
require 'json'
|
|
9
|
+
|
|
10
|
+
module Gloo
|
|
11
|
+
module Objs
|
|
12
|
+
class Slack < Gloo::Core::Obj
|
|
13
|
+
|
|
14
|
+
KEYWORD = 'slack'.freeze
|
|
15
|
+
KEYWORD_SHORT = 'slack'.freeze
|
|
16
|
+
URL = 'uri'.freeze
|
|
17
|
+
MSG = 'message'.freeze
|
|
18
|
+
USER = 'username'.freeze
|
|
19
|
+
CHANNEL = 'channel'.freeze
|
|
20
|
+
ICON = 'icon_emoji'.freeze
|
|
21
|
+
|
|
22
|
+
ATTACHMENT = 'attachment'.freeze
|
|
23
|
+
TITLE = 'title'.freeze
|
|
24
|
+
TEXT = 'text'.freeze
|
|
25
|
+
|
|
26
|
+
#
|
|
27
|
+
# The name of the object type.
|
|
28
|
+
#
|
|
29
|
+
def self.typename
|
|
30
|
+
return KEYWORD
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
#
|
|
34
|
+
# The short name of the object type.
|
|
35
|
+
#
|
|
36
|
+
def self.short_typename
|
|
37
|
+
return KEYWORD_SHORT
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
#
|
|
41
|
+
# Get the URI from the child object.
|
|
42
|
+
# Returns nil if there is none.
|
|
43
|
+
#
|
|
44
|
+
def uri_value
|
|
45
|
+
uri = find_child URL
|
|
46
|
+
return nil unless uri
|
|
47
|
+
|
|
48
|
+
return uri.value
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
#
|
|
52
|
+
# Get the URI from the child object.
|
|
53
|
+
# Returns nil if there is none.
|
|
54
|
+
#
|
|
55
|
+
def attachment_value
|
|
56
|
+
o = find_child ATTACHMENT
|
|
57
|
+
return nil unless o
|
|
58
|
+
|
|
59
|
+
title = o.find_child TITLE
|
|
60
|
+
text = o.find_child TEXT
|
|
61
|
+
return [ { 'title' => title.value,
|
|
62
|
+
'text' => text.value } ]
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
#
|
|
66
|
+
# Get all the children of the body container and
|
|
67
|
+
# convert to JSON that will be sent in the HTTP body.
|
|
68
|
+
#
|
|
69
|
+
def body_as_json
|
|
70
|
+
h = { 'text' => find_child( MSG ).value,
|
|
71
|
+
'username' => find_child( USER ).value,
|
|
72
|
+
'channel' => find_child( CHANNEL ).value,
|
|
73
|
+
'icon_emoji' => find_child( ICON ).value }
|
|
74
|
+
|
|
75
|
+
o = attachment_value
|
|
76
|
+
h[ 'attachments' ] = o if o
|
|
77
|
+
return h.to_json
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# ---------------------------------------------------------------------
|
|
81
|
+
# Children
|
|
82
|
+
# ---------------------------------------------------------------------
|
|
83
|
+
|
|
84
|
+
#
|
|
85
|
+
# Does this object have children to add when an object
|
|
86
|
+
# is created in interactive mode?
|
|
87
|
+
# This does not apply during obj load, etc.
|
|
88
|
+
#
|
|
89
|
+
def add_children_on_create?
|
|
90
|
+
return true
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
#
|
|
94
|
+
# Add children to this object.
|
|
95
|
+
# This is used by containers to add children needed
|
|
96
|
+
# for default configurations.
|
|
97
|
+
#
|
|
98
|
+
def add_default_children
|
|
99
|
+
fac = @engine.factory
|
|
100
|
+
fac.create_string URL, 'https://hooks.slack.com/services/...', self
|
|
101
|
+
fac.create_string MSG, 'textual message', self
|
|
102
|
+
fac.create_string USER, 'Slack Bot', self
|
|
103
|
+
fac.create_string CHANNEL, 'general', self
|
|
104
|
+
fac.create_string ICON, ':ghost:', self
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# ---------------------------------------------------------------------
|
|
108
|
+
# Messages
|
|
109
|
+
# ---------------------------------------------------------------------
|
|
110
|
+
|
|
111
|
+
#
|
|
112
|
+
# Get a list of message names that this object receives.
|
|
113
|
+
#
|
|
114
|
+
def self.messages
|
|
115
|
+
return super + [ 'run' ]
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
#
|
|
119
|
+
# Post the content to the Slack channel.
|
|
120
|
+
#
|
|
121
|
+
def msg_run
|
|
122
|
+
uri = uri_value
|
|
123
|
+
return unless uri
|
|
124
|
+
|
|
125
|
+
Gloo::Objs::HttpPost.post_json uri, body_as_json
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
|
2
|
+
# Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# An object that can send a message to a Teams webhook.
|
|
5
|
+
#
|
|
6
|
+
require 'net/http'
|
|
7
|
+
require 'uri'
|
|
8
|
+
require 'json'
|
|
9
|
+
|
|
10
|
+
module Gloo
|
|
11
|
+
module Objs
|
|
12
|
+
class Teams < Gloo::Core::Obj
|
|
13
|
+
|
|
14
|
+
KEYWORD = 'teams'.freeze
|
|
15
|
+
KEYWORD_SHORT = 'team'.freeze
|
|
16
|
+
URL = 'uri'.freeze
|
|
17
|
+
DEFAULT_URL = 'https://outlook.office.com/webhook/...'.freeze
|
|
18
|
+
MSG = 'message'.freeze
|
|
19
|
+
TITLE = 'title'.freeze
|
|
20
|
+
COLOR = 'color'.freeze
|
|
21
|
+
DEFAULT_COLOR = '008000'.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 URI from the child object.
|
|
39
|
+
# Returns nil if there is none.
|
|
40
|
+
#
|
|
41
|
+
def uri_value
|
|
42
|
+
uri = find_child URL
|
|
43
|
+
return nil unless uri
|
|
44
|
+
|
|
45
|
+
return uri.value
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Get the color value.
|
|
49
|
+
def color_value
|
|
50
|
+
c = find_child COLOR
|
|
51
|
+
return nil unless c
|
|
52
|
+
|
|
53
|
+
return c.value
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
#
|
|
57
|
+
# Get all the children of the body container and
|
|
58
|
+
# convert to JSON that will be sent in the HTTP body.
|
|
59
|
+
#
|
|
60
|
+
def body_as_json
|
|
61
|
+
h = { 'title' => find_child( TITLE ).value,
|
|
62
|
+
'text' => find_child( MSG ).value }
|
|
63
|
+
color = color_value
|
|
64
|
+
h[ 'themeColor' ] = color if color
|
|
65
|
+
return h.to_json
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# ---------------------------------------------------------------------
|
|
69
|
+
# Children
|
|
70
|
+
# ---------------------------------------------------------------------
|
|
71
|
+
|
|
72
|
+
#
|
|
73
|
+
# Does this object have children to add when an object
|
|
74
|
+
# is created in interactive mode?
|
|
75
|
+
# This does not apply during obj load, etc.
|
|
76
|
+
#
|
|
77
|
+
def add_children_on_create?
|
|
78
|
+
return true
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
#
|
|
82
|
+
# Add children to this object.
|
|
83
|
+
# This is used by containers to add children needed
|
|
84
|
+
# for default configurations.
|
|
85
|
+
#
|
|
86
|
+
def add_default_children
|
|
87
|
+
fac = @engine.factory
|
|
88
|
+
fac.create_string URL, DEFAULT_URL, self
|
|
89
|
+
fac.create_string TITLE, '', self
|
|
90
|
+
fac.create_string COLOR, DEFAULT_COLOR, self
|
|
91
|
+
fac.create_string MSG, '', self
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# ---------------------------------------------------------------------
|
|
95
|
+
# Messages
|
|
96
|
+
# ---------------------------------------------------------------------
|
|
97
|
+
|
|
98
|
+
#
|
|
99
|
+
# Get a list of message names that this object receives.
|
|
100
|
+
#
|
|
101
|
+
def self.messages
|
|
102
|
+
return super + [ 'run' ]
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
#
|
|
106
|
+
# Post the content to Microsoft Teams.
|
|
107
|
+
#
|
|
108
|
+
def msg_run
|
|
109
|
+
uri = uri_value
|
|
110
|
+
return unless uri
|
|
111
|
+
|
|
112
|
+
Gloo::Objs::HttpPost.post_json uri, body_as_json
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|