hmx_client 0.0.7 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -4
- data/Gemfile +4 -4
- data/Rakefile +1 -1
- data/bin/hmx +33 -33
- data/hmx_client.gemspec +27 -27
- data/lib/hmx/client.rb +167 -167
- data/lib/hmx/command.rb +140 -140
- data/lib/hmx/command/base.rb +195 -194
- data/lib/hmx/command/bootstrap.rb +18 -18
- data/lib/hmx/command/check.rb +170 -0
- data/lib/hmx/command/clone.rb +77 -77
- data/lib/hmx/command/config.rb +67 -67
- data/lib/hmx/command/dump.rb +67 -67
- data/lib/hmx/command/fn.rb +125 -43
- data/lib/hmx/command/fountain.rb +46 -46
- data/lib/hmx/command/get.rb +20 -20
- data/lib/hmx/command/getContent.rb +20 -20
- data/lib/hmx/command/help.rb +114 -114
- data/lib/hmx/command/partition.rb +38 -38
- data/lib/hmx/command/query.rb +22 -22
- data/lib/hmx/command/session.rb +35 -35
- data/lib/hmx/command/task.rb +32 -32
- data/lib/hmx/command/type.rb +45 -45
- data/lib/hmx/command/user.rb +68 -68
- data/lib/hmx/command/view.rb +161 -155
- data/lib/hmx/helpers.rb +76 -61
- data/lib/hmx/hmx.rb +148 -215
- data/lib/hmx/version.rb +3 -3
- data/lib/hmx_client.rb +7 -7
- data/sampleCommands.txt +5 -5
- metadata +12 -11
data/lib/hmx/helpers.rb
CHANGED
@@ -1,61 +1,76 @@
|
|
1
|
-
require 'cli-colorize'
|
2
|
-
|
3
|
-
module HmxClient
|
4
|
-
module Helpers
|
5
|
-
include CLIColorize
|
6
|
-
|
7
|
-
def getFromUser(prompt)
|
8
|
-
content = ''
|
9
|
-
done = false
|
10
|
-
puts prompt
|
11
|
-
while(!done)
|
12
|
-
line = gets.strip
|
13
|
-
if (line[line.length-1] == '\\')
|
14
|
-
done = false
|
15
|
-
content = content + line[0 .. line.length-2]
|
16
|
-
else
|
17
|
-
content = content + line
|
18
|
-
done = true
|
19
|
-
end
|
20
|
-
end
|
21
|
-
content
|
22
|
-
end
|
23
|
-
def error(msg)
|
24
|
-
puts(colorize(msg, :red))
|
25
|
-
exit 1
|
26
|
-
end
|
27
|
-
def longest(items)
|
28
|
-
items.map { |i| i.to_s.length }.sort.last
|
29
|
-
end
|
30
|
-
|
31
|
-
def display(msg="", newline=true)
|
32
|
-
if newline
|
33
|
-
puts(msg)
|
34
|
-
else
|
35
|
-
print(msg)
|
36
|
-
STDOUT.flush
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def display_table(objects, columns, headers)
|
41
|
-
lengths = []
|
42
|
-
columns.each_with_index do |column, index|
|
43
|
-
header = headers[index]
|
44
|
-
lengths << longest([header].concat(objects.map { |o| o[column].to_s }))
|
45
|
-
end
|
46
|
-
display_row headers, lengths
|
47
|
-
display_row headers.map { |header| "-" * header.length }, lengths
|
48
|
-
objects.each do |row|
|
49
|
-
display_row columns.map { |column| row[column] }, lengths
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def display_row(row, lengths)
|
54
|
-
row.zip(lengths).each do |column, length|
|
55
|
-
format = column.is_a?(Fixnum) ? "%#{length}s " : "%-#{length}s "
|
56
|
-
display format % column, false
|
57
|
-
end
|
58
|
-
display
|
59
|
-
end
|
60
|
-
|
61
|
-
|
1
|
+
require 'cli-colorize'
|
2
|
+
|
3
|
+
module HmxClient
|
4
|
+
module Helpers
|
5
|
+
include CLIColorize
|
6
|
+
|
7
|
+
def getFromUser(prompt)
|
8
|
+
content = ''
|
9
|
+
done = false
|
10
|
+
puts prompt
|
11
|
+
while(!done)
|
12
|
+
line = gets.strip
|
13
|
+
if (line[line.length-1] == '\\')
|
14
|
+
done = false
|
15
|
+
content = content + line[0 .. line.length-2]
|
16
|
+
else
|
17
|
+
content = content + line
|
18
|
+
done = true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
content
|
22
|
+
end
|
23
|
+
def error(msg)
|
24
|
+
puts(colorize(msg, :red))
|
25
|
+
exit 1
|
26
|
+
end
|
27
|
+
def longest(items)
|
28
|
+
items.map { |i| i.to_s.length }.sort.last
|
29
|
+
end
|
30
|
+
|
31
|
+
def display(msg="", newline=true)
|
32
|
+
if newline
|
33
|
+
puts(msg)
|
34
|
+
else
|
35
|
+
print(msg)
|
36
|
+
STDOUT.flush
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def display_table(objects, columns, headers)
|
41
|
+
lengths = []
|
42
|
+
columns.each_with_index do |column, index|
|
43
|
+
header = headers[index]
|
44
|
+
lengths << longest([header].concat(objects.map { |o| o[column].to_s }))
|
45
|
+
end
|
46
|
+
display_row headers, lengths
|
47
|
+
display_row headers.map { |header| "-" * header.length }, lengths
|
48
|
+
objects.each do |row|
|
49
|
+
display_row columns.map { |column| row[column] }, lengths
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def display_row(row, lengths)
|
54
|
+
row.zip(lengths).each do |column, length|
|
55
|
+
format = column.is_a?(Fixnum) ? "%#{length}s " : "%-#{length}s "
|
56
|
+
display format % column, false
|
57
|
+
end
|
58
|
+
display
|
59
|
+
end
|
60
|
+
|
61
|
+
def display_tab(data)
|
62
|
+
resp = ''
|
63
|
+
data.each { | line |
|
64
|
+
line.each { | cell |
|
65
|
+
if (cell.is_a? Array)
|
66
|
+
cell.each { | inner | resp = resp + "%20.20s\t" % inner }
|
67
|
+
else
|
68
|
+
resp = resp + "%20.20s\t" % cell
|
69
|
+
end
|
70
|
+
}
|
71
|
+
resp = resp + "\n"
|
72
|
+
}
|
73
|
+
dout resp
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/lib/hmx/hmx.rb
CHANGED
@@ -1,215 +1,148 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rest_client'
|
3
|
-
require 'json'
|
4
|
-
require 'digest/md5'
|
5
|
-
|
6
|
-
module HmxClient
|
7
|
-
|
8
|
-
include HmxClient::Helpers
|
9
|
-
|
10
|
-
class HmxException < Exception
|
11
|
-
attr :msg
|
12
|
-
def initialize(msg)
|
13
|
-
@msg = msg
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class Hmx
|
18
|
-
|
19
|
-
def loginApi(url, urlapi)
|
20
|
-
@urlapi = urlapi
|
21
|
-
@context = JSON.parse (RestClient.get url).to_str
|
22
|
-
end
|
23
|
-
def login(config)
|
24
|
-
puts config if $debug
|
25
|
-
@context = nil;
|
26
|
-
@urlapi = config[:api]
|
27
|
-
if config.has_key?(:context)
|
28
|
-
@context = JSON.parse(config[:context])
|
29
|
-
#Do a null check
|
30
|
-
begin
|
31
|
-
|
32
|
-
rescue => e
|
33
|
-
@context = nil;
|
34
|
-
end
|
35
|
-
end
|
36
|
-
if (@context.nil?)
|
37
|
-
session =
|
38
|
-
salty = session['MXSession']['salty']
|
39
|
-
sendString = config[:password] + ':' + salty
|
40
|
-
digestToSend = Digest::MD5.hexdigest(sendString)
|
41
|
-
@context =
|
42
|
-
config[:context] = JSON.generate(@context)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
|
47
|
-
:
|
48
|
-
:
|
49
|
-
:
|
50
|
-
:
|
51
|
-
|
52
|
-
|
53
|
-
:
|
54
|
-
:
|
55
|
-
:
|
56
|
-
:
|
57
|
-
:
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
:
|
63
|
-
|
64
|
-
{ :pos =>
|
65
|
-
{ :pos =>
|
66
|
-
|
67
|
-
|
68
|
-
:
|
69
|
-
|
70
|
-
|
71
|
-
:
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
:
|
77
|
-
:
|
78
|
-
:
|
79
|
-
:
|
80
|
-
:
|
81
|
-
:
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
end
|
142
|
-
def
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
performDistRequest(:dynquery, args)
|
150
|
-
end
|
151
|
-
def deleteData(*args)
|
152
|
-
performDistRequest(:deleteData, args)
|
153
|
-
end
|
154
|
-
def getSequenceSize(*args)
|
155
|
-
performDistRequest(:getSequenceSize, args)
|
156
|
-
end
|
157
|
-
def execPartialSequence(*args)
|
158
|
-
performDistRequest(:execPartSeq, args)
|
159
|
-
end
|
160
|
-
def requestSession(*args)
|
161
|
-
performDistRequest(:requestSession, args)
|
162
|
-
end
|
163
|
-
def validateUser(*args)
|
164
|
-
performDistRequest(:validateUser, args)
|
165
|
-
end
|
166
|
-
def runView(*args)
|
167
|
-
performDistRequest(:runView, args)
|
168
|
-
end
|
169
|
-
def getTypes(*args)
|
170
|
-
performDistRequest(:getTypes, args)
|
171
|
-
end
|
172
|
-
def updateType(*args)
|
173
|
-
performDistRequest(:updateType, args)
|
174
|
-
end
|
175
|
-
def getType(*args)
|
176
|
-
performDistRequest(:getType, args)
|
177
|
-
end
|
178
|
-
def getFn(args)
|
179
|
-
performDistRequest(:getFn, args)
|
180
|
-
end
|
181
|
-
def putFn(args)
|
182
|
-
performDistRequest(:putFn, args)
|
183
|
-
end
|
184
|
-
def expireSessions(args)
|
185
|
-
performDistRequest(:expireSessions, args)
|
186
|
-
end
|
187
|
-
def getAllTasks(args)
|
188
|
-
performDistRequest(:getAllTasks, args)
|
189
|
-
end
|
190
|
-
def getTask(args)
|
191
|
-
performDistRequest(:getTask, args)
|
192
|
-
end
|
193
|
-
def purgeTasks(args)
|
194
|
-
performDistRequest(:purgeTasks, args)
|
195
|
-
end
|
196
|
-
def getFountainState(args)
|
197
|
-
performDistRequest(:getFountainState, args)
|
198
|
-
end
|
199
|
-
def setFountainId(args)
|
200
|
-
performDistRequest(:setFountainId, args)
|
201
|
-
end
|
202
|
-
def getFountain(args)
|
203
|
-
performDistRequest(:getFountain, args)
|
204
|
-
end
|
205
|
-
def bootstrap
|
206
|
-
performDistRequest(:bootstrap, [])
|
207
|
-
end
|
208
|
-
def getPartitions
|
209
|
-
performDistRequest(:getPartitions, [])
|
210
|
-
end
|
211
|
-
def clonePartition(*args)
|
212
|
-
performDistRequest(:clonePartition, args)
|
213
|
-
end
|
214
|
-
end
|
215
|
-
end
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rest_client'
|
3
|
+
require 'json'
|
4
|
+
require 'digest/md5'
|
5
|
+
|
6
|
+
module HmxClient
|
7
|
+
|
8
|
+
include HmxClient::Helpers
|
9
|
+
|
10
|
+
class HmxException < Exception
|
11
|
+
attr :msg
|
12
|
+
def initialize(msg)
|
13
|
+
@msg = msg
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Hmx
|
18
|
+
|
19
|
+
def loginApi(url, urlapi)
|
20
|
+
@urlapi = urlapi
|
21
|
+
@context = JSON.parse (RestClient.get url).to_str
|
22
|
+
end
|
23
|
+
def login(config)
|
24
|
+
puts config if $debug
|
25
|
+
@context = nil;
|
26
|
+
@urlapi = config[:api]
|
27
|
+
if config.has_key?(:context)
|
28
|
+
@context = JSON.parse(config[:context])
|
29
|
+
#Do a null check
|
30
|
+
begin
|
31
|
+
doInfo([])
|
32
|
+
rescue => e
|
33
|
+
@context = nil;
|
34
|
+
end
|
35
|
+
end
|
36
|
+
if (@context.nil?)
|
37
|
+
session = doRequestSession([config[:partition], config[:user]])
|
38
|
+
salty = session['MXSession']['salty']
|
39
|
+
sendString = config[:password] + ':' + salty
|
40
|
+
digestToSend = Digest::MD5.hexdigest(sendString)
|
41
|
+
@context = doValidateUser([config[:partition], config[:user], digestToSend, session['MXSession']['sessionId']])
|
42
|
+
config[:context] = JSON.generate(@context)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
@@distMap = {
|
46
|
+
:GetPartitions => [ 'admin', 'GETPARTITIONS', 'partitions', []],
|
47
|
+
:ClonePartition => [ 'admin', 'CLONEPARTITION', 'partition', [ { :pos => 0, :name => 'destination' }, { :pos => 1, :name => 'copyStyle' } ] ],
|
48
|
+
:Info => [ 'user', 'INFO', 'response', []],
|
49
|
+
:GetData => [ 'user', 'GETDATA', 'data', [ { :pos => 0, :name => 'displayName' } ]],
|
50
|
+
:GetContent => [ 'user', 'GETCONTENT', 'content', [ { :pos => 0, :name => 'displayName' }]],
|
51
|
+
:PutData => ['user', 'PUTDATA', 'data', [ { :pos => 0, :name => 'data', :file => 1, :json => 1 }]],
|
52
|
+
:PutSimpleData => [ 'user', 'PUTSIMPLEDATA', 'data', [ { :pos => 0, :name => 'displayName'}, { :pos => 1, :name => 'content', :file => 1}]],
|
53
|
+
:Query => [ 'user', 'QUERY', 'result', [ { :pos => 0, :name => 'index' }, { :pos => 1, :name => 'params' }]],
|
54
|
+
:Dynquery => ['user', 'DYNQUERY', 'result', [ { :pos => 0, :name => 'typeName' }, { :pos => 1, :name => 'filterFn' }, { :pos => 2, :name => 'mapFn' } ]],
|
55
|
+
:DeleteData => [ 'user', 'DELETEDATA', 'data', [ { :pos => 0, :name => 'displayName' } ]],
|
56
|
+
:GetSequenceSize => [ 'user', 'GETSEQUENCESIZE', 'size', [ { :pos => 0, :name => 'typeName' }]],
|
57
|
+
:ExecPartSeq => [ 'user', 'EXECPARTIALSEQUENCE', 'response', [ { :pos => 0, :name => 'typeName' },
|
58
|
+
{ :pos => 1, :name => 'fn' },
|
59
|
+
{ :pos => 2, :name => 'start' },
|
60
|
+
{ :pos => 3, :name => 'size' } ] ] ,
|
61
|
+
:RequestSession => [ 'user', 'REQUESTSESSION', 'session', [ { :pos => 0, :name => 'partition' }, { :pos => 1, :name => 'user'}]],
|
62
|
+
:ValidateUser => [ 'user', 'VALIDATEUSER', 'context', [ { :pos => 0, :name => 'partition' },
|
63
|
+
{ :pos => 1, :name => 'user' },
|
64
|
+
{ :pos => 2, :name => 'hashPassword' },
|
65
|
+
{ :pos => 3, :name => 'session' }
|
66
|
+
]],
|
67
|
+
:SubmitTask => [ 'user', 'SUBMITTASK', 'task', [ { :pos => 0, :name => 'task' } ]],
|
68
|
+
:RunView => [ 'user', 'RUNVIEW', 'response', [ { :pos => 0, :name => 'view' }, { :pos => 1, :name => 'params' } ] ],
|
69
|
+
:GetTypes => [ 'admin', 'GETTYPES', 'types', []],
|
70
|
+
:GetType => [ 'admin', 'GETTYPE', 'type', [ { :pos => 0, :name => 'typeName' } ]],
|
71
|
+
:UpdateType => [ 'admin', 'UPDATETYPE', 'type', [ { :pos => 0, :name => 'type' }]],
|
72
|
+
:GetFn => [ 'user', 'GETFN', 'fnContent', [ { :pos =>0, :name => 'fnName' } ]],
|
73
|
+
:PutFn => [ 'user', 'PUTFN', 'response', [ { :pos => 0, :name => 'fnName' }, { :pos => 1, :name => 'fnContent', :file => 1 }, { :pos => 2, :name => 'fnLanguage'} ]],
|
74
|
+
:ExpireSessions => [ 'admin', 'EXPIRESESSIONS', 'sessions', []],
|
75
|
+
:GetAllTasks => [ 'task', 'GETALLTASKS', 'tasks', []],
|
76
|
+
:GetTask => [ 'task', 'GETTASK', 'task', [ { :pos=> 0, :name => 'taskId' } ]],
|
77
|
+
:PurgeTasks => [ 'task', 'PURGETASKS', 'response', []],
|
78
|
+
:GetFountainState => [ 'admin', 'GETFOUNTAINSTATE', 'state', []],
|
79
|
+
:SetFountainId => [ 'admin', 'SETFOUNTAINID', 'dummy', [ { :pos => 0, :name => 'fountain' }, { :pos => 1, :name=> 'value' }]],
|
80
|
+
:GetFountain => [ 'user', 'AUTOID', 'id', [ { :pos => 0, :name => 'fountain' } ]],
|
81
|
+
:Bootstrap => ['special', 'BOOTSTRAP', 'response', []]
|
82
|
+
}
|
83
|
+
# Meta initialize the class methods
|
84
|
+
@@distMap.keys.each { | commandName |
|
85
|
+
method_name = ( "do" + commandName.to_s).to_sym
|
86
|
+
define_method method_name do | arg |
|
87
|
+
performDistRequest(commandName.to_sym, arg)
|
88
|
+
end
|
89
|
+
}
|
90
|
+
def initialize
|
91
|
+
end
|
92
|
+
# Implementation note - the doXXX commands are defined in the section above and basically
|
93
|
+
# call performDistRequest for the symbol :XXX with the arguments provided. So by adding to
|
94
|
+
# @@distMap we automatically provide hmx.doXXX support for that call
|
95
|
+
def performDistRequest(cmd, args)
|
96
|
+
spec = @@distMap[cmd]
|
97
|
+
hash = getSenderHash()
|
98
|
+
spec[3].each { | param |
|
99
|
+
# if the args has enough , use that
|
100
|
+
# otherwise, prompt for the parameter
|
101
|
+
if (args.length > param[:pos])
|
102
|
+
hash[param[:name]] = args[param[:pos]]
|
103
|
+
elsif (param.has_key?(:file) && !HmxClient::Command.fileIn.nil?)
|
104
|
+
# Content comes from file
|
105
|
+
realFile = File.expand_path(HmxClient::Command.fileIn)
|
106
|
+
puts "Reading #{ realFile } to get parameter #{ param[:name] }"
|
107
|
+
hash[param[:name]] = File.open(realFile) { | f |
|
108
|
+
c = ''
|
109
|
+
while(line = f.gets)
|
110
|
+
c = c + line
|
111
|
+
end
|
112
|
+
c
|
113
|
+
}
|
114
|
+
else
|
115
|
+
hash[param[:name]] = getFromUser("Please enter the value of #{ param[:name] }")
|
116
|
+
end
|
117
|
+
if (param.has_key?(:json))
|
118
|
+
hash[param[:name]] = JSON.parse(hash[param[:name]])
|
119
|
+
end
|
120
|
+
}
|
121
|
+
standardRequest(spec[0], spec[1], hash, spec[2])
|
122
|
+
end
|
123
|
+
def performRequest(prefix, function, command)
|
124
|
+
puts "Send data #{ JSON.generate(command) }" if HmxClient::Command.debug?
|
125
|
+
puts "URL is #{ @urlapi+'/'+prefix } " if HmxClient::Command.debug?
|
126
|
+
response = RestClient.post @urlapi+'/'+prefix, :function=>function, :params=>JSON.generate(command), :multipart=>true
|
127
|
+
puts "Raw response is #{ response.to_str }" if HmxClient::Command.debug?
|
128
|
+
if (response.length > 0)
|
129
|
+
return JSON.parse(response.to_str)
|
130
|
+
else
|
131
|
+
return ""
|
132
|
+
end
|
133
|
+
end
|
134
|
+
def standardRequest(prefix, commandName, params, returnPart)
|
135
|
+
response = performRequest(prefix, commandName, params)
|
136
|
+
puts "JSON response is #{ response }" if HmxClient::Command.debug?
|
137
|
+
if response['inError']
|
138
|
+
raise HmxException.new(response['exception']), "Error returned from server"
|
139
|
+
end
|
140
|
+
return response[returnPart]
|
141
|
+
end
|
142
|
+
def getSenderHash()
|
143
|
+
hash = Hash.new
|
144
|
+
hash['context'] = @context if @context
|
145
|
+
return hash
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|