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/lib/MrMurano/makePretty.rb
CHANGED
@@ -1,20 +1,27 @@
|
|
1
|
+
# Last Modified: 2017.08.20 /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 'date'
|
2
9
|
require 'json'
|
3
10
|
require 'highline'
|
4
11
|
|
5
12
|
module MrMurano
|
6
13
|
module Pretties
|
7
|
-
|
8
|
-
HighLine::Style.new(:name=>:on_aliceblue, :code=>"\e[48;5;231m", :rgb=>[240, 248, 255])
|
14
|
+
HighLine::Style.new(name: :on_aliceblue, code: "\e[48;5;231m", rgb: [240, 248, 255])
|
9
15
|
PRETTIES_COLORSCHEME = HighLine::ColorScheme.new do |cs|
|
10
|
-
cs[:subject] = [
|
16
|
+
cs[:subject] = %i[red on_aliceblue]
|
11
17
|
cs[:timestamp] = [:blue]
|
12
18
|
cs[:json] = [:magenta]
|
13
19
|
end
|
14
20
|
HighLine.color_scheme = PRETTIES_COLORSCHEME
|
15
21
|
|
22
|
+
# rubocop:disable Style/MethodName: "Use snake_case for method names."
|
16
23
|
def self.makeJsonPretty(data, options)
|
17
|
-
if options.pretty
|
24
|
+
if options.pretty
|
18
25
|
ret = JSON.pretty_generate(data).to_s
|
19
26
|
ret[0] = HighLine.color(ret[0], :json)
|
20
27
|
ret[-1] = HighLine.color(ret[-1], :json)
|
@@ -31,9 +38,9 @@ module MrMurano
|
|
31
38
|
out += HighLine.color("#{line[:type] || '--'} ".upcase, :subject)
|
32
39
|
out += HighLine.color("[#{line[:subject] || ''}]", :subject)
|
33
40
|
out += ' '
|
34
|
-
if line.
|
35
|
-
if line[:timestamp].
|
36
|
-
if options.localtime
|
41
|
+
if line.key?(:timestamp)
|
42
|
+
if line[:timestamp].is_a? Numeric
|
43
|
+
if options.localtime
|
37
44
|
curtime = Time.at(line[:timestamp]).localtime.to_datetime.iso8601(3)
|
38
45
|
else
|
39
46
|
curtime = Time.at(line[:timestamp]).gmtime.to_datetime.iso8601(3)
|
@@ -46,11 +53,11 @@ module MrMurano
|
|
46
53
|
end
|
47
54
|
out += HighLine.color(curtime, :timestamp)
|
48
55
|
out += ":\n"
|
49
|
-
if line.
|
56
|
+
if line.key?(:data)
|
50
57
|
data = line[:data]
|
51
58
|
|
52
|
-
if data.
|
53
|
-
if data.
|
59
|
+
if data.is_a?(Hash)
|
60
|
+
if data.key?(:request) && data.key?(:response)
|
54
61
|
out += "---------\nrequest:"
|
55
62
|
out += makeJsonPretty(data[:request], options)
|
56
63
|
|
@@ -71,7 +78,6 @@ module MrMurano
|
|
71
78
|
end
|
72
79
|
out
|
73
80
|
end
|
74
|
-
|
75
81
|
end
|
76
82
|
end
|
77
|
-
|
83
|
+
|
data/lib/MrMurano/progress.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Last Modified: 2017.08.
|
1
|
+
# Last Modified: 2017.08.22 /coding: utf-8
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
# Copyright © 2016-2017 Exosite LLC.
|
@@ -32,6 +32,13 @@ module MrMurano
|
|
32
32
|
'▗',
|
33
33
|
].freeze
|
34
34
|
|
35
|
+
EXO_QUADRANTS_7 = [
|
36
|
+
'-',
|
37
|
+
'\\',
|
38
|
+
'|',
|
39
|
+
'/',
|
40
|
+
].freeze
|
41
|
+
|
35
42
|
def whirly_start(msg)
|
36
43
|
if $cfg['tool.verbose']
|
37
44
|
whirly_pause if @whirly_users > 0
|
@@ -54,7 +61,7 @@ module MrMurano
|
|
54
61
|
|
55
62
|
def whirly_show
|
56
63
|
Whirly.start(
|
57
|
-
spinner: EXO_QUADRANTS,
|
64
|
+
spinner: $cfg['tool.ascii'] && EXO_QUADRANTS_7 || EXO_QUADRANTS,
|
58
65
|
status: @whirly_msg,
|
59
66
|
append_newline: false,
|
60
67
|
#remove_after_stop: false,
|
data/lib/MrMurano/verbosing.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Last Modified: 2017.08.
|
1
|
+
# Last Modified: 2017.08.23 /coding: utf-8
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
# Copyright © 2016-2017 Exosite LLC.
|
@@ -149,7 +149,7 @@ module MrMurano
|
|
149
149
|
return true
|
150
150
|
end
|
151
151
|
confirmed = MrMurano::Verbose.ask_yes_no(
|
152
|
-
"Really delete
|
152
|
+
"Really delete #{MrMurano::Verbose.fancy_ticks(name)}? [y/N] ", false
|
153
153
|
)
|
154
154
|
MrMurano::Verbose.warning(exit_msg) if !confirmed && exit_msg
|
155
155
|
if block_given?
|
@@ -172,6 +172,18 @@ module MrMurano
|
|
172
172
|
MrMurano::Verbose.pluralize?(word, count)
|
173
173
|
end
|
174
174
|
|
175
|
+
def self.fancy_ticks(obj)
|
176
|
+
if $cfg.nil? || $cfg['tool.ascii']
|
177
|
+
"'#{obj}'"
|
178
|
+
else
|
179
|
+
"‘#{obj}’"
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
def fancy_ticks(obj)
|
184
|
+
MrMurano::Verbose.fancy_ticks(obj)
|
185
|
+
end
|
186
|
+
|
175
187
|
# 2017-07-01: Whirly wrappers. Maybe delete someday
|
176
188
|
# (after replacing all MrMurano::Verbose.whirly_*
|
177
189
|
# with MrMurano::Progress.whirly_*).
|
data/lib/MrMurano/version.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Last Modified: 2017.08.
|
1
|
+
# Last Modified: 2017.08.23 /coding: utf-8
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
# Copyright © 2016-2017 Exosite LLC.
|
@@ -26,7 +26,7 @@ module MrMurano
|
|
26
26
|
# '3.0.0-beta.2' is changed to '3.0.0.pre.beta.2'
|
27
27
|
# which breaks our build (which expects the version to match herein).
|
28
28
|
# So stick to using the '.pre.X' syntax, which ruby/gems knows.
|
29
|
-
VERSION = '3.0.
|
29
|
+
VERSION = '3.0.1'
|
30
30
|
EXE_NAME = File.basename($PROGRAM_NAME)
|
31
31
|
SIGN_UP_URL = 'https://exosite.com/signup/'
|
32
32
|
end
|
data/spec/GatewayDevice_spec.rb
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
# Last Modified: 2017.08.23 /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 'fileutils'
|
2
9
|
require 'MrMurano/version'
|
3
10
|
require 'MrMurano/Gateway'
|
@@ -25,31 +32,33 @@ RSpec.describe MrMurano::Gateway::Device do
|
|
25
32
|
context "listing" do
|
26
33
|
it "lists" do
|
27
34
|
body = {
|
28
|
-
:
|
29
|
-
:
|
30
|
-
[{:
|
31
|
-
:
|
32
|
-
:
|
33
|
-
:
|
34
|
-
:
|
35
|
-
:
|
36
|
-
:
|
37
|
-
:
|
38
|
-
:
|
39
|
-
:
|
40
|
-
{:
|
41
|
-
:
|
42
|
-
:
|
43
|
-
:
|
44
|
-
:
|
45
|
-
:
|
46
|
-
:
|
47
|
-
:
|
48
|
-
:
|
49
|
-
:
|
35
|
+
mayLoadMore: false,
|
36
|
+
devices:
|
37
|
+
[{identity: "58",
|
38
|
+
auth: {type: "cik"},
|
39
|
+
state: {},
|
40
|
+
locked: false,
|
41
|
+
reprovision: false,
|
42
|
+
devmode: false,
|
43
|
+
lastip: "",
|
44
|
+
lastseen: 1487021743864000,
|
45
|
+
status: "provisioned",
|
46
|
+
online: false},
|
47
|
+
{identity: "56",
|
48
|
+
auth: {type: "cik"},
|
49
|
+
state: {},
|
50
|
+
locked: false,
|
51
|
+
reprovision: false,
|
52
|
+
devmode: false,
|
53
|
+
lastip: "",
|
54
|
+
lastseen: 1487021650584000,
|
55
|
+
status: "provisioned",
|
56
|
+
online: false},
|
50
57
|
]}
|
51
|
-
stub_request(
|
52
|
-
|
58
|
+
stub_request(
|
59
|
+
:get,
|
60
|
+
"https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identity/"
|
61
|
+
).to_return(body: body.to_json)
|
53
62
|
|
54
63
|
ret = @gw.list
|
55
64
|
expect(ret).to eq(body)
|
@@ -57,22 +66,24 @@ RSpec.describe MrMurano::Gateway::Device do
|
|
57
66
|
|
58
67
|
it "lists with limit" do
|
59
68
|
body = {
|
60
|
-
:
|
61
|
-
:
|
62
|
-
[{:
|
63
|
-
:
|
64
|
-
:
|
65
|
-
:
|
66
|
-
:
|
67
|
-
:
|
68
|
-
:
|
69
|
-
:
|
70
|
-
:
|
71
|
-
:
|
69
|
+
mayLoadMore: false,
|
70
|
+
devices:
|
71
|
+
[{identity: "58",
|
72
|
+
auth: {type: "cik"},
|
73
|
+
state: {},
|
74
|
+
locked: false,
|
75
|
+
reprovision: false,
|
76
|
+
devmode: false,
|
77
|
+
lastip: "",
|
78
|
+
lastseen: 1487021743864000,
|
79
|
+
status: "provisioned",
|
80
|
+
online: false},
|
72
81
|
]}
|
73
|
-
stub_request(
|
74
|
-
|
75
|
-
|
82
|
+
stub_request(
|
83
|
+
:get,
|
84
|
+
"https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identity/"
|
85
|
+
).with(query: {limit: '1'}
|
86
|
+
).to_return(body: body.to_json)
|
76
87
|
|
77
88
|
ret = @gw.list(1)
|
78
89
|
expect(ret).to eq(body)
|
@@ -80,22 +91,24 @@ RSpec.describe MrMurano::Gateway::Device do
|
|
80
91
|
|
81
92
|
it "lists with before" do
|
82
93
|
body = {
|
83
|
-
:
|
84
|
-
:
|
85
|
-
[{:
|
86
|
-
:
|
87
|
-
:
|
88
|
-
:
|
89
|
-
:
|
90
|
-
:
|
91
|
-
:
|
92
|
-
:
|
93
|
-
:
|
94
|
-
:
|
94
|
+
mayLoadMore: false,
|
95
|
+
devices:
|
96
|
+
[{identity: "58",
|
97
|
+
auth: {type: "cik"},
|
98
|
+
state: {},
|
99
|
+
locked: false,
|
100
|
+
reprovision: false,
|
101
|
+
devmode: false,
|
102
|
+
lastip: "",
|
103
|
+
lastseen: 1487021743864000,
|
104
|
+
status: "provisioned",
|
105
|
+
online: false},
|
95
106
|
]}
|
96
|
-
stub_request(
|
97
|
-
|
98
|
-
|
107
|
+
stub_request(
|
108
|
+
:get,
|
109
|
+
"https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identity/"
|
110
|
+
).with(query: { limit: '1', before: '1487021743864000' }
|
111
|
+
).to_return(body: body.to_json)
|
99
112
|
|
100
113
|
ret = @gw.list(1, 1487021743864000)
|
101
114
|
expect(ret).to eq(body)
|
@@ -104,18 +117,20 @@ RSpec.describe MrMurano::Gateway::Device do
|
|
104
117
|
|
105
118
|
it "fetches one" do
|
106
119
|
body = {
|
107
|
-
:
|
108
|
-
:
|
109
|
-
:
|
110
|
-
:
|
111
|
-
:
|
112
|
-
:
|
113
|
-
:
|
114
|
-
:
|
115
|
-
:
|
116
|
-
:
|
117
|
-
stub_request(
|
118
|
-
|
120
|
+
identity: "58",
|
121
|
+
auth: {type: "cik"},
|
122
|
+
state: {},
|
123
|
+
locked: false,
|
124
|
+
reprovision: false,
|
125
|
+
devmode: false,
|
126
|
+
lastip: "",
|
127
|
+
lastseen: 1487021743864000,
|
128
|
+
status: "provisioned",
|
129
|
+
online: false}
|
130
|
+
stub_request(
|
131
|
+
:get,
|
132
|
+
"https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identity/58"
|
133
|
+
).to_return(body: body.to_json)
|
119
134
|
|
120
135
|
ret = @gw.fetch(58)
|
121
136
|
expect(ret).to eq(body)
|
@@ -123,18 +138,20 @@ RSpec.describe MrMurano::Gateway::Device do
|
|
123
138
|
|
124
139
|
it "enables one" do
|
125
140
|
body = {
|
126
|
-
:
|
127
|
-
:
|
128
|
-
:
|
129
|
-
:
|
130
|
-
:
|
131
|
-
:
|
132
|
-
:
|
133
|
-
:
|
134
|
-
:
|
135
|
-
:
|
136
|
-
stub_request(
|
137
|
-
|
141
|
+
identity: "58",
|
142
|
+
auth: {type: "cik"},
|
143
|
+
state: {},
|
144
|
+
locked: false,
|
145
|
+
reprovision: false,
|
146
|
+
devmode: false,
|
147
|
+
lastip: "",
|
148
|
+
lastseen: 1487021743864000,
|
149
|
+
status: "provisioned",
|
150
|
+
online: false}
|
151
|
+
stub_request(
|
152
|
+
:put,
|
153
|
+
"https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identity/58"
|
154
|
+
).to_return(body: body.to_json)
|
138
155
|
|
139
156
|
ret = @gw.enable(58)
|
140
157
|
expect(ret).to eq(body)
|
@@ -142,58 +159,64 @@ RSpec.describe MrMurano::Gateway::Device do
|
|
142
159
|
|
143
160
|
it "enables with options" do
|
144
161
|
body = {
|
145
|
-
:
|
146
|
-
:
|
147
|
-
:
|
148
|
-
:
|
149
|
-
:
|
150
|
-
:
|
151
|
-
:
|
152
|
-
:
|
153
|
-
:
|
154
|
-
:
|
155
|
-
stub_request(
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
162
|
+
identity: "58",
|
163
|
+
auth: {type: "cik"},
|
164
|
+
state: {},
|
165
|
+
locked: false,
|
166
|
+
reprovision: false,
|
167
|
+
devmode: false,
|
168
|
+
lastip: "",
|
169
|
+
lastseen: 1487021743864000,
|
170
|
+
status: "provisioned",
|
171
|
+
online: false}
|
172
|
+
stub_request(
|
173
|
+
:put,
|
174
|
+
"https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identity/58"
|
175
|
+
). with(body: { auth: { expire: 123456, type: :certificate }, locked: false }.to_json
|
176
|
+
).to_return(body: body.to_json)
|
177
|
+
|
178
|
+
ret = @gw.enable(58, type: :certificate, expire: '123456')
|
160
179
|
expect(ret).to eq(body)
|
161
180
|
end
|
162
181
|
|
163
182
|
it "enables with extra options" do
|
164
183
|
body = {
|
165
|
-
:
|
166
|
-
:
|
167
|
-
:
|
168
|
-
:
|
169
|
-
:
|
170
|
-
:
|
171
|
-
:
|
172
|
-
:
|
173
|
-
:
|
174
|
-
:
|
175
|
-
stub_request(
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
184
|
+
identity: "58",
|
185
|
+
auth: {type: "cik"},
|
186
|
+
state: {},
|
187
|
+
locked: false,
|
188
|
+
reprovision: false,
|
189
|
+
devmode: false,
|
190
|
+
lastip: "",
|
191
|
+
lastseen: 1487021743864000,
|
192
|
+
status: "provisioned",
|
193
|
+
online: false}
|
194
|
+
stub_request(
|
195
|
+
:put,
|
196
|
+
"https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identity/58"
|
197
|
+
).with(body: {auth: { expire: 123456, type: :certificate }, locked: false }.to_json
|
198
|
+
).to_return(body: body.to_json)
|
199
|
+
|
200
|
+
ret = @gw.enable(58, go: :blueteam, type: :certificate, expire: 123456, bob: :built)
|
180
201
|
expect(ret).to eq(body)
|
181
202
|
end
|
182
203
|
|
183
204
|
it "removes one" do
|
184
205
|
body = {
|
185
|
-
:
|
186
|
-
:
|
187
|
-
:
|
188
|
-
:
|
189
|
-
:
|
190
|
-
:
|
191
|
-
:
|
192
|
-
:
|
193
|
-
:
|
194
|
-
:
|
195
|
-
stub_request(
|
196
|
-
|
206
|
+
identity: "58",
|
207
|
+
auth: {type: "cik"},
|
208
|
+
state: {},
|
209
|
+
locked: false,
|
210
|
+
reprovision: false,
|
211
|
+
devmode: false,
|
212
|
+
lastip: "",
|
213
|
+
lastseen: 1487021743864000,
|
214
|
+
status: "provisioned",
|
215
|
+
online: false}
|
216
|
+
stub_request(
|
217
|
+
:delete,
|
218
|
+
"https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identity/58"
|
219
|
+
).to_return(body: body.to_json)
|
197
220
|
|
198
221
|
ret = @gw.remove(58)
|
199
222
|
expect(ret).to eq(body)
|
@@ -205,20 +228,26 @@ RSpec.describe MrMurano::Gateway::Device do
|
|
205
228
|
allow(@bgw).to receive(:token).and_return("TTTTTTTTTT")
|
206
229
|
expect(MrMurano::Gateway::GweBase).to receive(:new).and_return(@bgw)
|
207
230
|
allow(@gw).to receive(:token).and_return("TTTTTTTTTT")
|
208
|
-
stub_request(
|
209
|
-
|
231
|
+
stub_request(
|
232
|
+
:get,
|
233
|
+
"https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2"
|
234
|
+
).to_return(body: { fqdn: "xxxxx.m2.exosite-staging.io" }.to_json)
|
210
235
|
end
|
211
236
|
it "succeeds" do
|
212
|
-
stub_request(
|
213
|
-
|
237
|
+
stub_request(
|
238
|
+
:post,
|
239
|
+
"https://xxxxx.m2.exosite-staging.io/provision/activate"
|
240
|
+
).to_return(body: 'XXXXXXXX')
|
214
241
|
|
215
242
|
ret = @gw.activate(58)
|
216
243
|
expect(ret).to eq('XXXXXXXX')
|
217
244
|
end
|
218
245
|
|
219
246
|
it "was already activated" do
|
220
|
-
stub_request(
|
221
|
-
|
247
|
+
stub_request(
|
248
|
+
:post,
|
249
|
+
"https://xxxxx.m2.exosite-staging.io/provision/activate"
|
250
|
+
).to_return(status: 409)
|
222
251
|
|
223
252
|
saved = $stderr
|
224
253
|
$stderr = StringIO.new
|
@@ -232,8 +261,10 @@ RSpec.describe MrMurano::Gateway::Device do
|
|
232
261
|
end
|
233
262
|
|
234
263
|
it "wasn't enabled" do
|
235
|
-
stub_request(
|
236
|
-
|
264
|
+
stub_request(
|
265
|
+
:post,
|
266
|
+
"https://xxxxx.m2.exosite-staging.io/provision/activate"
|
267
|
+
).to_return(status: 404)
|
237
268
|
|
238
269
|
saved = $stderr
|
239
270
|
$stderr = StringIO.new
|
@@ -247,8 +278,10 @@ RSpec.describe MrMurano::Gateway::Device do
|
|
247
278
|
context "enables batch" do
|
248
279
|
it "enables from cvs" do
|
249
280
|
File.open('ids.csv', 'w') {|io| io << "ID\n1\n2\n3\n4\n5"}
|
250
|
-
stub_request(
|
251
|
-
|
281
|
+
stub_request(
|
282
|
+
:post,
|
283
|
+
'https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identities'
|
284
|
+
).with(headers: { 'Content-Type' => %r{^multipart/form-data.*} }) do |request|
|
252
285
|
request.body.to_s =~ %r{Content-Type: text/csv\r\n\r\nID\r?\n1\r?\n2\r?\n3\r?\n4\r?\n5}
|
253
286
|
end
|
254
287
|
@gw.enable_batch('ids.csv')
|
@@ -260,8 +293,10 @@ RSpec.describe MrMurano::Gateway::Device do
|
|
260
293
|
|
261
294
|
it "but file is not text" do
|
262
295
|
File.open('ids.csv', 'wb') {|io| io << "\0\0\0\0"}
|
263
|
-
stub_request(
|
264
|
-
|
296
|
+
stub_request(
|
297
|
+
:post,
|
298
|
+
'https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identities'
|
299
|
+
).to_return(status: 400, body: "CSV file format invalid")
|
265
300
|
saved = $stderr
|
266
301
|
$stderr = StringIO.new
|
267
302
|
@gw.enable_batch('ids.csv')
|
@@ -271,10 +306,12 @@ RSpec.describe MrMurano::Gateway::Device do
|
|
271
306
|
|
272
307
|
it "but file is missing header" do
|
273
308
|
File.open('ids.csv', 'w') {|io| io << "1\n2\n3\n4\n5"}
|
274
|
-
stub_request(
|
275
|
-
|
309
|
+
stub_request(
|
310
|
+
:post,
|
311
|
+
'https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identities'
|
312
|
+
).with(headers: { 'Content-Type' => %r{^multipart/form-data.*} }) do |request|
|
276
313
|
request.body.to_s =~ %r{Content-Type: text/csv\r\n\r\n1\r?\n2\r?\n3\r?\n4\r?\n5}
|
277
|
-
end.to_return(:
|
314
|
+
end.to_return(status: 400, body: "CSV file format invalid")
|
278
315
|
saved = $stderr
|
279
316
|
$stderr = StringIO.new
|
280
317
|
@gw.enable_batch('ids.csv')
|
@@ -284,9 +321,11 @@ RSpec.describe MrMurano::Gateway::Device do
|
|
284
321
|
end
|
285
322
|
|
286
323
|
it "reads state" do
|
287
|
-
body = {:
|
288
|
-
stub_request(
|
289
|
-
|
324
|
+
body = {bob: {reported: "9", set: "9", timestamp: 1487021046160363}}
|
325
|
+
stub_request(
|
326
|
+
:get,
|
327
|
+
'https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identity/56/state'
|
328
|
+
).to_return(body: body.to_json)
|
290
329
|
|
291
330
|
ret = @gw.read(56)
|
292
331
|
expect(ret).to eq(body)
|
@@ -294,28 +333,30 @@ RSpec.describe MrMurano::Gateway::Device do
|
|
294
333
|
|
295
334
|
context "writes state" do
|
296
335
|
it "succeeds" do
|
297
|
-
body = {:
|
298
|
-
stub_request(
|
299
|
-
|
336
|
+
body = {bob: "fuzz"}
|
337
|
+
stub_request(
|
338
|
+
:patch,
|
339
|
+
'https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identity/56/state'
|
340
|
+
).with(body: body.to_json)
|
300
341
|
|
301
|
-
@gw.write(56, :
|
342
|
+
@gw.write(56, bob: 'fuzz')
|
302
343
|
end
|
303
344
|
|
304
345
|
it "fails" do
|
305
|
-
body = {:
|
306
|
-
stub_request(
|
307
|
-
|
308
|
-
|
346
|
+
body = {bob: "fuzz"}
|
347
|
+
stub_request(
|
348
|
+
:patch,
|
349
|
+
'https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identity/56/state'
|
350
|
+
).with(body: body.to_json
|
351
|
+
).to_return(status: 400, body: 'Value is not settable')
|
309
352
|
|
310
353
|
saved = $stderr
|
311
354
|
$stderr = StringIO.new
|
312
355
|
|
313
|
-
@gw.write(56, :
|
356
|
+
@gw.write(56, bob: 'fuzz')
|
314
357
|
expect($stderr.string).to eq("\e[31mRequest Failed: 400: Value is not settable\e[0m\n")
|
315
358
|
$stderr = saved
|
316
359
|
end
|
317
360
|
end
|
318
|
-
|
319
361
|
end
|
320
362
|
|
321
|
-
# vim: set ai et sw=2 ts=2 :
|