MuranoCLI 3.0.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +50 -27
  3. data/.trustme.vim +12 -8
  4. data/bin/murano +23 -8
  5. data/docs/basic_example.rst +1 -1
  6. data/docs/completions/murano_completion-bash +88 -0
  7. data/lib/MrMurano/Account.rb +3 -3
  8. data/lib/MrMurano/Business.rb +6 -6
  9. data/lib/MrMurano/Config-Migrate.rb +1 -3
  10. data/lib/MrMurano/Config.rb +16 -8
  11. data/lib/MrMurano/Content.rb +56 -45
  12. data/lib/MrMurano/Gateway.rb +62 -21
  13. data/lib/MrMurano/Mock.rb +27 -19
  14. data/lib/MrMurano/Passwords.rb +7 -7
  15. data/lib/MrMurano/ReCommander.rb +171 -28
  16. data/lib/MrMurano/Setting.rb +38 -40
  17. data/lib/MrMurano/Solution-ServiceConfig.rb +2 -1
  18. data/lib/MrMurano/Solution-Services.rb +196 -61
  19. data/lib/MrMurano/Solution-Users.rb +7 -7
  20. data/lib/MrMurano/Solution.rb +22 -8
  21. data/lib/MrMurano/SolutionId.rb +10 -4
  22. data/lib/MrMurano/SubCmdGroupContext.rb +14 -5
  23. data/lib/MrMurano/SyncAllowed.rb +42 -0
  24. data/lib/MrMurano/SyncUpDown.rb +122 -65
  25. data/lib/MrMurano/Webservice-Cors.rb +9 -3
  26. data/lib/MrMurano/Webservice-Endpoint.rb +39 -33
  27. data/lib/MrMurano/Webservice-File.rb +35 -24
  28. data/lib/MrMurano/commands/business.rb +18 -18
  29. data/lib/MrMurano/commands/content.rb +3 -2
  30. data/lib/MrMurano/commands/devices.rb +137 -22
  31. data/lib/MrMurano/commands/globals.rb +8 -2
  32. data/lib/MrMurano/commands/keystore.rb +3 -2
  33. data/lib/MrMurano/commands/link.rb +13 -13
  34. data/lib/MrMurano/commands/login.rb +3 -2
  35. data/lib/MrMurano/commands/mock.rb +4 -3
  36. data/lib/MrMurano/commands/password.rb +4 -2
  37. data/lib/MrMurano/commands/postgresql.rb +5 -3
  38. data/lib/MrMurano/commands/settings.rb +78 -62
  39. data/lib/MrMurano/commands/show.rb +79 -74
  40. data/lib/MrMurano/commands/solution.rb +6 -4
  41. data/lib/MrMurano/commands/solution_picker.rb +5 -4
  42. data/lib/MrMurano/commands/status.rb +15 -4
  43. data/lib/MrMurano/commands/timeseries.rb +3 -2
  44. data/lib/MrMurano/commands/tsdb.rb +3 -2
  45. data/lib/MrMurano/hash.rb +6 -6
  46. data/lib/MrMurano/http.rb +66 -67
  47. data/lib/MrMurano/makePretty.rb +18 -12
  48. data/lib/MrMurano/progress.rb +9 -2
  49. data/lib/MrMurano/verbosing.rb +14 -2
  50. data/lib/MrMurano/version.rb +2 -2
  51. data/spec/GatewayDevice_spec.rb +190 -149
  52. data/spec/Mock_spec.rb +3 -3
  53. data/spec/Solution-ServiceEventHandler_spec.rb +170 -137
  54. data/spec/SyncUpDown_spec.rb +205 -191
  55. metadata +3 -2
