MuranoCLI 2.0.0 → 2.1.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.
@@ -2,8 +2,8 @@ require 'pp'
2
2
 
3
3
  # You don't need this.
4
4
  # To use this:
5
- # - mkdir -p ~/.mrmurano/plugins
6
- # - ln gb.rb ~/.mrmurano/plugins
5
+ # - mkdir -p ~/.murano/plugins
6
+ # - ln gb.rb ~/.murano/plugins
7
7
 
8
8
  command :_gb do |c|
9
9
  c.syntax = %{murano _gb <class> <method> (<args>)}
@@ -18,7 +18,8 @@ command :_gb do |c|
18
18
  begin
19
19
  gb = Object::const_get("MrMurano::#{cls}").new
20
20
  if gb.respond_to? meth then
21
- pp gb.__send__(meth, *args)
21
+ ret = gb.__send__(meth, *args)
22
+ gb.outf(ret) {|o,i| pp o}
22
23
  else
23
24
  say_error "'#{cls}' doesn't '#{meth}'"
24
25
  end
@@ -42,6 +42,9 @@ command :init do |c|
42
42
  say "You are only part of one business; using #{bizid[:name]}"
43
43
  $cfg.set('businesses.id', bizid[:bizid], :project)
44
44
 
45
+ elsif bizz.count == 0 then
46
+ acc.warning "You don't have any businesses; Log into the webUI and create one."
47
+ exit 3
45
48
  else
46
49
  choose do |menu|
47
50
  menu.prompt = "Select which Business to use:"
@@ -65,6 +68,29 @@ command :init do |c|
65
68
  sol = solz.first
66
69
  say "You only have one solution; using #{sol[:domain]}"
67
70
  $cfg.set('solution.id', sol[:apiId], :project)
