MrMurano 1.4.3 → 1.5.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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Gemfile +1 -0
  4. data/MrMurano.gemspec +4 -0
  5. data/README.markdown +84 -0
  6. data/Rakefile +4 -3
  7. data/TODO.taskpaper +9 -9
  8. data/bin/mr +2 -0
  9. data/lib/MrMurano/Account.rb +4 -55
  10. data/lib/MrMurano/{configFile.rb → Config.rb} +60 -10
  11. data/lib/MrMurano/Product.rb +16 -4
  12. data/lib/MrMurano/Solution-Endpoint.rb +3 -3
  13. data/lib/MrMurano/Solution-File.rb +4 -10
  14. data/lib/MrMurano/Solution-ServiceConfig.rb +1 -52
  15. data/lib/MrMurano/Solution-Services.rb +44 -8
  16. data/lib/MrMurano/Solution-Users.rb +2 -2
  17. data/lib/MrMurano/Solution.rb +3 -0
  18. data/lib/MrMurano/commands/account.rb +54 -0
  19. data/lib/MrMurano/commands/assign.rb +54 -0
  20. data/lib/MrMurano/{configCommand.rb → commands/config.rb} +0 -0
  21. data/lib/MrMurano/{contentCommand.rb → commands/content.rb} +0 -0
  22. data/lib/MrMurano/{cors.rb → commands/cors.rb} +0 -0
  23. data/lib/MrMurano/commands/domain.rb +17 -0
  24. data/lib/MrMurano/{exportImport.rb → commands/exportImport.rb} +32 -15
  25. data/lib/MrMurano/{keystore.rb → commands/keystore.rb} +0 -0
  26. data/lib/MrMurano/{logs.rb → commands/logs.rb} +0 -0
  27. data/lib/MrMurano/commands/productSpec.rb +94 -0
  28. data/lib/MrMurano/{status.rb → commands/status.rb} +0 -0
  29. data/lib/MrMurano/{sync.rb → commands/sync.rb} +0 -0
  30. data/lib/MrMurano/{timeseries.rb → commands/timeseries.rb} +0 -0
  31. data/lib/MrMurano/commands.rb +14 -0
  32. data/lib/MrMurano/http.rb +24 -3
  33. data/lib/MrMurano/version.rb +1 -1
  34. data/lib/MrMurano.rb +9 -17
  35. data/spec/Account-Passwords_spec.rb +2 -11
  36. data/spec/ConfigFile_spec.rb +48 -0
  37. data/spec/Config_spec.rb +329 -0
  38. data/spec/ProductBase_spec.rb +0 -3
  39. data/spec/ProductContent_spec.rb +0 -3
  40. data/spec/Product_spec.rb +0 -3
  41. data/spec/Solution-ServiceEventHandler_spec.rb +217 -0
  42. data/spec/Solution-ServiceModules_spec.rb +177 -0
  43. data/spec/testfiles/configfile +9 -0
  44. metadata +42 -14
  45. data/lib/MrMurano/shelledCommand.rb +0 -43
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 86450cabd85b63dc6f6db984acddfbb1571846ae
4
- data.tar.gz: cdc772d246ed238d2ac11018a808c1b8721fda4a
3
+ metadata.gz: 582e59cb41974922ea200196ccdaa17f61791ca7
4
+ data.tar.gz: 6daed3f5cecd632b93fa95b335126efb84bb75bb
5
5
  SHA512:
