gloo 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +139 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +12 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/gloo +4 -0
- data/exe/o +4 -0
- data/gloo.gemspec +38 -0
- data/lib/gloo.rb +19 -0
- data/lib/gloo/app/args.rb +71 -0
- data/lib/gloo/app/engine.rb +158 -0
- data/lib/gloo/app/help.rb +29 -0
- data/lib/gloo/app/info.rb +21 -0
- data/lib/gloo/app/log.rb +58 -0
- data/lib/gloo/app/mode.rb +25 -0
- data/lib/gloo/app/settings.rb +125 -0
- data/lib/gloo/core/baseo.rb +28 -0
- data/lib/gloo/core/dictionary.rb +101 -0
- data/lib/gloo/core/event_manager.rb +46 -0
- data/lib/gloo/core/factory.rb +67 -0
- data/lib/gloo/core/gloo_system.rb +190 -0
- data/lib/gloo/core/heap.rb +42 -0
- data/lib/gloo/core/it.rb +30 -0
- data/lib/gloo/core/literal.rb +25 -0
- data/lib/gloo/core/obj.rb +222 -0
- data/lib/gloo/core/obj_finder.rb +35 -0
- data/lib/gloo/core/op.rb +33 -0
- data/lib/gloo/core/parser.rb +52 -0
- data/lib/gloo/core/pn.rb +134 -0
- data/lib/gloo/core/script.rb +37 -0
- data/lib/gloo/core/tokens.rb +123 -0
- data/lib/gloo/core/verb.rb +63 -0
- data/lib/gloo/expr/expression.rb +103 -0
- data/lib/gloo/expr/l_boolean.rb +29 -0
- data/lib/gloo/expr/l_integer.rb +29 -0
- data/lib/gloo/expr/l_string.rb +53 -0
- data/lib/gloo/expr/op_div.rb +20 -0
- data/lib/gloo/expr/op_minus.rb +20 -0
- data/lib/gloo/expr/op_mult.rb +20 -0
- data/lib/gloo/expr/op_plus.rb +22 -0
- data/lib/gloo/objs/basic/boolean.rb +113 -0
- data/lib/gloo/objs/basic/container.rb +50 -0
- data/lib/gloo/objs/basic/integer.rb +65 -0
- data/lib/gloo/objs/basic/script.rb +101 -0
- data/lib/gloo/objs/basic/string.rb +65 -0
- data/lib/gloo/objs/basic/text.rb +64 -0
- data/lib/gloo/objs/basic/untyped.rb +42 -0
- data/lib/gloo/objs/cli/colorize.rb +73 -0
- data/lib/gloo/objs/cli/confirm.rb +92 -0
- data/lib/gloo/objs/cli/prompt.rb +92 -0
- data/lib/gloo/objs/ctrl/each.rb +212 -0
- data/lib/gloo/objs/dev/git.rb +112 -0
- data/lib/gloo/objs/ror/erb.rb +109 -0
- data/lib/gloo/objs/ror/eval.rb +92 -0
- data/lib/gloo/objs/system/file_handle.rb +86 -0
- data/lib/gloo/objs/system/system.rb +120 -0
- data/lib/gloo/objs/web/http_get.rb +128 -0
- data/lib/gloo/objs/web/http_post.rb +127 -0
- data/lib/gloo/objs/web/slack.rb +126 -0
- data/lib/gloo/objs/web/teams.rb +117 -0
- data/lib/gloo/persist/file_loader.rb +171 -0
- data/lib/gloo/persist/file_saver.rb +43 -0
- data/lib/gloo/persist/file_storage.rb +43 -0
- data/lib/gloo/persist/persist_man.rb +90 -0
- data/lib/gloo/utils/words.rb +19 -0
- data/lib/gloo/verbs/alert.rb +42 -0
- data/lib/gloo/verbs/context.rb +52 -0
- data/lib/gloo/verbs/create.rb +52 -0
- data/lib/gloo/verbs/help.rb +69 -0
- data/lib/gloo/verbs/if.rb +56 -0
- data/lib/gloo/verbs/list.rb +85 -0
- data/lib/gloo/verbs/load.rb +39 -0
- data/lib/gloo/verbs/put.rb +62 -0
- data/lib/gloo/verbs/quit.rb +40 -0
- data/lib/gloo/verbs/run.rb +46 -0
- data/lib/gloo/verbs/save.rb +37 -0
- data/lib/gloo/verbs/show.rb +55 -0
- data/lib/gloo/verbs/tell.rb +47 -0
- data/lib/gloo/verbs/unless.rb +56 -0
- data/lib/gloo/verbs/version.rb +37 -0
- data/lib/run.rb +13 -0
- metadata +254 -0
@@ -0,0 +1,128 @@
|
|
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 HttpGet < Gloo::Core::Obj
|
13
|
+
|
14
|
+
KEYWORD = 'http_get'
|
15
|
+
KEYWORD_SHORT = 'get'
|
16
|
+
URL = 'uri'
|
17
|
+
PARAMS = 'params'
|
18
|
+
RESULT = 'result'
|
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
|
+
# Get the URI from the child object.
|
36
|
+
# Returns nil if there is none.
|
37
|
+
#
|
38
|
+
def get_uri
|
39
|
+
uri = find_child URL
|
40
|
+
return nil unless uri
|
41
|
+
return uri.value
|
42
|
+
end
|
43
|
+
|
44
|
+
#
|
45
|
+
# Set the result of the API call.
|
46
|
+
#
|
47
|
+
def set_result data
|
48
|
+
r = find_child RESULT
|
49
|
+
return nil unless r
|
50
|
+
r.set_value data
|
51
|
+
end
|
52
|
+
|
53
|
+
#
|
54
|
+
# Get the URL for the service including all URL params.
|
55
|
+
#
|
56
|
+
def get_full_url
|
57
|
+
p = ""
|
58
|
+
params = find_child PARAMS
|
59
|
+
params.children.each do |child|
|
60
|
+
p << ( p.empty? ? "?" : "&" )
|
61
|
+
|
62
|
+
# TODO: Quote URL params for safety
|
63
|
+
p << "#{child.name}=#{child.value}"
|
64
|
+
end
|
65
|
+
return "#{get_uri}#{p}"
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
# ---------------------------------------------------------------------
|
70
|
+
# Children
|
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
|
+
def add_children_on_create?
|
77
|
+
return true
|
78
|
+
end
|
79
|
+
|
80
|
+
# Add children to this object.
|
81
|
+
# This is used by containers to add children needed
|
82
|
+
# for default configurations.
|
83
|
+
def add_default_children
|
84
|
+
fac = $engine.factory
|
85
|
+
fac.create "uri", "string", "https://web.site/", self
|
86
|
+
fac.create "params", "container", nil, self
|
87
|
+
fac.create "result", "string", nil, self
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
# ---------------------------------------------------------------------
|
92
|
+
# Messages
|
93
|
+
# ---------------------------------------------------------------------
|
94
|
+
|
95
|
+
#
|
96
|
+
# Get a list of message names that this object receives.
|
97
|
+
#
|
98
|
+
def self.messages
|
99
|
+
return super + [ "run" ]
|
100
|
+
end
|
101
|
+
|
102
|
+
# Post the content to the endpoint.
|
103
|
+
def msg_run
|
104
|
+
url = get_full_url
|
105
|
+
$log.debug url
|
106
|
+
result = Gloo::Objs::HttpGet.get_response url
|
107
|
+
set_result result
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
# ---------------------------------------------------------------------
|
112
|
+
# Static functions
|
113
|
+
# ---------------------------------------------------------------------
|
114
|
+
|
115
|
+
# Post the content to the endpoint.
|
116
|
+
def self.get_response url
|
117
|
+
uri = URI( url )
|
118
|
+
Net::HTTP.start( uri.host, uri.port,
|
119
|
+
:use_ssl => uri.scheme == 'https') do |http|
|
120
|
+
request = Net::HTTP::Get.new uri
|
121
|
+
response = http.request request # Net::HTTPResponse object
|
122
|
+
return response.body
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
@@ -0,0 +1,127 @@
|
|
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'
|
15
|
+
KEYWORD_SHORT = 'post'
|
16
|
+
URL = 'uri'
|
17
|
+
BODY = 'body'
|
18
|
+
|
19
|
+
#
|
20
|
+
# The name of the object type.
|
21
|
+
#
|
22
|
+
def self.typename
|
23
|
+
return KEYWORD
|
24
|
+
end
|
25
|
+
|
26
|
+
#
|
27
|
+
# The short name of the object type.
|
28
|
+
#
|
29
|
+
def self.short_typename
|
30
|
+
return KEYWORD_SHORT
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# Get the URI from the child object.
|
35
|
+
# Returns nil if there is none.
|
36
|
+
#
|
37
|
+
def get_uri
|
38
|
+
uri = find_child URL
|
39
|
+
return nil unless uri
|
40
|
+
return uri.value
|
41
|
+
end
|
42
|
+
|
43
|
+
#
|
44
|
+
# Get all the children of the body container and
|
45
|
+
# convert to JSON that will be sent in the HTTP body.
|
46
|
+
#
|
47
|
+
def get_body_as_json
|
48
|
+
h = {}
|
49
|
+
|
50
|
+
body = find_child BODY
|
51
|
+
body.children.each do |child|
|
52
|
+
h[ child.name ] = child.value
|
53
|
+
end
|
54
|
+
|
55
|
+
return h.to_json
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
# ---------------------------------------------------------------------
|
60
|
+
# Children
|
61
|
+
# ---------------------------------------------------------------------
|
62
|
+
|
63
|
+
# Does this object have children to add when an object
|
64
|
+
# is created in interactive mode?
|
65
|
+
# This does not apply during obj load, etc.
|
66
|
+
def add_children_on_create?
|
67
|
+
return true
|
68
|
+
end
|
69
|
+
|
70
|
+
# Add children to this object.
|
71
|
+
# This is used by containers to add children needed
|
72
|
+
# for default configurations.
|
73
|
+
def add_default_children
|
74
|
+
fac = $engine.factory
|
75
|
+
fac.create "uri", "string", "https://web.site/", self
|
76
|
+
fac.create "body", "container", nil, self
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
# ---------------------------------------------------------------------
|
81
|
+
# Messages
|
82
|
+
# ---------------------------------------------------------------------
|
83
|
+
|
84
|
+
#
|
85
|
+
# Get a list of message names that this object receives.
|
86
|
+
#
|
87
|
+
def self.messages
|
88
|
+
return super + [ "run" ]
|
89
|
+
end
|
90
|
+
|
91
|
+
# Post the content to the endpoint.
|
92
|
+
def msg_run
|
93
|
+
uri = get_uri
|
94
|
+
return unless uri
|
95
|
+
|
96
|
+
body = get_body_as_json
|
97
|
+
|
98
|
+
if uri.downcase.start_with?( "https" )
|
99
|
+
use_ssl = true
|
100
|
+
else
|
101
|
+
use_ssl = false
|
102
|
+
end
|
103
|
+
Gloo::Objs::HttpPost.post_json uri, body, use_ssl
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
# ---------------------------------------------------------------------
|
108
|
+
# Static functions
|
109
|
+
# ---------------------------------------------------------------------
|
110
|
+
|
111
|
+
# Post the content to the endpoint.
|
112
|
+
def self.post_json url, body, use_ssl=true
|
113
|
+
# Structure the request
|
114
|
+
uri = URI.parse( url )
|
115
|
+
request = Net::HTTP::Post.new( uri.path )
|
116
|
+
request.content_type = 'application/json'
|
117
|
+
request.body = body
|
118
|
+
n = Net::HTTP.new( uri.host, uri.port )
|
119
|
+
n.use_ssl = use_ssl
|
120
|
+
|
121
|
+
# Send the payload to the endpoint.
|
122
|
+
n.start { |http| http.request( request ) }
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,126 @@
|
|
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'
|
15
|
+
KEYWORD_SHORT = 'slack'
|
16
|
+
URL = 'uri'
|
17
|
+
MSG = 'message'
|
18
|
+
USER = 'username'
|
19
|
+
CHANNEL = 'channel'
|
20
|
+
ICON = 'icon_emoji'
|
21
|
+
|
22
|
+
ATTACHMENT = 'attachment'
|
23
|
+
TITLE = 'title'
|
24
|
+
TEXT = 'text'
|
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 get_uri
|
45
|
+
uri = find_child URL
|
46
|
+
return nil unless uri
|
47
|
+
return uri.value
|
48
|
+
end
|
49
|
+
|
50
|
+
#
|
51
|
+
# Get the URI from the child object.
|
52
|
+
# Returns nil if there is none.
|
53
|
+
#
|
54
|
+
def get_attachment
|
55
|
+
o = find_child ATTACHMENT
|
56
|
+
return nil unless o
|
57
|
+
|
58
|
+
title = o.find_child TITLE
|
59
|
+
text = o.find_child TEXT
|
60
|
+
return [{ 'title' => title.value, 'text' => text.value }]
|
61
|
+
end
|
62
|
+
|
63
|
+
#
|
64
|
+
# Get all the children of the body container and
|
65
|
+
# convert to JSON that will be sent in the HTTP body.
|
66
|
+
#
|
67
|
+
def get_body_as_json
|
68
|
+
h = { 'text' => find_child( MSG ).value,
|
69
|
+
'username' => find_child( USER ).value,
|
70
|
+
'channel' => find_child( CHANNEL ).value,
|
71
|
+
'icon_emoji' => find_child( ICON ).value,
|
72
|
+
}
|
73
|
+
|
74
|
+
o = get_attachment
|
75
|
+
h[ 'attachments' ] = o if o
|
76
|
+
return h.to_json
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
# ---------------------------------------------------------------------
|
81
|
+
# Children
|
82
|
+
# ---------------------------------------------------------------------
|
83
|
+
|
84
|
+
# Does this object have children to add when an object
|
85
|
+
# is created in interactive mode?
|
86
|
+
# This does not apply during obj load, etc.
|
87
|
+
def add_children_on_create?
|
88
|
+
return true
|
89
|
+
end
|
90
|
+
|
91
|
+
# Add children to this object.
|
92
|
+
# This is used by containers to add children needed
|
93
|
+
# for default configurations.
|
94
|
+
def add_default_children
|
95
|
+
fac = $engine.factory
|
96
|
+
fac.create URL, "string", "https://hooks.slack.com/services/...", self
|
97
|
+
fac.create MSG, "string", "textual message", self
|
98
|
+
fac.create USER, "string", "Slack Bot", self
|
99
|
+
fac.create CHANNEL, "string", "general", self
|
100
|
+
fac.create ICON, "string", ":ghost:", self
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
# ---------------------------------------------------------------------
|
105
|
+
# Messages
|
106
|
+
# ---------------------------------------------------------------------
|
107
|
+
|
108
|
+
#
|
109
|
+
# Get a list of message names that this object receives.
|
110
|
+
#
|
111
|
+
def self.messages
|
112
|
+
return super + [ "run" ]
|
113
|
+
end
|
114
|
+
|
115
|
+
# Post the content to the endpoint.
|
116
|
+
def msg_run
|
117
|
+
uri = get_uri
|
118
|
+
return unless uri
|
119
|
+
|
120
|
+
body = get_body_as_json
|
121
|
+
Gloo::Objs::HttpPost.post_json uri, body, true
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
end
|
126
|
+
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'
|
15
|
+
KEYWORD_SHORT = 'team'
|
16
|
+
URL = 'uri'
|
17
|
+
MSG = 'message'
|
18
|
+
TITLE = 'title'
|
19
|
+
COLOR = 'color'
|
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 get_uri
|
40
|
+
uri = find_child URL
|
41
|
+
return nil unless uri
|
42
|
+
return uri.value
|
43
|
+
end
|
44
|
+
|
45
|
+
# Get the color value.
|
46
|
+
def get_color
|
47
|
+
c = find_child COLOR
|
48
|
+
return nil unless c
|
49
|
+
return c.value
|
50
|
+
end
|
51
|
+
|
52
|
+
#
|
53
|
+
# Get all the children of the body container and
|
54
|
+
# convert to JSON that will be sent in the HTTP body.
|
55
|
+
#
|
56
|
+
def get_body_as_json
|
57
|
+
h = { 'title' => find_child( TITLE ).value,
|
58
|
+
'text' => find_child( MSG ).value
|
59
|
+
}
|
60
|
+
|
61
|
+
color = get_color
|
62
|
+
if color
|
63
|
+
h[ 'themeColor' ] = color
|
64
|
+
end
|
65
|
+
|
66
|
+
return h.to_json
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
# ---------------------------------------------------------------------
|
71
|
+
# Children
|
72
|
+
# ---------------------------------------------------------------------
|
73
|
+
|
74
|
+
# Does this object have children to add when an object
|
75
|
+
# is created in interactive mode?
|
76
|
+
# This does not apply during obj load, etc.
|
77
|
+
def add_children_on_create?
|
78
|
+
return true
|
79
|
+
end
|
80
|
+
|
81
|
+
# Add children to this object.
|
82
|
+
# This is used by containers to add children needed
|
83
|
+
# for default configurations.
|
84
|
+
def add_default_children
|
85
|
+
fac = $engine.factory
|
86
|
+
fac.create URL, "string", "https://outlook.office.com/webhook/...", self
|
87
|
+
fac.create TITLE, "string", "", self
|
88
|
+
fac.create COLOR, "color", "008000", self
|
89
|
+
fac.create MSG, "string", "", self
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
# ---------------------------------------------------------------------
|
94
|
+
# Messages
|
95
|
+
# ---------------------------------------------------------------------
|
96
|
+
|
97
|
+
#
|
98
|
+
# Get a list of message names that this object receives.
|
99
|
+
#
|
100
|
+
def self.messages
|
101
|
+
return super + [ "run" ]
|
102
|
+
end
|
103
|
+
|
104
|
+
# Post the content to the endpoint.
|
105
|
+
def msg_run
|
106
|
+
uri = get_uri
|
107
|
+
return unless uri
|
108
|
+
|
109
|
+
body = get_body_as_json
|
110
|
+
# puts body
|
111
|
+
|
112
|
+
Gloo::Objs::HttpPost.post_json uri, body, true
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|