71
+
72
+ elsif solz.count == 0 then
73
+ say "You don't have any solutions; lets create one"
74
+ solname = ask("Solution Name? ")
75
+ ret = acc.new_solution(solname)
76
+ if ret.nil? then
77
+ acc.error "Create Solution failed"
78
+ exit 5
79
+ end
80
+ if not ret.kind_of?(Hash) and not ret.empty? then
81
+ acc.error "Create Solution failed: #{ret.to_s}"
82
+ exit 2
83
+ end
84
+
85
+ # create doesn't return anything, so we need to go look for it.
86
+ ret = acc.solutions.select{|i| i[:domain] =~ /#{solname}\./}
87
+ sid = ret.first[:apiId]
88
+ if sid.nil? or sid.empty? then
89
+ acc.error "Solution didn't find an apiId!!!! #{ret}"
90
+ exit 3
91
+ end
92
+ $cfg.set('solution.id', sid, :project)
93
+
68
94
  else
69
95
  choose do |menu|
70
96
  menu.prompt = "Select which Solution to use:"
@@ -88,6 +114,29 @@ command :init do |c|
88
114
  prd = podz.first
89
115
  say "You only have one product; using #{prd[:label]}"
90
116
  $cfg.set('product.id', prd[:modelId], :project)
117
+
118
+ elsif podz.count == 0 then
119
+ say "You don't have any products; lets create one"
120
+ podname = ask("Product Name? ")
121
+ ret = acc.new_product(podname)
122
+ if ret.nil? then
123
+ acc.error "Create Product failed"
124
+ exit 5
125
+ end
126
+ if not ret.kind_of?(Hash) and not ret.empty? then
127
+ acc.error "Create Product failed: #{ret.to_s}"
128
+ exit 2
129
+ end
130
+
131
+ # create doesn't return anything, so we need to go look for it.
132
+ ret = acc.products.select{|i| i[:label] == podname}
133
+ pid = ret.first[:modelId]
134
+ if pid.nil? or pid.empty? then
135
+ acc.error "Product didn't find an apiId!!!! #{ret}"
136
+ exit 3
137
+ end
138
+ $cfg.set('product.id', pid, :project)
139
+
91
140
  else
92
141
  choose do |menu|
93
142
  menu.prompt = "Select which Product to use:"
@@ -104,8 +153,8 @@ command :init do |c|
104
153
  puts ''
105
154
  say "Ok, In business ID: #{$cfg['business.id']} using Solution ID: #{$cfg['solution.id']} with Product ID: #{$cfg['product.id']}"
106
155
 
107
- # If no ProjectFile or Solutionfile, then write a ProjectFile
108
- if $project.project_file.nil? then
156
+ # If no ProjectFile, then write a ProjectFile
157
+ if not $project.usingProjectfile then
109
158
  tmpl = File.read(File.join(File.dirname(__FILE__),'..','template','projectFile.murano.erb'))
110
159
  tmpl = ERB.new(tmpl)
111
160
  res = tmpl.result($project.data_binding)
@@ -127,7 +176,10 @@ command :init do |c|
127
176
  path = $cfg[cfgi]
128
177
  path = Pathname.new(path) unless path.kind_of? Pathname
129
178
  path = base + path
130
- path.mkpath unless path.exist?
179
+ unless path.exist? then
180
+ path = path.dirname unless path.extname.empty?
181
+ path.mkpath
182
+ end
131
183
  end
132
184
  say "Default directories created"
133
185
  end
@@ -0,0 +1,20 @@
1
+ require 'MrMurano/Account'
2
+
3
+ command 'login' do |c|
4
+ c.syntax = %{murano login}
5
+ c.summary = %{Log into Murano}
6
+ c.description = %{Log into Murano
7
+
8
+ If you are having trouble logging in, try deleting the saved password first.
9
+ `murano password delete <username>`
10
+ }
11
+ c.option '--show-token', %{Shows the API token}
12
+
13
+ c.action do |args, options|
14
+ acc = MrMurano::Account.new
15
+ ret = acc.token
16
+ say ret if options.show_token
17
+ end
18
+ end
19
+
20
+ # vim: set ai et sw=2 ts=2 :
@@ -11,10 +11,6 @@ end
11
11
 
12
12
  alias_command 'password current', :config, 'user.name'
13
13
 
14
- class Outter
15
- include MrMurano::Verbose
16
- end
17
-
18
14
  command 'password list' do |c|
19
15
  c.syntax = %{murano password list}
20
16
  c.summary = %{List the usernames with saved passwords}
@@ -24,19 +20,16 @@ command 'password list' do |c|
24
20
  psd.load
25
21
 
26
22
  ret = psd.list
27
- outter = Outter.new
28
- outter.outf(ret) do |dd, ios|
23
+ psd.outf(ret) do |dd, ios|
29
24
  rows=[]
30
25
  dd.each_pair do |key, value|
31
26
  value.each{|v| rows << [key, v] }
32
27
  end
33
- outter.tabularize({
28
+ psd.tabularize({
34
29
  :rows=>rows, :headers => [:Host, :Username]
35
30
  }, ios)
36
31
  end
37
-
38
32
  end
39
-
40
33
  end
41
34
 
42
35
  command 'password set' do |c|
@@ -50,6 +43,11 @@ command 'password set' do |c|
50
43
  psd = MrMurano::Passwords.new
51
44
  psd.load
52
45
 
46
+ if args.count < 1 then
47
+ psd.error "Missing username"
48
+ exit 1
49
+ end
50
+
53
51
  username = args.shift
54
52
  host = args.shift
55
53
  host = $cfg['net.host'] if host.nil?
@@ -76,6 +74,11 @@ command 'password delete' do |c|
76
74
  psd = MrMurano::Passwords.new
77
75
  psd.load
78
76
 
77
+ if args.count < 1 then
78
+ psd.error "Missing username"
79
+ exit 1
80
+ end
81
+
79
82
  username = args.shift
80
83
  host = args.shift
81
84
  host = $cfg['net.host'] if host.nil?
@@ -70,7 +70,11 @@ command :status do |c|
70
70
  def gmerge(ret, type, options)
71
71
  if options.grouped then
72
72
  [:toadd, :todel, :tomod, :unchg].each do |kind|
73
- ret[kind].each{|item| item[:pp_type] = type; @grouped[kind] << item}
73
+ ret[kind].each do |item|
74
+ item = item.to_h
75
+ item[:pp_type] = type
76
+ @grouped[kind] << item
77
+ end
74
78
  end
75
79
  else
76
80
  pretty(ret, options)
@@ -6,6 +6,7 @@ require 'MrMurano/commands/cors'
6
6
  require 'MrMurano/commands/domain'
7
7
  require 'MrMurano/commands/init'
8
8
  require 'MrMurano/commands/keystore'
9
+ require 'MrMurano/commands/login'
9
10
  require 'MrMurano/commands/logs'
10
11
  require 'MrMurano/commands/mock'
11
12
  require 'MrMurano/commands/postgresql'
@@ -24,7 +25,6 @@ require 'MrMurano/commands/solutionDelete'
24
25
  require 'MrMurano/commands/solutionList'
25
26
  require 'MrMurano/commands/status'
26
27
  require 'MrMurano/commands/sync'
27
- require 'MrMurano/commands/timeseries'
28
28
  require 'MrMurano/commands/tsdb'
29
29
  require 'MrMurano/commands/usage'
30
30
 
@@ -1,4 +1,4 @@
1
1
  module MrMurano
2
- VERSION = '2.0.0'.freeze
2
+ VERSION = '2.1.0'.freeze
3
3
  end
4
4
 
data/spec/Account_spec.rb CHANGED
@@ -7,6 +7,8 @@ require '_workspace'
7
7
  RSpec.describe MrMurano::Account, "token" do
8
8
  include_context "WORKSPACE"
9
9
  before(:example) do
10
+ @saved_cfg = ENV['MURANO_CONFIGFILE']
11
+ ENV['MURANO_CONFIGFILE'] = nil
10
12
  $cfg = MrMurano::Config.new
11
13
  $cfg.load
12
14
  $cfg['net.host'] = 'bizapi.hosted.exosite.io'
@@ -18,6 +20,7 @@ RSpec.describe MrMurano::Account, "token" do
18
20
 
19
21
  after(:example) do
20
22
  @acc.token_reset
23
+ ENV['MURANO_CONFIGFILE'] = @saved_cfg
21
24
  end
22
25
 
23
26
  context "Get login info" do
@@ -107,6 +110,8 @@ end
107
110
  RSpec.describe MrMurano::Account do
108
111
  include_context "WORKSPACE"
109
112
  before(:example) do
113
+ @saved_cfg = ENV['MURANO_CONFIGFILE']
114
+ ENV['MURANO_CONFIGFILE'] = nil
110
115
  $cfg = MrMurano::Config.new
111
116
  $cfg.load
112
117
  $cfg['net.host'] = 'bizapi.hosted.exosite.io'
@@ -116,6 +121,9 @@ RSpec.describe MrMurano::Account do
116
121
  @acc = MrMurano::Account.new
117
122
  allow(@acc).to receive(:token).and_return("TTTTTTTTTT")
118
123
  end
124
+ after(:example) do
125
+ ENV['MURANO_CONFIGFILE'] = @saved_cfg
126
+ end
119
127
 
120
128
  it "initializes" do
121
129
  uri = @acc.endPoint('')
@@ -10,6 +10,8 @@ RSpec.describe MrMurano::ConfigMigrate do
10
10
  before(:example) do
11
11
  @saved_pwd = ENV['MURANO_PASSWORD']
12
12
  ENV['MURANO_PASSWORD'] = nil
13
+ @saved_cfg = ENV['MURANO_CONFIGFILE']
14
+ ENV['MURANO_CONFIGFILE'] = nil
13
15
 
14
16
  $cfg = MrMurano::Config.new
15
17
  $cfg.load
@@ -27,6 +29,7 @@ RSpec.describe MrMurano::ConfigMigrate do
27
29
  after(:example) do
28
30
  $stdout, $stderr = @stdsaved
29
31
  ENV['MURANO_PASSWORD'] = @saved_pwd
32
+ ENV['MURANO_CONFIGFILE'] = @saved_cfg
30
33
  end
31
34
 
32
35
  it "imports all" do
data/spec/Config_spec.rb CHANGED
@@ -131,8 +131,11 @@ RSpec.describe MrMurano::Config do
131
131
  end
132
132
 
133
133
  context "ENV['MURANO_CONFIGFILE']" do
134
+ before(:example) do
135
+ @saved_cfg = ENV['MURANO_CONFIGFILE']
136
+ end
134
137
  after(:example) do
135
- ENV['MURANO_CONFIGFILE'] = nil
138
+ ENV['MURANO_CONFIGFILE'] = @saved_cfg
136
139
  ENV['MR_CONFIGFILE'] = nil
137
140
  end
138
141
 
@@ -165,13 +168,24 @@ RSpec.describe MrMurano::Config do
165
168
  end
166
169
 
167
170
  it "warns about migrating old ENV name" do
171
+ ENV['MURANO_CONFIGFILE'] = nil
172
+ ENV['MR_CONFIGFILE'] = @tmpdir + '/home/testcreate.config'
173
+ expect_any_instance_of(MrMurano::Config).to receive(:warning).once
174
+ MrMurano::Config.new
175
+ end
176
+
177
+ it "errors if both are defined" do
178
+ ENV['MURANO_CONFIGFILE'] = @tmpdir + '/home/testcreate.config'
168
179
  ENV['MR_CONFIGFILE'] = @tmpdir + '/home/testcreate.config'
169
180
  expect_any_instance_of(MrMurano::Config).to receive(:warning).once
181
+ expect_any_instance_of(MrMurano::Config).to receive(:error).once
170
182
  MrMurano::Config.new
171
183
  end
172
184
  end
173
185
 
174
186
  it "dumps" do
187
+ @saved_cfg = ENV['MURANO_CONFIGFILE']
188
+ ENV['MURANO_CONFIGFILE'] = nil
175
189
  cfg = MrMurano::Config.new
176
190
  cfg.load
177
191
  cfg['sync.bydefault'] = 'files'
@@ -182,6 +196,7 @@ RSpec.describe MrMurano::Config do
182
196
  want = template.result(binding)
183
197
 
184
198
  expect(ret).to eq(want)
199
+ ENV['MURANO_CONFIGFILE'] = @saved_cfg
185
200
  end
186
201
 
187
202
  context "fixing permissions" do
@@ -290,12 +290,14 @@ RSpec.describe MrMurano::Endpoint do
290
290
  'Content-Type'=>'application/json'}).
291
291
  to_return(body: "")
292
292
 
293
- ret = @srv.upload(@tio_.path, {:id=>"9K0",
294
- :method=>"websocket",
295
- :path=>"/api/v1/bar",
296
- :content_type=>"application/json",
297
- }, true)
298
- expect(ret)
293
+ ret = @srv.upload(@tio_.path,
294
+ MrMurano::Endpoint::RouteItem.new(
295
+ :id=>"9K0",
296
+ :method=>"websocket",
297
+ :path=>"/api/v1/bar",
298
+ :content_type=>"application/json",
299
+ ), true)
300
+ expect(ret)
299
301
  end
300
302
 
301
303
  it "when nothing is there" do
@@ -308,11 +310,13 @@ RSpec.describe MrMurano::Endpoint do
308
310
  'Content-Type'=>'application/json'}).