6
- metadata.gz: ac4278c5d0dbad4af322d9d37c416f989610fc4bde3ee9d634698bbd91101a65a9cea12383d0bcca9689f6e6f73d63c00c5bd6a515f17472b47e7eaa63e7214c
7
- data.tar.gz: fcc89fbf8ea4f675b670960bfc39cb6b65cee7ec87fffddede8e72a160cab14d2ba775a516e47491c437c86f36d9971326e70195a19b8b8f2f87bdfe53adfb8e
6
+ metadata.gz: 723355b78007243ccdd74e4362969cbc7ce5dc27ecd1a722e267bb99ab795c872be7bb56da3e77b01ac3627239118676be1f7438f72eeba12ab8cd5dd3d9ac2f
7
+ data.tar.gz: 43df4f2518b7df9d1830b0fdc0aba4946c1871a107830e146378b5151e7b48486a8fff3cf16bd4b303cbec16212644e9f5593711de568e590fe746d3ee2573d6
data/.gitignore CHANGED
@@ -12,6 +12,7 @@ xcuserdata
12
12
  Pods/
13
13
  pkg/
14
14
 
15
+ .mrmurano/
15
16
  .mrmuranorc
16
17
  .mrmuranorc.private
17
18
  files/
data/Gemfile CHANGED
@@ -9,6 +9,7 @@ gem 'mime-types-data', '~> 3.2016'
9
9
  gem 'inifile', '~> 3.0'
10
10
  gem 'http-form_data', '~> 1.0.1'
11
11
  gem 'rainbow', '~> 2.1.0'
12
+ gem 'dotenv', '~> 2.1.1'
12
13
 
13
14
  group :test do
14
15
  gem 'rake', '~> 10.1.1'
data/MrMurano.gemspec CHANGED
@@ -15,6 +15,8 @@ Gem::Specification.new do |s|
15
15
  Push and pull data from Murano.
16
16
  Get status on what things have changed.
17
17
  See a diff of the changes before you push.
18
+
19
+ and so much more.
18
20
  }
19
21
 
20
22
  s.files = `git ls-files`.split("\n")
@@ -29,11 +31,13 @@ Gem::Specification.new do |s|
29
31
  s.add_runtime_dependency('inifile', '~> 3.0')
30
32
  s.add_runtime_dependency('http-form_data', '~> 1.0.1')
31
33
  s.add_runtime_dependency('rainbow', '~> 2.1.0')
34
+ s.add_runtime_dependency('dotenv', '~> 2.1.1')
32
35
 
33
36
  s.add_development_dependency('bundler', '~> 1.7.6')
34
37
  s.add_development_dependency('rake', '~> 10.1.1')
35
38
  s.add_development_dependency('rspec', '~> 3.5')
36
39
  s.add_development_dependency('webmock', '~> 2.1.0')
40
+ # maybe? s.add_development_dependency('vcr', '~> ???')
37
41
  end
38
42
 
39
43
 
data/README.markdown CHANGED
@@ -29,6 +29,17 @@ Or
29
29
  > gem update MrMurano
