MrMurano 1.4.3 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +1 -0
- data/MrMurano.gemspec +4 -0
- data/README.markdown +84 -0
- data/Rakefile +4 -3
- data/TODO.taskpaper +9 -9
- data/bin/mr +2 -0
- data/lib/MrMurano/Account.rb +4 -55
- data/lib/MrMurano/{configFile.rb → Config.rb} +60 -10
- data/lib/MrMurano/Product.rb +16 -4
- data/lib/MrMurano/Solution-Endpoint.rb +3 -3
- data/lib/MrMurano/Solution-File.rb +4 -10
- data/lib/MrMurano/Solution-ServiceConfig.rb +1 -52
- data/lib/MrMurano/Solution-Services.rb +44 -8
- data/lib/MrMurano/Solution-Users.rb +2 -2
- data/lib/MrMurano/Solution.rb +3 -0
- data/lib/MrMurano/commands/account.rb +54 -0
- data/lib/MrMurano/commands/assign.rb +54 -0
- data/lib/MrMurano/{configCommand.rb → commands/config.rb} +0 -0
- data/lib/MrMurano/{contentCommand.rb → commands/content.rb} +0 -0
- data/lib/MrMurano/{cors.rb → commands/cors.rb} +0 -0
- data/lib/MrMurano/commands/domain.rb +17 -0
- data/lib/MrMurano/{exportImport.rb → commands/exportImport.rb} +32 -15
- data/lib/MrMurano/{keystore.rb → commands/keystore.rb} +0 -0
- data/lib/MrMurano/{logs.rb → commands/logs.rb} +0 -0
- data/lib/MrMurano/commands/productSpec.rb +94 -0
- data/lib/MrMurano/{status.rb → commands/status.rb} +0 -0
- data/lib/MrMurano/{sync.rb → commands/sync.rb} +0 -0
- data/lib/MrMurano/{timeseries.rb → commands/timeseries.rb} +0 -0
- data/lib/MrMurano/commands.rb +14 -0
- data/lib/MrMurano/http.rb +24 -3
- data/lib/MrMurano/version.rb +1 -1
- data/lib/MrMurano.rb +9 -17
- data/spec/Account-Passwords_spec.rb +2 -11
- data/spec/ConfigFile_spec.rb +48 -0
- data/spec/Config_spec.rb +329 -0
- data/spec/ProductBase_spec.rb +0 -3
- data/spec/ProductContent_spec.rb +0 -3
- data/spec/Product_spec.rb +0 -3
- data/spec/Solution-ServiceEventHandler_spec.rb +217 -0
- data/spec/Solution-ServiceModules_spec.rb +177 -0
- data/spec/testfiles/configfile +9 -0
- metadata +42 -14
- data/lib/MrMurano/shelledCommand.rb +0 -43
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 582e59cb41974922ea200196ccdaa17f61791ca7
|
4
|
+
data.tar.gz: 6daed3f5cecd632b93fa95b335126efb84bb75bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 723355b78007243ccdd74e4362969cbc7ce5dc27ecd1a722e267bb99ab795c872be7bb56da3e77b01ac3627239118676be1f7438f72eeba12ab8cd5dd3d9ac2f
|
7
|
+
data.tar.gz: 43df4f2518b7df9d1830b0fdc0aba4946c1871a107830e146378b5151e7b48486a8fff3cf16bd4b303cbec16212644e9f5593711de568e590fe746d3ee2573d6
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
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
|
-
|
21
|
-
|
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
|
-
-
|
46
|
-
|
47
|
-
|
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
data/lib/MrMurano/Account.rb
CHANGED
@@ -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 =
|
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
|
-
|
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
|
-
#
|
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
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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',
|
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
|
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
|
-
|
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()
|
data/lib/MrMurano/Product.rb
CHANGED
@@ -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
|
-
|
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['
|
232
|
+
request['Authorization'] = nil
|
229
233
|
request.content_type = 'application/x-www-form-urlencoded; charset=utf-8'
|
230
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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 <<
|
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 '
|
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 :
|