309
311
  to_return(body: "")
310
312
 
311
- ret = @srv.upload(@tio_.path, {:id=>"9K0",
312
- :method=>"websocket",
313
- :path=>"/api/v1/bar",
314
- :content_type=>"application/json",
315
- }, false)
313
+ ret = @srv.upload(@tio_.path,
314
+ MrMurano::Endpoint::RouteItem.new(
315
+ :id=>"9K0",
316
+ :method=>"websocket",
317
+ :path=>"/api/v1/bar",
318
+ :content_type=>"application/json",
319
+ ), false)
316
320
  expect(ret)
317
321
  end
318
322
 
@@ -322,10 +326,12 @@ RSpec.describe MrMurano::Endpoint do
322
326
  'Content-Type'=>'application/json'}).
323
327
  to_return(body: "")
324
328
 
325
- ret = @srv.upload(@tio_.path, {:method=>"websocket",
326
- :path=>"/api/v1/bar",
327
- :content_type=>"application/json",
328
- }, false)
329
+ ret = @srv.upload(@tio_.path,
330
+ MrMurano::Endpoint::RouteItem.new(
331
+ :method=>"websocket",
332
+ :path=>"/api/v1/bar",
333
+ :content_type=>"application/json",
334
+ ), false)
329
335
  expect(ret)