30
30
  ```
31
31
 
32
+ You will likely need to be root for the above commands. If you would rather not
33
+ install as root, you can install gems in the user directory.
34
+
35
+ ```
36
+ > gem install MrMurano --user-install
37
+ ```
38
+
39
+ Your `PATH` may need to be updated to find the installed `mr` command. See the
40
+ [Ruby Gem FAQ](http://guides.rubygems.org/faqs/#user-install). In short, you need
41
+ to add the output of `ruby -rubygems -e 'puts Gem.user_dir'` to your `PATH`.
42
+
32
43
  ## Features
33
44
 
34
45
  ### Logs
@@ -43,6 +54,41 @@ MrMurano does a few things to make your log output easier to follow.
43
54
 
44
55
  All of these can be toggled with command line options.
45
56
 
57
+ ### MR_CONFIGFILE environment and Dotenv
58
+
59
+ The environment variable `MR_CONFIGFILE` is checked for an additional config to
60
+ load. This in conjuction with dotenv support, allows for easily switching between
61
+ development, staging, and production setups.
62
+
63
+ To use this, write the three solution ids into `.mrmurano.dev`, `.mrmurano.stg`,
64
+ and `.mrmurano.prod`. Then write the `.env` file to point at the system you're
65
+ currently working on.
66
+
67
+ The files for this are then:
68
+ ```
69
+ cat >> .mrmurano.dev <<EOF
70
+ [solution]
71
+ id=AAAAAAAA
72
+ EOF
73
+
74
+ cat >> .mrmurano.stg <<EOF
75
+ [solution]
76
+ id=BBBBBBBB
77
+ EOF
78
+
79
+ cat >> .mrmurano.prod <<EOF
80
+ [solution]
81
+ id=CCCCCCCC
82
+ EOF
83
+
84
+ cat >> .env <<EOF
85
+ MR_CONFIGFILE=.mrmurano.dev
86
+ EOF
87
+ ```
88
+
89
+ This also allows for keeping private things in a seperate config file and having
90
+ the shared things checked into source control.
91
+
46
92
  ### Keystore
47
93
 
48
94
  To aid with debugging, MrMurano has direct access to a solution's Keystore service.
@@ -78,6 +124,44 @@ For the endpoints, modules, and eventhandlers directories. The can contain both
78
124
  files or a sub-directory of files. This allows for keeping common things grouped
79
125
  together. Or adding a git submodule in to manage reusable chunks.
80
126
 
127
+ So, as an example, your project could be like:
128
+ ```
129
+ endpoints
130
+ endpoints/get_-v1-data-averaged.lua
131
+ endpoints/get_-v1-data-cupsDrank.lua
132
+ endpoints/get_-v1-data-latest.lua
133
+ endpoints/statusboard-data.lua
134
+ endpoints/users
135
+ endpoints/users/get_-session.lua
136
+ endpoints/users/get_-v1-verify-code.lua
137
+ endpoints/users/patch_-v1-user.lua
138
+ endpoints/users/post_-session.lua
139
+ endpoints/users/post_-v1-pushtoken.lua
140
+ endpoints/users/put_-v1-user-email.lua
141
+ eventhandlers
142
+ eventhandlers/product.lua
143
+ eventhandlers/timer_timer.lua
144
+ files
145
+ files/batteryMeter.svg
146
+ files/index.html
147
+ files/meter.html
148
+ modules
149
+ modules/TSQ
150
+ modules/TSQ/func_field_quote_test.lua
151
+ modules/TSQ/isadate_test.lua
152
+ modules/TSQ/README.md
153
+ modules/TSQ/results_test.lua
154
+ modules/TSQ/select_fields_test.lua
155
+ modules/TSQ/tsq-1.2-2.rockspec
156
+ modules/TSQ/tsq.lua
157
+ modules/TSQ/tsq_test.lua
158
+ modules/TSQ/tsw.lua
159
+ modules/TSQ/tsw_test.lua
160
+ modules/users.lua
161
+ modules/util.lua
162
+ spec
163
+ spec/cico.murano.spec
164
+ ```
81
165
 
82
166
 
83
167
  ### Bundles
data/Rakefile CHANGED
@@ -17,11 +17,12 @@ task :echo do
17
17
  puts "= #{Bundler::GemHelper.gemspec.version} ="
18
18
  end
19
19
 
20
- task :run do
21
- sh %{ruby -Ilib bin/mr }
20
+ desc "Prints a cmd to test this in another directory"
21
+ task :testwith do
22
+ pwd=Dir.pwd.sub(Dir.home, '~')
23
+ puts "ruby -I#{pwd}/lib #{pwd}/bin/mr "
22
24
  end
23
25
 
24
-
25
26
  task :test do
26
27
  sh %{rspec}
27
28
  end
data/TODO.taskpaper CHANGED
@@ -1,8 +1,9 @@
1
1
  Readme:
2
2
  - Add more walk-thrus of common actions. (create new solution, …)
3
+ - Look into using VCR for testing.
3
4
 
4
5
  Commands:
5
- - Status will show {modules,eventhandlers} have changes when they don’t.
6
+ - Status will show {modules,eventhandlers} have changes when they don’t. @done(2016-09-23)
6
7
  - First time run needs to be smoothed out. @done(2016-08-09)
7
8
  - Default for most commands should be -same @done(2016-08-02)
8
9
  - Add Diff Command @done(2016-07-27)
@@ -12,12 +13,13 @@ Account:
12
13
  - Netrc library (or the netrc format) doesn't allow '#' in passwords. @done(2016-08-10)
13
14
 
14
15
  Endpoints:
15
- - Add support for multiple endpoints in one file (maybe)
16
+ - Add support for multiple endpoints in one file (maybe) @pri(low)
16
17
  - Add directory support like in modules @done(2016-07-26)
17
18
 
18
19
  Files:
19
20
  - Add ignore patterns to config
20
21
  - Switch to mime-types v3
22
+ - Figure out how to make the hexed-sha checksum faster. @done(2016-09-23)
21
23
  - Fix upload. @done(2016-08-01)
22
24
  - Files won't update, they always delete then add. @done(2016-07-28)
23
25
 
@@ -36,22 +38,20 @@ Timeseries:
36
38
  - Add CSV output option. @done(2016-09-09)
37
39
 
38
40
  Product:
41
+ - Auto convert exoline spec files into murano spec files on upload?
39
42
  - Need to add way to set the product ID on a device eventhandler. @done(2016-08-01)
40
43
 
41
44
  Service Device:
42
45
  - When listing and bussiness.id is missing, gracefully fall back to --idonly @done(2016-09-12)
43
46
 
44
47
  Config:
45
- - Think about adding dev,staging,prod system; how would that work?
46
- Would it work ok to just use the --configfile option?
47
- I'm thinking so. To the point of dropping the :private scope.
48
- - Add ENV support for some (or all?) options.
49
- At least the --configfile option. (and --config option)
50
- - Maybe add dotenv support.
48
+ - Add ENV['MR_CONFIGFILE'] path to file to load like --configfile @done(2016-09-22)
49
+ - Maybe add dotenv support. @done(2016-09-22)
50
+ - Think about adding dev,staging,prod system; how would that work? @done(2016-09-16)
51
51
 
52
52
  SolutionBase:
53
- - Errors from the server should be displayed prettier.
54
53
  - All network traffic is serialized. Make some parallel.
54
+ - Errors from the server should be displayed prettier. @done(2016-09-26)
55
55
  - JSON parse should use symbols for keys. @done(2016-09-01)
56
56
  - Add the --curl verbose option. @done(2016-08-12)
57
57
  - Rebuild how local names and paths are computed from remote items. @done(2016-07-27)
data/bin/mr CHANGED
@@ -5,6 +5,8 @@ require 'commander/import'
5
5
  require 'pathname'
6
6
  require 'MrMurano'
7
7
  require 'pp'
8
+ require 'dotenv'
9
+ Dotenv.load
8
10
 
9
11
  program :version, MrMurano::VERSION
10
12
  program :description, %{Manage a Solution and Product in Exosite's Murano}
@@ -2,10 +2,10 @@ require 'uri'
2
2
  require 'net/http'
3
3
  require 'json'
4
4
  require 'date'
5
- require 'pp'
6
- require 'terminal-table'
7
5
  require 'pathname'
8
6
  require 'yaml'
7
+ require 'MrMurano/Config'
8
+ require 'MrMurano/http'
9
9
 
10
10
  module MrMurano
11
11
  class Passwords
@@ -65,7 +65,7 @@ module MrMurano
65
65
  user = ask("Account name: ")
66
66
  $cfg.set('user.name', user, :user)
67
67
  end
68
- pff = Pathname.new(ENV['HOME']) + '.mrmurano/passwords'
68
+ pff = $cfg.file_at('passwords', :user)
69
69
  pf = Passwords.new(pff)
70
70
  pf.load
71
71
  pws = pf.get(host, user)
@@ -100,7 +100,7 @@ module MrMurano
100
100
  token = JSON.parse(response.body, json_opts)
101
101
  @@token = token[:token]
102
102
  else
103
- say_error "No token! because: #{response}"
103
+ showHttpError(request, response)
104
104
  @@token = nil
105
105
  raise response
106
106
  end
@@ -125,55 +125,4 @@ module MrMurano
125
125
  end
126
126
  end
127
127
 
128
- command :account do |c|
129
- c.syntax = %{mr account [options]}
130
- c.description = %{Show things about your account.}
131
- c.option '--businesses', 'Get businesses for user'
132
- c.option '--products', 'Get products for user (needs a business)'
133
- c.option '--solutions', 'Get solutions for user (needs a business)'
134
- c.option '--idonly', 'Only return the ids'
135
-
136
- c.example %{List all businesses}, 'mr account --businesses'
137
- c.example %{List solutions}, 'mr account --solutions -c business.id=XXXXXXXX'
138
-
139
- c.action do |args, options|
140
-
141
- acc = MrMurano::Account.new
142
-
143
- if options.businesses then
144
- data = acc.businesses
145
- if options.idonly then
146
- say data.map{|row| row[:bizid]}.join(' ')
147
- else
148
- busy = data.map{|row| [row[:bizid], row[:role], row[:name]]}
149
- table = Terminal::Table.new :rows => busy, :headings => ['Biz ID', 'Role', 'Name']
150
- say table
151
- end
152
-
153
- elsif options.products then
154
- data = acc.products
155
- if options.idonly then
156
- say data.map{|row| row[:pid]}.join(' ')
157
- else
158
- busy = data.map{|r| [r[:label], r[:type], r[:pid], r[:modelId]]}
159
- table = Terminal::Table.new :rows => busy, :headings => ['Label', 'Type', 'PID', 'ModelID']
160
- say table
161
- end
162
-
163
- elsif options.solutions then
164
- data = acc.solutions
165
- if options.idonly then
166
- say data.map{|row| row[:apiId]}.join(' ')
167
- else
168
- busy = data.map{|r| [r[:apiId], r[:domain], r[:type], r[:sid]]}
169
- table = Terminal::Table.new :rows => busy, :headings => ['API ID', 'Domain', 'Type', 'SID']
170
- say table
171
- end
172
-
173
- else
174
- say acc.token
175
- end
176
-
177
- end
178
- end
179
128
  # vim: set ai et sw=2 ts=2 :
@@ -6,7 +6,7 @@ module MrMurano
6
6
  #
7
7
  # internal transient this-run-only things (also -c options)
8
8
  # specified from --configfile
9
- # private .mrmuranorc.private at project dir (for things you don't want to commit)
9
+ # env from ENV['MR_CONFIGFILE']
10
10
  # project .mrmuranorc at project dir
11
11
  # user .mrmuranorc at $HOME
12
12
  # system .mrmuranorc at /etc
@@ -32,10 +32,11 @@ module MrMurano
32
32
  end
33
33
 
34
34
  attr :paths
35
+ attr_reader :projectDir
35
36
 
36
- CFG_SCOPES=%w{internal specified project private user system defaults}.map{|i| i.to_sym}.freeze
37
+ CFG_SCOPES=%w{internal specified env project private user system defaults}.map{|i| i.to_sym}.freeze
37
38
  CFG_FILE_NAME = '.mrmuranorc'.freeze
38
- CFG_PRVT_NAME = '.mrmuranorc.private'.freeze
39
+ CFG_PRVT_NAME = '.mrmuranorc.private'.freeze # Going away.
39
40
  CFG_DIR_NAME = '.mrmurano'.freeze
40
41
  CFG_ALTRC_NAME = '.mrmurano/config'.freeze
41
42
  CFG_SYS_NAME = '/etc/mrmuranorc'.freeze
@@ -44,10 +45,21 @@ module MrMurano
44
45
  @paths = []
45
46
  @paths << ConfigFile.new(:internal, nil, IniFile.new())
46
47
  # :specified --configfile FILE goes here. (see load_specific)
47
- prjfile = findProjectDir()
48
- unless prjfile.nil? then
49
- @paths << ConfigFile.new(:private, prjfile + CFG_PRVT_NAME)
50
- @paths << ConfigFile.new(:project, prjfile + CFG_FILE_NAME)
48
+ unless ENV['MR_CONFIGFILE'].nil? then
49
+ # if it exists, must be a file
50
+ # if it doesn't exist, that's ok
51
+ ep = Pathname.new(ENV['MR_CONFIGFILE'])
52
+ if ep.file? or not ep.exist? then
53
+ @paths << ConfigFile.new(:env, ep)
54
+ end
55
+ end
56
+ @projectDir = findProjectDir()
57
+ unless @projectDir.nil? then
58
+ if (@projectDir + CFG_PRVT_NAME).exist? then
59
+ say_warning "!!! Using .mrmuranorc.private is deprecated"
60
+ end
61
+ @paths << ConfigFile.new(:private, @projectDir + CFG_PRVT_NAME)
62
+ @paths << ConfigFile.new(:project, @projectDir + CFG_FILE_NAME)
51
63
  end
52
64
  @paths << ConfigFile.new(:user, Pathname.new(Dir.home) + CFG_FILE_NAME)
53
65
  @paths << ConfigFile.new(:system, Pathname.new(CFG_SYS_NAME))
@@ -60,7 +72,7 @@ module MrMurano
60
72
 
61
73
  set('net.host', 'bizapi.hosted.exosite.io', :defaults)
62
74
 
63
- set('location.base', prjfile, :defaults) unless prjfile.nil?
75
+ set('location.base', @projectDir, :defaults) unless @projectDir.nil?
64
76
  set('location.files', 'files', :defaults)
65
77
  set('location.endpoints', 'endpoints', :defaults)
66
78
  set('location.modules', 'modules', :defaults)
@@ -87,7 +99,7 @@ module MrMurano
87
99
  def findProjectDir()
88
100
  result=nil
89
101
  fileNames=[CFG_FILE_NAME, CFG_PRVT_NAME, CFG_ALTRC_NAME]
90
- dirNames=[CFG_DIR_NAME, '.git']
102
+ dirNames=[CFG_DIR_NAME]
91
103
  home = Pathname.new(Dir.home)
92
104
  pwd = Pathname.new(Dir.pwd)
93
105
  return nil if home == pwd
@@ -105,22 +117,59 @@ module MrMurano
105
117
  end
106
118
  end
107
119
  end
108
- # if nothing found, assume it will live in pwd.
120
+
121
+ # If nothing found, do a last ditch try by looking for .git/
122
+ if result.nil? then
123
+ pwd.dirname.ascend do |i|
124
+ break unless result.nil?
125
+ break if i == home
126
+ if (i + '.git').directory? then
127
+ result = i
128
+ end
129
+ end
130
+ end
131
+
132
+ # Now if nothing found, assume it will live in pwd.
109
133
  result = Pathname.new(Dir.pwd) if result.nil?
110
134
  return result
111
135
  end
136
+ private :findProjectDir
137
+
138
+ def file_at(name, scope=:project)
139
+ case scope
140
+ when :internal
141
+ root = nil
142
+ when :specified
143
+ root = nil
144
+ when :project
145
+ root = @projectDir + CFG_DIR_NAME
146
+ when :user
147
+ root = Pathname.new(Dir.home) + CFG_DIR_NAME
148
+ when :system
149
+ root = nil
150
+ when :defaults
151
+ root = nil
152
+ end
153
+ return nil if root.nil?
154
+ root.mkpath
155
+ root + name
156
+ end
112
157
 
158
+ ## Load all of the potential config files
113
159
  def load()
114
160
  # - read/write config file in [Project, User, System] (all are optional)
115
161
  @paths.each { |cfg| cfg.load }
116
162
  end
117
163
 
164
+ ## Load specified file into the config stack
165
+ # This can be called multiple times and each will get loaded into the config
118
166
  def load_specific(file)
119
167
  spc = ConfigFile.new(:specified, Pathname.new(file))
120
168
  spc.load
121
169
  @paths.insert(1, spc)
122
170
  end
123
171
 
172
+ ## Get a value for key, looking at the specificed scopes
124
173
  # key is <section>.<key>
125
174
  def get(key, scope=CFG_SCOPES)
126
175
  scope = [scope] unless scope.kind_of? Array
@@ -139,6 +188,7 @@ module MrMurano
139
188
  return nil
140
189
  end
141
190
 
191
+ ## Dump out a combined config
142
192
  def dump()
143
193
  # have a fake, merge all into it, then dump it.
144
194
  base = IniFile.new()
@@ -2,6 +2,8 @@ require 'uri'
2
2
  require 'mime/types'
3
3
  require 'csv'
4
4
  require 'pp'
5
+ require 'MrMurano/http'
6
+ require 'MrMurano/verbosing'
5
7
 
6
8
  module MrMurano
7
9
  class ProductBase
@@ -124,7 +126,7 @@ module MrMurano
124
126
  end
125
127
  end
126
128
  else
127
- say_error "got #{resp.to_s} from #{request} #{request.uri.to_s}"
129
+ showHttpError(request, response)
128
130
  raise resp
129
131
  end
130
132
  end
@@ -216,8 +218,10 @@ module MrMurano
216
218
  end
217
219
 
218
220
  def activate(sn)
219
- # TODO: Need to create a new @http for the different host. Fails otherwise
220
221
  uri = URI("https://#{@pid}.m2.exosite.com/provision/activate")
222
+ http = Net::HTTP.new(uri.host, uri.port)
223
+ http.use_ssl = true
224
+ http.start
221
225
  request = Net::HTTP::Post.new(uri)
222
226
  request.form_data = {
223
227
  :vendor => @pid,
@@ -225,9 +229,17 @@ module MrMurano
225
229
  :sn => sn
226
230
  }
227
231
  request['User-Agent'] = "MrMurano/#{MrMurano::VERSION}"
228
- request['authorization'] = nil
232
+ request['Authorization'] = nil
229
233
  request.content_type = 'application/x-www-form-urlencoded; charset=utf-8'
230
- workit(request)
234
+ curldebug(request)
235
+ response = http.request(request)
236
+ case response
237
+ when Net::HTTPSuccess
238
+ return response.body
239
+ else
240
+ showHttpError(request, response)
241
+ raise response
242
+ end
231
243
  end
232
244
 
233
245
  def add_sn(sn, extra='')
@@ -2,6 +2,7 @@ require 'uri'
2
2
  require 'net/http'
3
3
  require 'json'
4
4
  require 'pp'
5
+ require 'MrMurano/Solution'
5
6
 
6
7
  module MrMurano
7
8
  # …/endpoint
@@ -35,7 +36,7 @@ module MrMurano
35
36
  end
36
37
 
37
38
  ##
38
- # Upload endpoint
39
+ # Upload endpoint
39
40
  # :local path to file to push
40
41
  # :remote hash of method and endpoint path
41
42
  def upload(local, remote)
@@ -58,8 +59,7 @@ module MrMurano
58
59
  verbose "\tDoesn't exist, creating"
59
60
  post('/', remote)
60
61
  else
61
- say_error "got #{response} from #{request} #{request.uri.to_s}"
62
- say_error ":: #{response.body}"
62
+ showHttpError(request, response)
63
63
  end
64
64
  end
65
65
  else
@@ -4,6 +4,7 @@ require "http/form_data"
4
4
  require 'digest/sha1'
5
5
  require 'mime/types'
6
6
  require 'pp'
7
+ require 'MrMurano/Solution'
7
8
 
8
9
  module MrMurano
9
10
  # …/file
@@ -36,7 +37,7 @@ module MrMurano
36
37
  end
37
38
  end
38
39
  else
39
- say_error "got #{resp.to_s} from #{request} #{request.uri.to_s}"
40
+ showHttpError(request, response)
40
41
  raise resp
41
42
  end
42
43
  end
@@ -101,8 +102,7 @@ module MrMurano
101
102
  case response
102
103
  when Net::HTTPSuccess
103
104
  else
104
- say_error "got #{response} from #{request} #{request.uri.to_s}"
105
- say_error ":: #{response.body}"
105
+ showHttpError(request, response)
106
106
  end
107
107
  end
108
108
  end
@@ -124,16 +124,10 @@ module MrMurano
124
124
  # It does not actually take the SHA1 of the file.
125
125
  # It first converts the file to hex, then takes the SHA1 of that string
126
126
  #sha1 = Digest::SHA1.file(path.to_s).hexdigest
127
- def hexit(str)
128
- ret=''
129
- # TODO: find a faster way to do this.
130
- str.each_byte{|b| ret << "%02x" % b}
131
- ret
132
- end
133
127
  sha1 = Digest::SHA1.new
134
128
  path.open('rb:ASCII-8BIT') do |io|
135
129
  while chunk = io.read(1048576) do
136
- sha1 << hexit(chunk)
130
+ sha1 << Digest.hexencode(chunk)
137
131
  end
138
132
  end
139
133
  debug "Checking #{name} (#{mime.simplified} #{sha1.hexdigest})"
@@ -1,4 +1,4 @@
1
- require 'terminal-table'
1
+ require 'MrMurano/Solution'
2
2
 
3
3
  module MrMurano
4
4
  # …/serviceconfig
@@ -51,55 +51,4 @@ module MrMurano
51
51
  end
52
52
  end
53
53
 
54
- command 'assign list' do |c|
55
- c.syntax = 'mr assign list [options]'
56
- c.description = 'List the products that are assigned'
57
- c.option '--idonly', 'Only return the ids'
58
- c.action do |args, options|
59
- sol = MrMurano::SC_Device.new
60
-
61
- trigs = sol.showTriggers()
62
- if options.idonly or $cfg['business.id'].nil? then
63
- say trigs.join(' ')
64
- else
65
- acc = MrMurano::Account.new
66
- products = acc.products
67
- products.select!{|p| trigs.include? p[:modelId] }
68
- if products.empty? then
69
- say trigs.join(' ')
70
- else
71
- busy = products.map{|r| [r[:label], r[:type], r[:pid], r[:modelId]]}
72
- table = Terminal::Table.new :rows => busy, :headings => ['Label', 'Type', 'PID', 'ModelID']
73
- say table
74
- end
75
- end
76
- end
77
- end
78
- alias_command :assign, 'assign list'
79
-
80
- command 'assign set' do |c|
81
- c.syntax = 'mr assign set [product]'
82
- c.description = 'Assign a product to a eventhandler'
83
-
84
- c.action do |args, options|
85
- sol = MrMurano::SC_Device.new
86
-
87
- prname = args.shift
88
- if prname.nil? then
89
- prid = $cfg['product.id']
90
- else
91
- acc = MrMurano::Account.new
92
- products = acc.products
93
- products.select!{|p|
94
- p[:label] == prname or p[:modelId] == prname or p[:pid] == prname
95
- }
96
- prid = products.map{|p| p[:modelId]}
97
- end
98
- raise "No product ID!" if prid.nil?
99
- say "Assigning #{prid} to solution" if $cfg['tool.verbose']
100
- sol.assignTriggers(prid) unless $cfg['tool.dry']
101
- end
102
-
103
- end
104
-
105
54
  # vim: set ai et sw=2 ts=2 :