MuranoCLI 3.0.0 → 3.0.1
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/.rubocop.yml +50 -27
- data/.trustme.vim +12 -8
- data/bin/murano +23 -8
- data/docs/basic_example.rst +1 -1
- data/docs/completions/murano_completion-bash +88 -0
- data/lib/MrMurano/Account.rb +3 -3
- data/lib/MrMurano/Business.rb +6 -6
- data/lib/MrMurano/Config-Migrate.rb +1 -3
- data/lib/MrMurano/Config.rb +16 -8
- data/lib/MrMurano/Content.rb +56 -45
- data/lib/MrMurano/Gateway.rb +62 -21
- data/lib/MrMurano/Mock.rb +27 -19
- data/lib/MrMurano/Passwords.rb +7 -7
- data/lib/MrMurano/ReCommander.rb +171 -28
- data/lib/MrMurano/Setting.rb +38 -40
- data/lib/MrMurano/Solution-ServiceConfig.rb +2 -1
- data/lib/MrMurano/Solution-Services.rb +196 -61
- data/lib/MrMurano/Solution-Users.rb +7 -7
- data/lib/MrMurano/Solution.rb +22 -8
- data/lib/MrMurano/SolutionId.rb +10 -4
- data/lib/MrMurano/SubCmdGroupContext.rb +14 -5
- data/lib/MrMurano/SyncAllowed.rb +42 -0
- data/lib/MrMurano/SyncUpDown.rb +122 -65
- data/lib/MrMurano/Webservice-Cors.rb +9 -3
- data/lib/MrMurano/Webservice-Endpoint.rb +39 -33
- data/lib/MrMurano/Webservice-File.rb +35 -24
- data/lib/MrMurano/commands/business.rb +18 -18
- data/lib/MrMurano/commands/content.rb +3 -2
- data/lib/MrMurano/commands/devices.rb +137 -22
- data/lib/MrMurano/commands/globals.rb +8 -2
- data/lib/MrMurano/commands/keystore.rb +3 -2
- data/lib/MrMurano/commands/link.rb +13 -13
- data/lib/MrMurano/commands/login.rb +3 -2
- data/lib/MrMurano/commands/mock.rb +4 -3
- data/lib/MrMurano/commands/password.rb +4 -2
- data/lib/MrMurano/commands/postgresql.rb +5 -3
- data/lib/MrMurano/commands/settings.rb +78 -62
- data/lib/MrMurano/commands/show.rb +79 -74
- data/lib/MrMurano/commands/solution.rb +6 -4
- data/lib/MrMurano/commands/solution_picker.rb +5 -4
- data/lib/MrMurano/commands/status.rb +15 -4
- data/lib/MrMurano/commands/timeseries.rb +3 -2
- data/lib/MrMurano/commands/tsdb.rb +3 -2
- data/lib/MrMurano/hash.rb +6 -6
- data/lib/MrMurano/http.rb +66 -67
- data/lib/MrMurano/makePretty.rb +18 -12
- data/lib/MrMurano/progress.rb +9 -2
- data/lib/MrMurano/verbosing.rb +14 -2
- data/lib/MrMurano/version.rb +2 -2
- data/spec/GatewayDevice_spec.rb +190 -149
- data/spec/Mock_spec.rb +3 -3
- data/spec/Solution-ServiceEventHandler_spec.rb +170 -137
- data/spec/SyncUpDown_spec.rb +205 -191
- metadata +3 -2
data/spec/Mock_spec.rb
CHANGED
@@ -16,7 +16,7 @@ RSpec.describe MrMurano::Mock, "#mock" do
|
|
16
16
|
it "can create the testpoint file" do
|
17
17
|
uuid = @mock.create_testpoint()
|
18
18
|
expect(uuid.length).to be("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX".length)
|
19
|
-
path = @mock.
|
19
|
+
path = @mock.testpoint_path()
|
20
20
|
testpoint = File.read(path)
|
21
21
|
expect(testpoint.include? uuid).to be(true)
|
22
22
|
end
|
@@ -29,14 +29,14 @@ RSpec.describe MrMurano::Mock, "#mock" do
|
|
29
29
|
|
30
30
|
it "can remove the testpoint file" do
|
31
31
|
@mock.create_testpoint()
|
32
|
-
path = @mock.
|
32
|
+
path = @mock.testpoint_path()
|
33
33
|
removed = @mock.remove_testpoint()
|
34
34
|
expect(removed).to be(true)
|
35
35
|
expect(File.exist?(path)).to be(false)
|
36
36
|
end
|
37
37
|
|
38
38
|
it "can remove the missing testpoint file" do
|
39
|
-
path = @mock.
|
39
|
+
path = @mock.testpoint_path()
|
40
40
|
removed = @mock.remove_testpoint()
|
41
41
|
expect(removed).to be(false)
|
42
42
|
expect(File.exist?(path)).to be(false)
|
@@ -1,3 +1,10 @@
|
|
1
|
+
# Last Modified: 2017.08.22 /coding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# Copyright © 2016-2017 Exosite LLC.
|
5
|
+
# License: MIT. See LICENSE.txt.
|
6
|
+
# vim:tw=0:ts=2:sw=2:et:ai
|
7
|
+
|
1
8
|
require 'tempfile'
|
2
9
|
require 'MrMurano/version'
|
3
10
|
require 'MrMurano/ProjectFile'
|
@@ -30,94 +37,105 @@ RSpec.describe MrMurano::EventHandler do
|
|
30
37
|
end
|
31
38
|
|
32
39
|
it "lists" do
|
33
|
-
body = {
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
40
|
+
body = {
|
41
|
+
items: [
|
42
|
+
{
|
43
|
+
id: "9K0",
|
44
|
+
name: "debug",
|
45
|
+
alias: "XYZ_debug",
|
46
|
+
solution_id: "XYZ",
|
47
|
+
service: "device",
|
48
|
+
event: "datapoint",
|
49
|
+
created_at: "2016-07-07T19:16:19.479Z",
|
50
|
+
updated_at: "2016-09-12T13:26:55.868Z",
|
51
|
+
},
|
52
|
+
],
|
53
|
+
total: 1,
|
54
|
+
}
|
42
55
|
stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/eventhandler").
|
43
|
-
with(:
|
44
|
-
|
45
|
-
|
46
|
-
|
56
|
+
with(headers: {
|
57
|
+
'Authorization'=>'token TTTTTTTTTT',
|
58
|
+
'Content-Type'=>'application/json',
|
59
|
+
}).to_return(body: body.to_json)
|
47
60
|
ret = @srv.list
|
48
61
|
expect(ret).to eq(body[:items])
|
49
62
|
end
|
50
63
|
|
51
64
|
it "fetches, with header" do
|
52
|
-
body = {
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
65
|
+
body = {
|
66
|
+
id: "9K0",
|
67
|
+
name: "debug",
|
68
|
+
alias: "XYZ_debug",
|
69
|
+
solution_id: "XYZ",
|
70
|
+
service: "device",
|
71
|
+
event: "datapoint",
|
72
|
+
created_at: "2016-07-07T19:16:19.479Z",
|
73
|
+
updated_at: "2016-09-12T13:26:55.868Z",
|
74
|
+
script: %{--#EVENT device datapoint
|
75
|
+
-- lua code is here
|
76
|
+
function foo(bar)
|
77
|
+
return bar + 1
|
78
|
+
end
|
79
|
+
},
|
66
80
|
}
|
67
81
|
stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/eventhandler/9K0").
|
68
|
-
with(:
|
69
|
-
|
70
|
-
|
71
|
-
|
82
|
+
with(headers: {
|
83
|
+
'Authorization'=>'token TTTTTTTTTT',
|
84
|
+
'Content-Type'=>'application/json',
|
85
|
+
}).to_return(body: body.to_json)
|
72
86
|
ret = @srv.fetch('9K0')
|
73
87
|
expect(ret).to eq(body[:script])
|
74
88
|
end
|
75
89
|
|
76
90
|
it "fetches, with header into block" do
|
77
|
-
body = {
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
+
body = {
|
92
|
+
id: "9K0",
|
93
|
+
name: "debug",
|
94
|
+
alias: "XYZ_debug",
|
95
|
+
solution_id: "XYZ",
|
96
|
+
service: "device",
|
97
|
+
event: "datapoint",
|
98
|
+
created_at: "2016-07-07T19:16:19.479Z",
|
99
|
+
updated_at: "2016-09-12T13:26:55.868Z",
|
100
|
+
script: %{
|
101
|
+
--#EVENT device datapoint
|
102
|
+
-- lua code is here
|
103
|
+
function foo(bar)
|
104
|
+
return bar + 1
|
105
|
+
end
|
106
|
+
},
|
91
107
|
}
|
92
108
|
stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/eventhandler/9K0").
|
93
|
-
with(:
|
94
|
-
|
95
|
-
|
96
|
-
|
109
|
+
with(headers: {
|
110
|
+
'Authorization'=>'token TTTTTTTTTT',
|
111
|
+
'Content-Type'=>'application/json',
|
112
|
+
}).to_return(body: body.to_json)
|
97
113
|
ret = nil
|
98
114
|
@srv.fetch('9K0') { |sc| ret = sc }
|
99
115
|
expect(ret).to eq(body[:script])
|
100
116
|
end
|
101
117
|
|
102
118
|
it "fetches, without header" do
|
103
|
-
body = {
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
119
|
+
body = {
|
120
|
+
id: "9K0",
|
121
|
+
name: "debug",
|
122
|
+
alias: "XYZ_debug",
|
123
|
+
solution_id: "XYZ",
|
124
|
+
service: "device",
|
125
|
+
event: "datapoint",
|
126
|
+
created_at: "2016-07-07T19:16:19.479Z",
|
127
|
+
updated_at: "2016-09-12T13:26:55.868Z",
|
128
|
+
script: %{-- lua code is here
|
112
129
|
function foo(bar)
|
113
130
|
return bar + 1
|
114
131
|
end
|
115
|
-
}
|
132
|
+
},
|
116
133
|
}
|
117
134
|
stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/eventhandler/9K0").
|
118
|
-
with(:
|
119
|
-
|
120
|
-
|
135
|
+
with(headers: {
|
136
|
+
'Authorization'=>'token TTTTTTTTTT',
|
137
|
+
'Content-Type'=>'application/json',
|
138
|
+
}).to_return(body: body.to_json)
|
121
139
|
|
122
140
|
ret = @srv.fetch('9K0')
|
123
141
|
expect(ret).to eq(%{--#EVENT device datapoint
|
@@ -130,9 +148,10 @@ end
|
|
130
148
|
|
131
149
|
it "removes" do
|
132
150
|
stub_request(:delete, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/eventhandler/9K0").
|
133
|
-
with(:
|
134
|
-
|
135
|
-
|
151
|
+
with(headers: {
|
152
|
+
'Authorization'=>'token TTTTTTTTTT',
|
153
|
+
'Content-Type'=>'application/json',
|
154
|
+
}).to_return(body: "")
|
136
155
|
|
137
156
|
ret = @srv.remove('9K0')
|
138
157
|
expect(ret).to eq({})
|
@@ -140,24 +159,26 @@ end
|
|
140
159
|
|
141
160
|
it "uploads over old version" do
|
142
161
|
stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/eventhandler/XYZ_data_datapoint").
|
143
|
-
with(:
|
144
|
-
|
145
|
-
|
162
|
+
with(headers: {
|
163
|
+
'Authorization'=>'token TTTTTTTTTT',
|
164
|
+
'Content-Type'=>'application/json',
|
165
|
+
}).to_return(body: "")
|
146
166
|
|
147
167
|
Tempfile.open('foo') do |tio|
|
148
|
-
tio << %{
|
149
|
-
|
150
|
-
|
151
|
-
|
168
|
+
tio << %{
|
169
|
+
-- lua code is here
|
170
|
+
function foo(bar)
|
171
|
+
return bar + 1
|
172
|
+
end
|
152
173
|
}
|
153
174
|
tio.close
|
154
175
|
|
155
176
|
ret = @srv.upload(tio.path,
|
156
177
|
MrMurano::EventHandler::EventHandlerItem.new(
|
157
|
-
:
|
158
|
-
:
|
159
|
-
:
|
160
|
-
:
|
178
|
+
id: "9K0",
|
179
|
+
service: 'data',
|
180
|
+
event: 'datapoint',
|
181
|
+
solution_id: "XYZ",
|
161
182
|
))
|
162
183
|
expect(ret)
|
163
184
|
end
|
@@ -165,28 +186,31 @@ end
|
|
165
186
|
|
166
187
|
it "uploads when nothing is there" do
|
167
188
|
stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/eventhandler/XYZ_device_datapoint").
|
168
|
-
with(:
|
169
|
-
|
170
|
-
|
189
|
+
with(headers: {
|
190
|
+
'Authorization'=>'token TTTTTTTTTT',
|
191
|
+
'Content-Type'=>'application/json',
|
192
|
+
}).to_return(status: 404)
|
171
193
|
stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/eventhandler/").
|
172
|
-
with(:
|
173
|
-
|
174
|
-
|
194
|
+
with(headers: {
|
195
|
+
'Authorization'=>'token TTTTTTTTTT',
|
196
|
+
'Content-Type'=>'application/json',
|
197
|
+
}).to_return(body: "")
|
175
198
|
|
176
199
|
Tempfile.open('foo') do |tio|
|
177
|
-
tio << %{
|
178
|
-
|
179
|
-
|
180
|
-
|
200
|
+
tio << %{
|
201
|
+
-- lua code is here
|
202
|
+
function foo(bar)
|
203
|
+
return bar + 1
|
204
|
+
end
|
181
205
|
}
|
182
206
|
tio.close
|
183
207
|
|
184
208
|
ret = @srv.upload(tio.path,
|
185
209
|
MrMurano::EventHandler::EventHandlerItem.new(
|
186
|
-
:
|
187
|
-
:
|
188
|
-
:
|
189
|
-
:
|
210
|
+
id: "9K0",
|
211
|
+
service: 'device',
|
212
|
+
event: 'datapoint',
|
213
|
+
solution_id: "XYZ",
|
190
214
|
))
|
191
215
|
expect(ret)
|
192
216
|
end
|
@@ -195,22 +219,26 @@ end
|
|
195
219
|
|
196
220
|
context "compares" do
|
197
221
|
before(:example) do
|
198
|
-
@iA = {
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
222
|
+
@iA = {
|
223
|
+
id: "9K0",
|
224
|
+
name: "debug",
|
225
|
+
alias: "XYZ_debug",
|
226
|
+
solution_id: "XYZ",
|
227
|
+
service: "device",
|
228
|
+
event: "datapoint",
|
229
|
+
created_at: "2016-07-07T19:16:19.479Z",
|
230
|
+
updated_at: "2016-09-12T13:26:55.868Z",
|
231
|
+
}
|
232
|
+
@iB = {
|
233
|
+
id: "9K0",
|
234
|
+
name: "debug",
|
235
|
+
alias: "XYZ_debug",
|
236
|
+
solution_id: "XYZ",
|
237
|
+
service: "device",
|
238
|
+
event: "datapoint",
|
239
|
+
created_at: "2016-07-07T19:16:19.479Z",
|
240
|
+
updated_at: "2016-09-12T13:26:55.868Z",
|
241
|
+
}
|
214
242
|
end
|
215
243
|
it "both have updated_at" do
|
216
244
|
ret = @srv.docmp(@iA, @iB)
|
@@ -221,13 +249,13 @@ end
|
|
221
249
|
Tempfile.open('foo') do |tio|
|
222
250
|
tio << "something"
|
223
251
|
tio.close
|
224
|
-
iA = @iA.reject{|k,
|
225
|
-
:
|
252
|
+
iA = @iA.reject { |k, _v| k == :updated_at }.merge({
|
253
|
+
local_path: Pathname.new(tio.path),
|
226
254
|
})
|
227
255
|
ret = @srv.docmp(iA, @iB)
|
228
256
|
expect(ret).to eq(true)
|
229
257
|
|
230
|
-
iB = @iB.merge({:
|
258
|
+
iB = @iB.merge( { updated_at: Pathname.new(tio.path).mtime.getutc })
|
231
259
|
ret = @srv.docmp(iA, iB)
|
232
260
|
expect(ret).to eq(false)
|
233
261
|
end
|
@@ -237,13 +265,13 @@ end
|
|
237
265
|
Tempfile.open('foo') do |tio|
|
238
266
|
tio << "something"
|
239
267
|
tio.close
|
240
|
-
iB = @iB.reject{|k,
|
241
|
-
:
|
268
|
+
iB = @iB.reject{ |k, _v| k == :updated_at }.merge({
|
269
|
+
local_path: Pathname.new(tio.path),
|
242
270
|
})
|
243
271
|
ret = @srv.docmp(@iA, iB)
|
244
272
|
expect(ret).to eq(true)
|
245
273
|
|
246
|
-
iA = @iA.merge({:
|
274
|
+
iA = @iA.merge({ updated_at: Pathname.new(tio.path).mtime.getutc })
|
247
275
|
ret = @srv.docmp(iA, iB)
|
248
276
|
expect(ret).to eq(false)
|
249
277
|
end
|
@@ -252,12 +280,12 @@ end
|
|
252
280
|
|
253
281
|
context "Lookup functions" do
|
254
282
|
it "gets local name" do
|
255
|
-
ret = @srv.tolocalname({ :
|
283
|
+
ret = @srv.tolocalname({ name: "bob" }, nil)
|
256
284
|
expect(ret).to eq('bob.lua')
|
257
285
|
end
|
258
286
|
|
259
287
|
it "gets synckey" do
|
260
|
-
ret = @srv.synckey({ :
|
288
|
+
ret = @srv.synckey({ service: 'device', event: 'datapoint' })
|
261
289
|
expect(ret).to eq("device_datapoint")
|
262
290
|
end
|
263
291
|
|
@@ -275,25 +303,25 @@ end
|
|
275
303
|
|
276
304
|
it "raises on alias without service" do
|
277
305
|
expect {
|
278
|
-
@srv.mkname(MrMurano::EventHandler::EventHandlerItem.new(:
|
306
|
+
@srv.mkname(MrMurano::EventHandler::EventHandlerItem.new(event: 'bob'))
|
279
307
|
}.to raise_error %{Missing parts! {"event":"bob"}}
|
280
308
|
end
|
281
309
|
|
282
310
|
it "raises on alias without event" do
|
283
311
|
expect {
|
284
|
-
@srv.mkalias(MrMurano::EventHandler::EventHandlerItem.new(:
|
312
|
+
@srv.mkalias(MrMurano::EventHandler::EventHandlerItem.new(service: 'bob'))
|
285
313
|
}.to raise_error %{Missing parts! {"service":"bob"}}
|
286
314
|
end
|
287
315
|
|
288
316
|
it "raises on name without service" do
|
289
317
|
expect {
|
290
|
-
@srv.mkalias(MrMurano::EventHandler::EventHandlerItem.new(:
|
318
|
+
@srv.mkalias(MrMurano::EventHandler::EventHandlerItem.new(event: 'bob'))
|
291
319
|
}.to raise_error %{Missing parts! {"event":"bob"}}
|
292
320
|
end
|
293
321
|
|
294
322
|
it "raises on name without event" do
|
295
323
|
expect {
|
296
|
-
@srv.mkname(MrMurano::EventHandler::EventHandlerItem.new(:
|
324
|
+
@srv.mkname(MrMurano::EventHandler::EventHandlerItem.new(service: 'bob'))
|
297
325
|
}.to raise_error %{Missing parts! {"service":"bob"}}
|
298
326
|
end
|
299
327
|
end
|
@@ -312,14 +340,18 @@ end
|
|
312
340
|
tio.close
|
313
341
|
|
314
342
|
ret = @srv.to_remote_item(nil, tio.path)
|
315
|
-
expect(ret).to eq(
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
343
|
+
expect(ret).to eq(
|
344
|
+
{
|
345
|
+
service: 'device',
|
346
|
+
event: 'datapoint',
|
347
|
+
svc_alias: nil,
|
348
|
+
type: nil,
|
349
|
+
line: 0,
|
350
|
+
line_end: 3,
|
351
|
+
local_path: Pathname.new(tio.path),
|
352
|
+
script: %{--#EVENT device datapoint\n-- do something.\nTsdb.write{tags={sn='1'},metrics={[data.alias]=data.value[2]}}\n},
|
353
|
+
}
|
354
|
+
)
|
323
355
|
end
|
324
356
|
end
|
325
357
|
|
@@ -348,13 +380,14 @@ end
|
|
348
380
|
ret = @srv.to_remote_item(nil, tio.path)
|
349
381
|
expect(ret).to eq(
|
350
382
|
MrMurano::EventHandler::EventHandlerItem.new(
|
351
|
-
:
|
352
|
-
:
|
353
|
-
:
|
354
|
-
:
|
355
|
-
:
|
356
|
-
:
|
357
|
-
:
|
383
|
+
service: 'device',
|
384
|
+
event: 'datapoint',
|
385
|
+
svc_alias: nil,
|
386
|
+
type: nil,
|
387
|
+
line: 1,
|
388
|
+
line_end: 3,
|
389
|
+
local_path: Pathname.new(tio.path),
|
390
|
+
script: %{--#EVENT device datapoint\nTsdb.write{tags={sn='1'},metrics={[data.alias]=data.value[2]}}\n},
|
358
391
|
))
|
359
392
|
end
|
360
393
|
end
|
@@ -364,9 +397,9 @@ end
|
|
364
397
|
context "Matching" do
|
365
398
|
before(:example) do
|
366
399
|
@an_item = {
|
367
|
-
:
|
368
|
-
:
|
369
|
-
:
|
400
|
+
service: 'bob',
|
401
|
+
event: 'built',
|
402
|
+
local_path: Pathname.new('a/relative/path.lua'),
|
370
403
|
}
|
371
404
|
end
|
372
405
|
context "service" do
|
@@ -397,4 +430,4 @@ end
|
|
397
430
|
end
|
398
431
|
end
|
399
432
|
end
|
400
|
-
|
433
|
+
|