MuranoCLI 2.2.4 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. checksums.yaml +4 -4
  2. data/.agignore +3 -0
  3. data/.gitignore +18 -1
  4. data/.rubocop.yml +222 -0
  5. data/.trustme.sh +185 -0
  6. data/.trustme.vim +24 -0
  7. data/Gemfile +23 -4
  8. data/LICENSE.txt +1 -1
  9. data/MuranoCLI.gemspec +43 -8
  10. data/README.markdown +9 -11
  11. data/Rakefile +187 -143
  12. data/TODO.taskpaper +2 -2
  13. data/bin/murano +51 -52
  14. data/docs/basic_example.rst +436 -0
  15. data/docs/completions/murano_completion-bash +3484 -0
  16. data/docs/demo.md +32 -32
  17. data/docs/develop.rst +391 -0
  18. data/lib/MrMurano.rb +21 -7
  19. data/lib/MrMurano/Account.rb +159 -174
  20. data/lib/MrMurano/Business.rb +381 -0
  21. data/lib/MrMurano/Config-Migrate.rb +32 -26
  22. data/lib/MrMurano/Config.rb +407 -128
  23. data/lib/MrMurano/Content.rb +191 -0
  24. data/lib/MrMurano/Gateway.rb +489 -0
  25. data/lib/MrMurano/Keystore.rb +48 -0
  26. data/lib/MrMurano/Passwords.rb +103 -0
  27. data/lib/MrMurano/ProjectFile.rb +121 -79
  28. data/lib/MrMurano/ReCommander.rb +114 -10
  29. data/lib/MrMurano/Setting.rb +90 -0
  30. data/lib/MrMurano/Solution-ServiceConfig.rb +89 -45
  31. data/lib/MrMurano/Solution-Services.rb +461 -166
  32. data/lib/MrMurano/Solution-Users.rb +70 -31
  33. data/lib/MrMurano/Solution.rb +372 -13
  34. data/lib/MrMurano/SolutionId.rb +73 -0
  35. data/lib/MrMurano/SyncRoot.rb +137 -0
  36. data/lib/MrMurano/SyncUpDown.rb +594 -284
  37. data/lib/MrMurano/Webservice-Cors.rb +71 -0
  38. data/lib/MrMurano/Webservice-Endpoint.rb +234 -0
  39. data/lib/MrMurano/Webservice-File.rb +193 -0
  40. data/lib/MrMurano/Webservice.rb +51 -0
  41. data/lib/MrMurano/commands.rb +18 -15
  42. data/lib/MrMurano/commands/business.rb +300 -6
  43. data/lib/MrMurano/commands/completion-bash.erb +166 -0
  44. data/lib/MrMurano/commands/{zshcomplete.erb → completion-zsh.erb} +0 -0
  45. data/lib/MrMurano/commands/completion.rb +76 -39
  46. data/lib/MrMurano/commands/config.rb +108 -44
  47. data/lib/MrMurano/commands/content.rb +115 -72
  48. data/lib/MrMurano/commands/cors.rb +29 -14
  49. data/lib/MrMurano/commands/devices.rb +286 -0
  50. data/lib/MrMurano/commands/domain.rb +52 -12
  51. data/lib/MrMurano/commands/gb.rb +24 -9
  52. data/lib/MrMurano/commands/globals.rb +64 -0
  53. data/lib/MrMurano/commands/init.rb +377 -155
  54. data/lib/MrMurano/commands/keystore.rb +92 -82
  55. data/lib/MrMurano/commands/link.rb +300 -0
  56. data/lib/MrMurano/commands/login.rb +74 -11
  57. data/lib/MrMurano/commands/logs.rb +63 -32
  58. data/lib/MrMurano/commands/mock.rb +57 -29
  59. data/lib/MrMurano/commands/password.rb +57 -39
  60. data/lib/MrMurano/commands/postgresql.rb +127 -94
  61. data/lib/MrMurano/commands/settings.rb +203 -0
  62. data/lib/MrMurano/commands/show.rb +79 -38
  63. data/lib/MrMurano/commands/solution.rb +423 -5
  64. data/lib/MrMurano/commands/solution_picker.rb +547 -0
  65. data/lib/MrMurano/commands/status.rb +195 -61
  66. data/lib/MrMurano/commands/sync.rb +78 -39
  67. data/lib/MrMurano/commands/timeseries.rb +71 -55
  68. data/lib/MrMurano/commands/tsdb.rb +113 -87
  69. data/lib/MrMurano/commands/usage.rb +57 -15
  70. data/lib/MrMurano/hash.rb +100 -10
  71. data/lib/MrMurano/http.rb +187 -43
  72. data/lib/MrMurano/makePretty.rb +16 -14
  73. data/lib/MrMurano/optparse.rb +2178 -0
  74. data/lib/MrMurano/progress.rb +138 -0
  75. data/lib/MrMurano/schema/resource-v1.0.0.yaml +32 -0
  76. data/lib/MrMurano/template/projectFile.murano.erb +16 -13
  77. data/lib/MrMurano/verbosing.rb +166 -29
  78. data/lib/MrMurano/version.rb +30 -1
  79. data/spec/Account-Passwords_spec.rb +21 -4
  80. data/spec/Account_spec.rb +69 -146
  81. data/spec/Business_spec.rb +290 -0
  82. data/spec/ConfigFile_spec.rb +1 -0
  83. data/spec/ConfigMigrate_spec.rb +12 -8
  84. data/spec/Config_spec.rb +40 -34
  85. data/spec/Content_spec.rb +363 -0
  86. data/spec/GatewayBase_spec.rb +54 -0
  87. data/spec/GatewayDevice_spec.rb +321 -0
  88. data/spec/GatewayResource_spec.rb +266 -0
  89. data/spec/GatewaySettings_spec.rb +120 -0
  90. data/spec/Http_spec.rb +18 -8
  91. data/spec/Mock_spec.rb +2 -2
  92. data/spec/ProjectFile_spec.rb +25 -14
  93. data/spec/Setting_spec.rb +110 -0
  94. data/spec/Solution-ServiceConfig_spec.rb +44 -5
  95. data/spec/Solution-ServiceEventHandler_spec.rb +23 -14
  96. data/spec/Solution-ServiceModules_spec.rb +47 -37
  97. data/spec/Solution-UsersRoles_spec.rb +10 -8
  98. data/spec/Solution_spec.rb +17 -8
  99. data/spec/SyncRoot_spec.rb +46 -20
  100. data/spec/SyncUpDown_spec.rb +437 -201
  101. data/spec/Verbosing_spec.rb +12 -4
  102. data/spec/{Solution-Cors_spec.rb → Webservice-Cors_spec.rb} +23 -20
  103. data/spec/{Solution-Endpoint_spec.rb → Webservice-Endpoint_spec.rb} +43 -41
  104. data/spec/{Solution-File_spec.rb → Webservice-File_spec.rb} +44 -33
  105. data/spec/Webservice-Setting_spec.rb +89 -0
  106. data/spec/_workspace.rb +4 -4
  107. data/spec/cmd_business_spec.rb +9 -4
  108. data/spec/cmd_common.rb +44 -1
  109. data/spec/cmd_content_spec.rb +43 -17
  110. data/spec/cmd_cors_spec.rb +4 -4
  111. data/spec/cmd_device_spec.rb +61 -16
  112. data/spec/cmd_domain_spec.rb +29 -6
  113. data/spec/cmd_init_spec.rb +281 -126
  114. data/spec/cmd_keystore_spec.rb +3 -3
  115. data/spec/cmd_link_spec.rb +98 -0
  116. data/spec/cmd_password_spec.rb +1 -1
  117. data/spec/cmd_setting_application_spec.rb +260 -0
  118. data/spec/cmd_setting_product_spec.rb +220 -0
  119. data/spec/cmd_status_spec.rb +223 -114
  120. data/spec/cmd_syncdown_spec.rb +115 -35
  121. data/spec/cmd_syncup_spec.rb +68 -15
  122. data/spec/cmd_usage_spec.rb +35 -8
  123. data/spec/fixtures/dumped_config +6 -4
  124. data/spec/fixtures/gateway_resource_files/resources.notyaml +12 -0
  125. data/spec/fixtures/gateway_resource_files/resources.yaml +13 -0
  126. data/spec/fixtures/gateway_resource_files/resources_invalid.yaml +13 -0
  127. data/spec/fixtures/mrmuranorc_deleted_bob +0 -2
  128. data/spec/fixtures/product_spec_files/lightbulb.yaml +20 -13
  129. data/spec/fixtures/{syncable_content → syncable_conflict}/services/devdata.lua +1 -1
  130. data/spec/fixtures/{syncable_content → syncable_conflict}/services/timers.lua +0 -0
  131. data/spec/spec_helper.rb +5 -0
  132. metadata +262 -171
  133. data/bin/mr +0 -8
  134. data/lib/MrMurano/Product-1P-Device.rb +0 -145
  135. data/lib/MrMurano/Product-Resources.rb +0 -205
  136. data/lib/MrMurano/Product.rb +0 -358
  137. data/lib/MrMurano/Solution-Cors.rb +0 -47
  138. data/lib/MrMurano/Solution-Endpoint.rb +0 -191
  139. data/lib/MrMurano/Solution-File.rb +0 -166
  140. data/lib/MrMurano/commands/assign.rb +0 -57
  141. data/lib/MrMurano/commands/businessList.rb +0 -45
  142. data/lib/MrMurano/commands/product.rb +0 -14
  143. data/lib/MrMurano/commands/productCreate.rb +0 -39
  144. data/lib/MrMurano/commands/productDelete.rb +0 -33
  145. data/lib/MrMurano/commands/productDevice.rb +0 -87
  146. data/lib/MrMurano/commands/productDeviceIdCmds.rb +0 -89
  147. data/lib/MrMurano/commands/productList.rb +0 -45
  148. data/lib/MrMurano/commands/productWrite.rb +0 -27
  149. data/lib/MrMurano/commands/solutionCreate.rb +0 -41
  150. data/lib/MrMurano/commands/solutionDelete.rb +0 -34
  151. data/lib/MrMurano/commands/solutionList.rb +0 -45
  152. data/spec/ProductBase_spec.rb +0 -113
  153. data/spec/ProductContent_spec.rb +0 -162
  154. data/spec/ProductResources_spec.rb +0 -329
  155. data/spec/Product_1P_Device_spec.rb +0 -202
  156. data/spec/Product_1P_RPC_spec.rb +0 -175
  157. data/spec/Product_spec.rb +0 -153
  158. data/spec/Solution-ServiceDevice_spec.rb +0 -176
  159. data/spec/cmd_assign_spec.rb +0 -51