330
336
  end
331
337
 
@@ -336,11 +342,13 @@ RSpec.describe MrMurano::Endpoint do
336
342
  to_return(status: 502, body: "{}")
337
343
 
338
344
  expect(@srv).to receive(:error).and_return(nil)
339
- ret = @srv.upload(@tio_.path, {:id=>"9K0",
340
- :method=>"websocket",
341
- :path=>"/api/v1/bar",
342
- :content_type=>"application/json",
343
- }, true)
345
+ ret = @srv.upload(@tio_.path,
346
+ MrMurano::Endpoint::RouteItem.new(
347
+ :id=>"9K0",
348
+ :method=>"websocket",
349
+ :path=>"/api/v1/bar",
350
+ :content_type=>"application/json",
351
+ ), true)
344
352
  expect(ret)
345
353
  end
346
354
  end
@@ -145,11 +145,13 @@ end
145
145
  }
146
146
  tio.close
147
147
 
148
- ret = @srv.upload(tio.path, {:id=>"9K0",
149
- :service=>'data',
150
- :event=>'datapoint',
151
- :solution_id=>"XYZ",
152
- })
148
+ ret = @srv.upload(tio.path,
149
+ MrMurano::EventHandler::EventHandlerItem.new(
150
+ :id=>"9K0",
151
+ :service=>'data',
152
+ :event=>'datapoint',
153
+ :solution_id=>"XYZ",
154
+ ))
153
155
  expect(ret)