@@ -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.get_testpoint_path()
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.get_testpoint_path()
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.get_testpoint_path()
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 = {:items=>[{:id=>"9K0",
34
- :name=>"debug",
35
- :alias=>"XYZ_debug",
36
- :solution_id=>"XYZ",
37
- :service=>"device",
38
- :event=>"datapoint",
39
- :created_at=>"2016-07-07T19:16:19.479Z",
40
- :updated_at=>"2016-09-12T13:26:55.868Z"}],
41
- :total=>1}
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(:headers=>{'Authorization'=>'token TTTTTTTTTT',
44
- 'Content-Type'=>'application/json'}).
45
- to_return(body: body.to_json)
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 = {:id=>"9K0",
53
- :name=>"debug",
54
- :alias=>"XYZ_debug",
55
- :solution_id=>"XYZ",
56
- :service=>"device",
57
- :event=>"datapoint",
58
- :created_at=>"2016-07-07T19:16:19.479Z",
59
- :updated_at=>"2016-09-12T13:26:55.868Z",
60
- :script=>%{--#EVENT device datapoint
61
- -- lua code is here
62
- function foo(bar)
63
- return bar + 1
64
- end
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(:headers=>{'Authorization'=>'token TTTTTTTTTT',
69
- 'Content-Type'=>'application/json'}).
70
- to_return(body: body.to_json)
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 = {:id=>"9K0",
78
- :name=>"debug",
79
- :alias=>"XYZ_debug",
80
- :solution_id=>"XYZ",
81
- :service=>"device",
82
- :event=>"datapoint",
83
- :created_at=>"2016-07-07T19:16:19.479Z",
84
- :updated_at=>"2016-09-12T13:26:55.868Z",
85
- :script=>%{--#EVENT device datapoint
86
- -- lua code is here
87
- function foo(bar)
88
- return bar + 1
89
- end
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(:headers=>{'Authorization'=>'token TTTTTTTTTT',
94
- 'Content-Type'=>'application/json'}).
95
- to_return(body: body.to_json)
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 = {:id=>"9K0",
104
- :name=>"debug",
105
- :alias=>"XYZ_debug",
106
- :solution_id=>"XYZ",
107
- :service=>"device",
108
- :event=>"datapoint",
109
- :created_at=>"2016-07-07T19:16:19.479Z",
110
- :updated_at=>"2016-09-12T13:26:55.868Z",
111
- :script=>%{-- lua code is here
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(:headers=>{'Authorization'=>'token TTTTTTTTTT',
119
- 'Content-Type'=>'application/json'}).
120
- to_return(body: body.to_json)
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(:headers=>{'Authorization'=>'token TTTTTTTTTT',
134
- 'Content-Type'=>'application/json'}).
135
- to_return(body: "")
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(:headers=>{'Authorization'=>'token TTTTTTTTTT',
144
- 'Content-Type'=>'application/json'}).
145
- to_return(body: "")
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 << %{-- lua code is here
149
- function foo(bar)
150
- return bar + 1
151
- end
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
- :id=>"9K0",
158
- :service=>'data',
159
- :event=>'datapoint',
160
- :solution_id=>"XYZ",
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(:headers=>{'Authorization'=>'token TTTTTTTTTT',
169
- 'Content-Type'=>'application/json'}).
170
- to_return(status: 404)
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(:headers=>{'Authorization'=>'token TTTTTTTTTT',
173
- 'Content-Type'=>'application/json'}).
174
- to_return(body: "")
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 << %{-- lua code is here
178
- function foo(bar)
179
- return bar + 1
180
- end
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
- :id=>"9K0",
187
- :service=>'device',
188
- :event=>'datapoint',
189
- :solution_id=>"XYZ",
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 = {:id=>"9K0",
199
- :name=>"debug",
200
- :alias=>"XYZ_debug",
201
- :solution_id=>"XYZ",
202
- :service=>"device",
203
- :event=>"datapoint",
204
- :created_at=>"2016-07-07T19:16:19.479Z",
205
- :updated_at=>"2016-09-12T13:26:55.868Z"}
206
- @iB = {:id=>"9K0",
207
- :name=>"debug",
208
- :alias=>"XYZ_debug",
209
- :solution_id=>"XYZ",
210
- :service=>"device",
211
- :event=>"datapoint",
212
- :created_at=>"2016-07-07T19:16:19.479Z",
213
- :updated_at=>"2016-09-12T13:26:55.868Z"}
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,v| k == :updated_at}.merge({
225
- :local_path => Pathname.new(tio.path)
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({:updated_at=>Pathname.new(tio.path).mtime.getutc})
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,v| k == :updated_at}.merge({
241
- :local_path => Pathname.new(tio.path)
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({:updated_at=>Pathname.new(tio.path).mtime.getutc})
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({ :name=>"bob" }, nil)
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({ :service=>'device', :event=>'datapoint' })
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(:event=>'bob'))
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(:service=>'bob'))
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(:event=>'bob'))
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(:service=>'bob'))
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({:service=>'device',
316
- :event=>'datapoint',
317
- :type=>nil,
318
- :line=>0,
319
- :line_end=>3,
320
- :local_path=>Pathname.new(tio.path),
321
- :script=>%{--#EVENT device datapoint\n-- do something.\nTsdb.write{tags={sn='1'},metrics={[data.alias]=data.value[2]}}\n},
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
- :service=>'device',
352
- :event=>'datapoint',
353
- :type=>nil,
354
- :line=>1,
355
- :line_end=>3,
356
- :local_path=>Pathname.new(tio.path),
357
- :script=>%{--#EVENT device datapoint\nTsdb.write{tags={sn='1'},metrics={[data.alias]=data.value[2]}}\n},
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
- :service=>'bob',
368
- :event=>'built',
369
- :local_path=>Pathname.new('a/relative/path.lua'),
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
- # vim: set ai et sw=2 ts=2 :
433
+