@@ -1,45 +0,0 @@
1
- require 'MrMurano/Account'
2
- require 'terminal-table'
3
-
4
- command 'solution list' do |c|
5
- c.syntax = %{murano solution list [options]}
6
- c.description = %{List solutions}
7
- c.option '--idonly', 'Only return the ids'
8
- c.option '--[no-]all', 'Show all fields'
9
- c.option '-o', '--output FILE', %{Download to file instead of STDOUT}
10
-
11
- c.action do |args, options|
12
- acc = MrMurano::Account.new
13
- data = acc.solutions
14
-
15
- io=nil
16
- if options.output then
17
- io = File.open(options.output, 'w')
18
- end
19
-
20
- if options.idonly then
21
- headers = [:apiId]
22
- data = data.map{|row| [row[:apiId]]}
23
- elsif not options.all then
24
- headers = [:apiId, :domain]
25
- data = data.map{|r| [r[:apiId], r[:domain]]}
26
- else
27
- headers = data[0].keys
28
- data = data.map{|r| headers.map{|h| r[h]}}
29
- end
30
-
31
- acc.outf(data, io) do |dd, ios|
32
- if options.idonly then
33
- ios.puts dd.join(' ')
34
- else
35
- acc.tabularize({
36
- :headers=>headers.map{|h| h.to_s},
37
- :rows=>dd
38
- }, ios)
39
- end
40
- end
41
- io.close unless io.nil?
42
- end
43
- end
44
-
45
- # vim: set ai et sw=2 ts=2 :
@@ -1,113 +0,0 @@
1
- require 'MrMurano/version'
2
- require 'MrMurano/Product'
3
- require '_workspace'
4
-
5
- RSpec.describe MrMurano::ProductBase, "#product_base" do
6
- include_context "WORKSPACE"
7
- before(:example) do
8
- $cfg = MrMurano::Config.new
9
- $cfg.load
10
- $project = MrMurano::ProjectFile.new
11
- $project.load
12
- $cfg['net.host'] = 'bizapi.hosted.exosite.io'
13
- $cfg['product.id'] = 'XYZ'
14
-
15
- @prd = MrMurano::ProductBase.new
16
- allow(@prd).to receive(:token).and_return("TTTTTTTTTT")
17
- end
18
-
19
- it "initializes" do
20
- uri = @prd.endPoint('/')
21
- expect(uri.to_s).to eq("https://bizapi.hosted.exosite.io/api:1/product/XYZ/")
22
- end
23
-
24
- it "can get" do
25
- stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/").
26
- with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
27
- 'Content-Type'=>'application/json'}).
28
- to_return(body: "Fooo")
29
-
30
- ret = @prd.get('/')
31
- expect(ret).to eq("Fooo")
32
- end
33
-
34
- it "returns hash when getting empty body" do
35
- stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/").
36
- with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
37
- 'Content-Type'=>'application/json'}).
38
- to_return(body: "")
39
-
40
- ret = @prd.get('/')
41
- expect(ret).to eq({})
42
- end
43
-
44
- it "auto parses JSON responses" do
45
- stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/").
46
- with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
47
- 'Content-Type'=>'application/json'}).
48
- to_return(body: %{{"first": "str", "sec":[1,2,3], "third":{"a":"b"}}})
49
-
50
- ret = @prd.get('/')
51
- expect(ret).to eq({:sec=>[1,2,3],:third=>{:a=>'b'},:first=>'str'})
52
- end
53
-
54
- it "can post nothing" do
55
- stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/").
56
- with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
57
- 'Content-Type'=>'application/json'}).
58
- to_return(body: "")
59
- ret = @prd.post('/')
60
- expect(ret).to eq({})
61
- end
62
-
63
- it "can post json" do
64
- stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/").
65
- with(headers: {'Authorization'=>'token TTTTTTTTTT',
66
- 'Content-Type'=>'application/json'},
67
- body: {:this=>"is", :a=>'test'}).
68
- to_return(body: "")
69
- ret = @prd.post('/', {:this=>"is", :a=>'test'})
70
- expect(ret).to eq({})
71
- end
72
-
73
- it "can post form data" do
74
- stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/").
75
- with(headers: {'Authorization'=>'token TTTTTTTTTT',
76
- 'Content-Type'=>'application/x-www-form-urlencoded'},
77
- body: "this=is&a=test").
78
- to_return(body: "")
79
- ret = @prd.postf('/', {:this=>"is", :a=>'test'})
80
- expect(ret).to eq({})
81
- end
82
-
83
- it "can put nothing" do
84
- stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/").
85
- with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
86
- 'Content-Type'=>'application/json'}).
87
- to_return(body: "")
88
- ret = @prd.put('/')
89
- expect(ret).to eq({})
90
- end
91
-
92
- it "can put json" do
93
- stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/").
94
- with(headers: {'Authorization'=>'token TTTTTTTTTT',
95
- 'Content-Type'=>'application/json'},
96
- body: {:this=>"is", :a=>'test'}).
97
- to_return(body: "")
98
- ret = @prd.put('/', {:this=>"is", :a=>'test'})
99
- expect(ret).to eq({})
100
- end
101
-
102
- it "can delete" do
103
- stub_request(:delete, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/").
104
- with(headers: {'Authorization'=>'token TTTTTTTTTT',
105
- 'Content-Type'=>'application/json'}).
106
- to_return(body: "")
107
- ret = @prd.delete('/')
108
- expect(ret).to eq({})
109
- end
110
-
111
- end
112
-
113
- # vim: set ai et sw=2 ts=2 :
@@ -1,162 +0,0 @@
1
- require 'MrMurano/version'
2
- require 'MrMurano/Config'
3
- require 'MrMurano/Product'
4
- require '_workspace'
5
-
6
- RSpec.describe MrMurano::ProductContent, "#product_content" do
7
- include_context "WORKSPACE"
8
- before(:example) do
9
- $cfg = MrMurano::Config.new
10
- $cfg.load
11
- $project = MrMurano::ProjectFile.new
12
- $project.load
13
- $cfg['net.host'] = 'bizapi.hosted.exosite.io'
14
- $cfg['product.id'] = 'XYZ'
15
-
16
- @prd = MrMurano::ProductContent.new
17
- allow(@prd).to receive(:token).and_return("TTTTTTTTTT")
18
-
19
- @urlroot = "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/provision/manage/content/XYZ"
20
- end
21
-
22
- it "lists nothing" do
23
- stub_request(:get, @urlroot + "/").
24
- with(headers: {'Authorization'=>'token TTTTTTTTTT',
25
- 'Content-Type'=>'application/json'}).
26
- to_return(body: "")
27
-
28
- ret = @prd.list
29
- expect(ret).to eq([])
30
- end
31
-
32
- it "lists something" do
33
- stub_request(:get, @urlroot + "/").
34
- with(headers: {'Authorization'=>'token TTTTTTTTTT',
35
- 'Content-Type'=>'application/json'}).
36
- to_return(body: "one\ntwo\nthree\n")
37
-
38
- ret = @prd.list
39
- expect(ret).to eq(['one','two','three'])
40
- end
41
-
42
- it "lists something for identifier" do
43
- stub_request(:get, @urlroot + "/?sn=12").
44
- with(headers: {'Authorization'=>'token TTTTTTTTTT',
45
- 'Content-Type'=>'application/json'}).
46
- to_return(body: "one\ntwo\nthree\n")
47
-
48
- ret = @prd.list_for('12')
49
- expect(ret).to eq(['one','two','three'])
50
- end
51
-
52
- it "creates an item" do
53
- stub_request(:post, @urlroot + "/").
54
- with(headers: {'Authorization'=>'token TTTTTTTTTT',
55
- 'Content-Type'=>'application/x-www-form-urlencoded'}).
56
- with(body: {'id'=>'testFor', 'meta'=> 'some meta'}).
57
- to_return(status: 205)
58
-
59
- ret = @prd.create("testFor", "some meta")
60
- expect(ret).to eq({})
61
- end
62
-
63
- it "removes an item" do
64
- stub_request(:post, @urlroot + "/").
65
- with(headers: {'Authorization'=>'token TTTTTTTTTT',
66
- 'Content-Type'=>'application/x-www-form-urlencoded'}).
67
- with(body: {'id'=>'testFor', 'delete'=>'true'}).
68
- to_return(status: 205)
69
-
70
- ret = @prd.remove("testFor")
71
- expect(ret).to eq({})
72
- end
73
-
74
- it "gets info for content" do
75
- stub_request(:get, @urlroot + "/testFor").
76
- with(headers: {'Authorization'=>'token TTTTTTTTTT',
77
- 'Content-Type'=>'application/json'}).
78
- to_return(body: "text/plain,42,123456789,test meta,false")
79
-
80
- ret = @prd.info("testFor")
81
- expect(ret).to eq([['text/plain','42','123456789','test meta','false']])
82
- end
83
-
84
- it "gets info for missing content" do
85
- stub_request(:get, @urlroot + "/testFor").
86
- with(headers: {'Authorization'=>'token TTTTTTTTTT',
87
- 'Content-Type'=>'application/json'}).
88
- to_return(status: 404, body: "")
89
-
90
- ret = @prd.info("testFor")
91
- expect(ret).to be_nil
92
- end
93
-
94
- it "removes content" do
95
- stub_request(:delete, @urlroot + "/testFor").
96
- with(headers: {'Authorization'=>'token TTTTTTTTTT',
97
- 'Content-Type'=>'application/json'}).
98
- to_return(status: 205)
99
-
100
- ret = @prd.remove_content("testFor")
101
- expect(ret).to eq({})
102
- end
103
-
104
- it "uploads content data" do
105
- pth = (@testdir + 'spec/fixtures/product_spec_files/lightbulb.yaml').realpath
106
- size = FileTest.size(pth.to_path)
107
- stub_request(:post, @urlroot + "/testFor").
108
- with(headers: {'Authorization'=>'token TTTTTTTTTT',
109
- 'Content-Type'=>/text\/(x-)?yaml/,
110
- 'Content-Length' => size
111
- }).
112
- to_return(status: 205)
113
-
114
- ret = @prd.upload('testFor', pth.to_path)
115
- expect(ret).to eq({})
116
- end
117
-
118
- context "downloads content" do
119
- it "to block" do
120
- stub_request(:get, @urlroot + "/testFor?download=true").
121
- with(headers: {'Authorization'=>'token TTTTTTTTTT',
122
- 'Content-Type'=>'application/json'}).
123
- to_return(body: "short and sweet")
124
-
125
- data = ""
126
- @prd.download('testFor') {|chunk| data << chunk}
127
- expect(data).to eq("short and sweet")
128
- end
129
-
130
- it "to stdout" do
131
- stub_request(:get, @urlroot + "/testFor?download=true").
132
- with(headers: {'Authorization'=>'token TTTTTTTTTT',
133
- 'Content-Type'=>'application/json'}).
134
- to_return(body: "short and sweet")
135
-
136
- begin
137
- old_stdout = $stdout
138
- $stdout = StringIO.new('','w')
139
- @prd.download('testFor')
140
- expect($stdout.string).to eq("short and sweet")
141
- ensure
142
- $stdout = old_stdout
143
- end
144
- end
145
-
146
- it "but error" do
147
- stub_request(:get, @urlroot + "/testFor?download=true").
148
- with(headers: {'Authorization'=>'token TTTTTTTTTT',
149
- 'Content-Type'=>'application/json'}).
150
- to_return(status:404, body: "{}")
151
-
152
- data = ""
153
- expect(@prd).to receive(:error).once
154
- @prd.download('testFor') {|chunk| data << chunk}
155
- expect(data).to eq("")
156
-
157
- end
158
- end
159
-
160
- end
161
-
162
- # vim: set ai et sw=2 ts=2 :
@@ -1,329 +0,0 @@
1
- require 'MrMurano/version'
2
- require 'MrMurano/Config'
3
- require 'MrMurano/Product-Resources'
4
- require '_workspace'
5
-
6
- RSpec.describe MrMurano::ProductResources do
7
- include_context "WORKSPACE"
8
- before(:example) do
9
- $cfg = MrMurano::Config.new
10
- $cfg.load
11
- $project = MrMurano::ProjectFile.new
12
- $project.load
13
- $cfg['net.host'] = 'bizapi.hosted.exosite.io'
14
- $cfg['product.id'] = 'XYZ'
15
- $cfg['product.spec'] = 'XYZ.yaml'
16
-
17
- @prd = MrMurano::ProductResources.new
18
- allow(@prd).to receive(:token).and_return("TTTTTTTTTT")
19
- allow(@prd).to receive(:model_rid).and_return("LLLLLLLLLL")
20
- end
21
-
22
- it "initializes" do
23
- uri = @prd.endPoint('')
24
- expect(uri.to_s).to eq("https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process")
25
- end
26
-
27
- context "queries" do
28
- it "gets info" do
29
- stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
30
- with(body: {:auth=>{:client_id=>"LLLLLLLLLL"},
31
- :calls=>[{:id=>1,
32
- :procedure=>"info",
33
- :arguments=>["LLLLLLLLLL", {}]} ]}).
34
- to_return(body: [{:id=>1, :status=>"ok", :result=>{:comments=>[]}}])
35
-
36
- ret = @prd.info
37
- expect(ret).to eq({:comments=>[]})
38
- end
39
-
40
- it "gets listing" do
41
- stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
42
- with(body: {:auth=>{:client_id=>"LLLLLLLLLL"},
43
- :calls=>[{:id=>1,
44
- :procedure=>"info",
45
- :arguments=>["LLLLLLLLLL", {}]} ]}).
46
- to_return(body: [{:id=>1, :status=>"ok", :result=>{:aliases=>{:abcdefg=>["bob"]}}}])
47
-
48
- ret = @prd.list
49
- expect(ret).to eq([{:alias=>"bob", :rid=>:abcdefg}])
50
- end
51
-
52
- it "gets item" do
53
- stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
54
- with(body: {:auth=>{:client_id=>"LLLLLLLLLL"},
55
- :calls=>[{:id=>1,
56
- :procedure=>"info",
57
- :arguments=>["FFFFFFFFFF", {}]} ]}).
58
- to_return(body: [{:id=>1, :status=>"ok", :result=>{:comments=>[]}}])
59
-
60
- ret = @prd.fetch("FFFFFFFFFF")
61
- expect(ret).to eq({:comments=>[]})
62
- end
63
- end
64
-
65
- context "Modifying" do
66
- it "Drops RID" do
67
- stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
68
- with(body: {:auth=>{:client_id=>"LLLLLLLLLL"},
69
- :calls=>[{:id=>1,
70
- :procedure=>"drop",
71
- :arguments=>["abcdefg"]} ]}).
72
- to_return(body: [{:id=>1, :status=>"ok"}])
73
-
74
- ret = @prd.remove("abcdefg")
75
- expect(ret).to be_nil
76
- end
77
-
78
- it "Creates" do
79
- frid = "ffffffffffffffffffffffffffffffffffffffff"
80
- stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
81
- with(body: {:auth=>{:client_id=>"LLLLLLLLLL"},
82
- :calls=>[{:id=>1,
83
- :procedure=>"create",
84
- :arguments=>["dataport",{
85
- :format=>"string",
86
- :name=>"bob",
87
- :retention=>{
88
- :count=>1,
89
- :duration=>"infinity"
90
- }
91
- }]} ]}).
92
- to_return(body: [{:id=>1, :status=>"ok", :result=>frid}])
93
-
94
- stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
95
- with(body: {:auth=>{:client_id=>"LLLLLLLLLL"},
96
- :calls=>[{:id=>1,
97
- :procedure=>"map",
98
- :arguments=>["alias", frid, "bob"]} ]}).
99
- to_return(body: [{:id=>1, :status=>"ok"}])
100
-
101
- ret = @prd.create("bob")
102
- expect(ret).to be_nil
103
- end
104
- end
105
-
106
- context "uploads" do
107
- it "replacing" do
108
- frid = "ffffffffffffffffffffffffffffffffffffffff"
109
- stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
110
- with(body: {:auth=>{:client_id=>"LLLLLLLLLL"},
111
- :calls=>[{:id=>1,
112
- :procedure=>"drop",
113
- :arguments=>[frid]} ]}).
114
- to_return(body: [{:id=>1, :status=>"ok"}])
115
-
116
- stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
117
- with(body: {:auth=>{:client_id=>"LLLLLLLLLL"},
118
- :calls=>[{:id=>1,
119
- :procedure=>"create",
120
- :arguments=>["dataport",{
121
- :format=>"string",
122
- :name=>"bob",
123
- :retention=>{
124
- :count=>1,
125
- :duration=>"infinity"
126
- }
127
- }]} ]}).
128
- to_return(body: [{:id=>1, :status=>"ok", :result=>frid}])
129
-
130
- stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
131
- with(body: {:auth=>{:client_id=>"LLLLLLLLLL"},
132
- :calls=>[{:id=>1,
133
- :procedure=>"map",
134
- :arguments=>["alias", frid, "bob"]} ]}).
135
- to_return(body: [{:id=>1, :status=>"ok"}])
136
-
137
- @prd.upload(nil, {:alias=>"bob", :format=>"string", :rid=>frid}, true)
138
- end
139
-
140
- it "creating" do
141
- frid = "ffffffffffffffffffffffffffffffffffffffff"
142
- stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
143
- with(body: {:auth=>{:client_id=>"LLLLLLLLLL"},
144
- :calls=>[{:id=>1,
145
- :procedure=>"create",
146
- :arguments=>["dataport",{
147
- :format=>"string",
148
- :name=>"bob",
149
- :retention=>{
150
- :count=>1,
151
- :duration=>"infinity"
152
- }
153
- }]} ]}).
154
- to_return(body: [{:id=>1, :status=>"ok", :result=>frid}])
155
-
156
- stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
157
- with(body: {:auth=>{:client_id=>"LLLLLLLLLL"},
158
- :calls=>[{:id=>1,
159
- :procedure=>"map",
160
- :arguments=>["alias", frid, "bob"]} ]}).
161
- to_return(body: [{:id=>1, :status=>"ok"}])
162
-
163
- @prd.upload(nil, {:alias=>"bob", :format=>"string"}, false)
164
- end
165
- end
166
-
167
- context "compares" do
168
- before(:example) do
169
- @iA = {:alias=>"data",
170
- :format=>"string",
171
- }
172
- @iB = {:alias=>"data",
173
- :format=>"string",
174
- }
175
- end
176
- it "same" do
177
- ret = @prd.docmp(@iA, @iB)
178
- expect(ret).to eq(false)
179
- end
180
-
181
- it "different alias" do
182
- iA = @iA.merge({:alias=>"bob"})
183
- ret = @prd.docmp(iA, @iB)
184
- expect(ret).to eq(true)
185
- end
186
-
187
- it "different format" do
188
- iA = @iA.merge({:format=>"integer"})
189
- ret = @prd.docmp(iA, @iB)
190
- expect(ret).to eq(true)
191
- end
192
- end
193
-
194
-
195
- context "Lookup functions" do
196
- it "gets local name" do
197
- ret = @prd.tolocalname({ :method=>'get', :path=>'one/two/three' }, nil)
198
- expect(ret).to eq('')
199
- end
200
-
201
- it "gets synckey" do
202
- ret = @prd.synckey({ :alias=>'get' })
203
- expect(ret).to eq("get")
204
- end
205
-
206
- it "tolocalpath is into" do
207
- ret = @prd.tolocalpath('a/path/', {:id=>'cors'})
208
- expect(ret).to eq('a/path/')
209
- end
210
- end
211
-
212
- context "local resoruces" do
213
- before(:example) do
214
- # pull over test file.
215
- FileUtils.mkpath(File.dirname($cfg['location.specs']))
216
- lb = (@testdir + 'spec/fixtures/product_spec_files/lightbulb.yaml').realpath
217
- @spec_path = $cfg['location.specs']
218
- FileUtils.copy(lb.to_path, @spec_path)
219
- end
220
-
221
- context "gets local items" do
222
- it "is there" do
223
- ret = @prd.localitems(@spec_path)
224
- expect(ret).to eq([
225
- {:alias=>"state", :format=>"integer", :initial=>0},
226
- {:alias=>"temperature", :format=>"float", :initial=>0},
227
- {:alias=>"uptime", :format=>"integer", :initial=>0},
228
- {:alias=>"humidity", :format=>"float", :initial=>0}
229
- ])
230
- end
231
-
232
- it "is missing" do
233
- expect(@prd).to receive(:warning).once.with("Skipping missing specs/resources.yaml-h")
234
- ret = @prd.localitems(@spec_path + '-h')
235
- expect(ret).to eq([])
236
- end
237
-
238
- it "isn't a file" do
239
- expect(@prd).to receive(:warning).once.with("Cannot read from specs/resources.yaml-h")
240
- FileUtils.mkpath(@spec_path + '-h')
241
- ret = @prd.localitems(@spec_path + '-h')
242
- expect(ret).to eq([])
243
- end
244
-
245
- it "has wrong format" do
246
- File.open(@spec_path + '-h', 'w') do |io|
247
- io << ['a','b','c'].to_yaml
248
- end
249
- expect(@prd).to receive(:warning).once.with("Unexpected data in specs/resources.yaml-h")
250
- ret = @prd.localitems(@spec_path + '-h')
251
- expect(ret).to eq([])
252
- end
253
- end
254
- end
255
-
256
- context "downloads" do
257
- before(:example) do
258
- FileUtils.mkpath($cfg['location.specs'])
259
- @lb = (@testdir + 'spec/fixtures/product_spec_files/lightbulb.yaml').realpath
260
- @spec_path = Pathname.new(File.join($cfg['location.specs'], $cfg['product.spec']))
261
- end
262
-
263
- it "when nothing is there" do
264
- frid = "FFFFFFFFFF"
265
- stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
266
- with(body: {:auth=>{:client_id=>"LLLLLLLLLL"},
267
- :calls=>[{:id=>1,
268
- :procedure=>"info",
269
- :arguments=>[frid, {}]} ]}).
270
- to_return(body: [{:id=>1, :status=>"ok", :result=>{:description=>{:format=>'integer'}}}])
271
-
272
- @prd.download(@spec_path, {:rid=>frid, :alias=>'state'})
273
-
274
- data = nil
275
- @spec_path.open{|io| data = YAML.load(io)}
276
- expect(data).to eq({"resources"=>[{"alias"=>"state", "format"=>"integer"}]})
277
- end
278
-
279
- it "merging into existing file" do
280
- FileUtils.copy(@lb.to_path, @spec_path)
281
- frid = "FFFFFFFFFF"
282
- stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
283
- with(body: {:auth=>{:client_id=>"LLLLLLLLLL"},
284
- :calls=>[{:id=>1,
285
- :procedure=>"info",
286
- :arguments=>[frid, {}]} ]}).
287
- to_return(body: [{:id=>1, :status=>"ok", :result=>{:description=>{:format=>'integer'}}}])
288
-
289
- @prd.download(@spec_path, {:rid=>frid, :alias=>'state'})
290
- #FileUtils.copy_stream(@spec_path, $stdout)
291
- #expect(FileUtils.cmp(@spec_path.to_path, @lb.to_path)).to be true
292
-
293
- data = nil
294
- @spec_path.open{|io| data = YAML.load(io)}
295
- expect(data).to eq({"resources"=>[
296
- {"alias"=>"temperature", "format"=>"float", "initial"=>0},
297
- {"alias"=>"uptime", "format"=>"integer", "initial"=>0},
298
- {"alias"=>"humidity", "format"=>"float", "initial"=>0},
299
- {"alias"=>"state", "format"=>"integer"}
300
- ]})
301
- end
302
-
303
- end
304
-
305
- context "removes local items" do
306
- before(:example) do
307
- # pull over test file.
308
- FileUtils.mkpath($cfg['location.specs'])
309
- @lb = (@testdir + 'spec/fixtures/product_spec_files/lightbulb.yaml').realpath
310
- @spec_path = File.join($cfg['location.specs'], $cfg['product.spec'])
311
- FileUtils.copy(@lb.to_path, @spec_path)
312
- @spec_path = Pathname.new(@spec_path)
313
- end
314
-
315
- it "it exists and has item" do
316
- @prd.removelocal(@spec_path, {:alias=>"state"})
317
- lbns = (@testdir + 'spec/fixtures/product_spec_files/lightbulb-no-state.yaml').realpath
318
- expect(lbns.read).to eq(@spec_path.read)
319
- end
320
-
321
- it "it exists and does not have item" do
322
- @prd.removelocal(@spec_path, {:alias=>"ThisAliasDoesNotExistInHere"})
323
- # nothing changed
324
- expect(@lb.read).to eq(@spec_path.read)
325
- end
326
- end
327
- end
328
-
329
- # vim: set ai et sw=2 ts=2 :