154
156
  end
155
157
  end
@@ -172,11 +174,13 @@ end
172
174
  }
173
175
  tio.close
174
176
 
175
- ret = @srv.upload(tio.path, {:id=>"9K0",
176
- :solution_id=>"XYZ",
177
- :service=>"device",
178
- :event=>"datapoint",
179
- })
177
+ ret = @srv.upload(tio.path,
178
+ MrMurano::EventHandler::EventHandlerItem.new(
179
+ :id=>"9K0",
180
+ :service=>'device',
181
+ :event=>'datapoint',
182
+ :solution_id=>"XYZ",
183
+ ))
180
184
  expect(ret)
181
185
  end
182
186
 
@@ -264,25 +268,25 @@ end
264
268
 
265
269
  it "raises on alias without service" do
266
270
  expect {
267
- @srv.mkname( {:event=>'bob'} )
271
+ @srv.mkname( MrMurano::EventHandler::EventHandlerItem.new(:event=>'bob') )
268
272
  }.to raise_error %{Missing parts! {"event":"bob"}}
269
273
  end
270
274
 
271
275
  it "raises on alias without event" do
272
276
  expect {
273
- @srv.mkalias( {:service=>'bob'} )
277
+ @srv.mkalias( MrMurano::EventHandler::EventHandlerItem.new(:service=>'bob') )
274
278
  }.to raise_error %{Missing parts! {"service":"bob"}}
275
279
  end
276
280
 
277
281
  it "raises on name without service" do
278
282
  expect {
279
- @srv.mkalias( {:event=>'bob'} )
283
+ @srv.mkalias( MrMurano::EventHandler::EventHandlerItem.new(:event=>'bob') )
280
284
  }.to raise_error %{Missing parts! {"event":"bob"}}
281
285
  end
282
286
 
283
287
  it "raises on name without event" do
284
288
  expect {
285
- @srv.mkname( {:service=>'bob'} )
289
+ @srv.mkname( MrMurano::EventHandler::EventHandlerItem.new(:service=>'bob') )
286
290
  }.to raise_error %{Missing parts! {"service":"bob"}}
287
291
  end
288
292
  end
@@ -334,13 +338,15 @@ end
334
338
  tio.close
335
339
 
336
340
  ret = @srv.toRemoteItem(nil, tio.path)
337
- expect(ret).to eq({:service=>'device',
338
- :event=>'datapoint',
339
- :line=>1,
340
- :line_end=>3,
341
- :local_path=>Pathname.new(tio.path),
342
- :script=>%{--#EVENT device datapoint\nTsdb.write{tags={sn='1'},metrics={[data.alias]=data.value[2]}}\n},
343
- })
341
+ expect(ret).to eq(
342
+ MrMurano::EventHandler::EventHandlerItem.new(
343
+ :service=>'device',
344
+ :event=>'datapoint',
345
+ :line=>1,
346
+ :line_end=>3,
347
+ :local_path=>Pathname.new(tio.path),
348
+ :script=>%{--#EVENT device datapoint\nTsdb.write{tags={sn='1'},metrics={[data.alias]=data.value[2]}}\n},
349
+ ))
344
350
  end
345
351
  end
346
352