mkit 0.4.1 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fbf4273a9458c659131f42dff9f804d23632b282bb6ee04d803c8e8623262fa1
4
- data.tar.gz: f9c7cdff9a122c90c714fd16de80bfc07f19ded8d88806d2b7e7f3af2f7dc246
3
+ metadata.gz: fb997b1bc61151dde6209eeaefdf4f669df9255b7e69735eb0c5c56e346222f1
4
+ data.tar.gz: 3819a29d9335a2d4831051d133d9e0056b93d54803701a27ed596a750f907d7b
5
5
  SHA512:
6
- metadata.gz: e0975eb515e8b4b91006953f293206b02b1b377a3668b8478af9dfa84f9a58216cbbe83928c8458bb3d9676543cb748dedfa00c26f65279ffe59f15f847cab5d
7
- data.tar.gz: d790f9aa1edcac942df9a72317295c9c091eb88ec029d2584c0275bbd7740fe94272504a984a3248d0aa1d77949e7343ee189fa0018b5724ecfd0de44308a567
6
+ metadata.gz: c95a967e4a016554700b9e844de87481fd8f4b1f71e2cb4cdae16509104b177485f6cdcc3aa114f3d4ab8680e8d39fb05c125fca4dd81edbb089800d08ec275e
7
+ data.tar.gz: f62ac16133370c7bc41f901fe148b708c046f4598331848daefd4bb108419f7b2fc510a9176bff771fbff3afa4e38d5ce000d70d8cad1feeb41b8f339956d802
@@ -0,0 +1,22 @@
1
+ name: Publish Gem
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - v[0-9]*.[0-9]*.[0-9]*
7
+
8
+ jobs:
9
+ build:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v3
13
+ - name: Publish to RubyGems
14
+ run: |
15
+ mkdir -p $HOME/.gem
16
+ touch $HOME/.gem/credentials
17
+ chmod 0600 $HOME/.gem/credentials
18
+ printf -- "---\n:rubygems_api_key: ${RUBYGEMS_API_KEY}\n" > $HOME/.gem/credentials
19
+ gem build *.gemspec
20
+ gem push *.gem
21
+ env:
22
+ RUBYGEMS_API_KEY: "${{secrets.RUBYGEMS_API_KEY}}"
data/.rubocop.yml ADDED
@@ -0,0 +1,10 @@
1
+ # The behavior of RuboCop can be controlled via the .rubocop.yml
2
+ # configuration file. It makes it possible to enable/disable
3
+ # certain cops (checks) and to alter their behavior if they accept
4
+ # any parameters. The file can be placed either in your home
5
+ # directory or in some project directory.
6
+ #
7
+ # RuboCop will start looking for the configuration file in the directory
8
+ # where the inspected file is and continue its way up to the root directory.
9
+ #
10
+ # See https://docs.rubocop.org/rubocop/configuration
data/Gemfile CHANGED
@@ -1,21 +1,23 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
2
 
3
- #ruby '2.6.10'
3
+ source 'https://rubygems.org'
4
+
5
+ # ruby '3.0.2'
4
6
 
5
- gem 'net-ping'
6
7
  gem 'dry-container'
8
+ gem 'net-ping'
9
+ gem 'rake'
7
10
  gem 'sqlite3'
8
11
  gem 'standalone_migrations'
12
+ gem 'text-table'
9
13
 
10
- gem 'sinatra-activerecord', :require => 'sinatra/activerecord'
11
- gem 'rack', '>= 2.0.6'
14
+ gem 'async-dns'
12
15
  gem 'pry'
16
+ gem 'rack', '>= 2.0.6'
13
17
  gem 'rubydns'
14
- gem 'async-dns'
18
+ gem 'sinatra-activerecord'
15
19
  # rest http server
20
+ gem 'net_http_unix' # socket client
16
21
  gem 'sinatra'
17
22
  gem 'thin' # socket server
18
- gem 'net_http_unix' # socket client
19
- #gem 'puma'
20
-
21
-
23
+ # gem 'puma'
data/Gemfile.lock CHANGED
@@ -104,6 +104,7 @@ GEM
104
104
  nokogiri (~> 1.14)
105
105
  railties (>= 6.0.0, < 7.1.0)
106
106
  rake (>= 10.0)
107
+ text-table (1.2.4)
107
108
  thin (1.8.2)
108
109
  daemons (~> 1.0, >= 1.0.9)
109
110
  eventmachine (~> 1.0, >= 1.0.4)
@@ -126,11 +127,13 @@ DEPENDENCIES
126
127
  net_http_unix
127
128
  pry
128
129
  rack (>= 2.0.6)
130
+ rake
129
131
  rubydns
130
132
  sinatra
131
133
  sinatra-activerecord
132
134
  sqlite3
133
135
  standalone_migrations
136
+ text-table
134
137
  thin
135
138
 
136
139
  BUNDLED WITH
data/README.md CHANGED
@@ -53,35 +53,47 @@ There's also samples on the samples dir, for daemontools and systemd.
53
53
 
54
54
  ### Accessing the API
55
55
 
56
- * Create new service
57
- * `mkitc create samples/apps/rabbitmq.yml`
58
- * Update service
59
- * `mkitc update samples/apps/rabbitmq.yml`
60
- * Get service
61
- * `mkitc ps {id|service_name}`
62
- * Delete service
63
- * `mkitc rm {id|service_name}`
64
- * List services
65
- * `mkitc ps [-v (verbose)]`
66
- * Control service
67
- * `mkitc start {id|service_name}`
68
- * `mkitc stop {id|service_name}`
56
+ A client is provided to interact with mkit server.
57
+
58
+ Run `mkitc help` to list current supported commands.
59
+
60
+ ```
61
+ Usage: mkitc <command> [options]
62
+
63
+ Micro k8s on Ruby - a simple tool to mimic a (very) minimalistic k8 cluster
64
+
65
+ Commands:
66
+
67
+ ps show services status (alias for status)
68
+ status show services status
69
+ logs prints service logs
70
+ start start service
71
+ stop stop service
72
+ restart restart service
73
+ create create new service
74
+ update update service
75
+ rm remove service
76
+ version prints mkit server version
77
+ proxy haproxy status and control
78
+
79
+ Run 'mkitc help <command>' for specific command information.
80
+ ```
69
81
 
70
82
  Example:
71
83
 
72
84
  ```
73
85
  $ mkitc ps postgres
74
- id name addr ports status
75
- 4 postgres 10.210.198.10 tcp/5432 RUNNING
76
- pods
77
- id pod_id pod_name pod_ip status
78
- 19 4ce31a007211 5d148a16f3aa 172.17.0.2 RUNNING
86
+ +----+----------+---------------+----------+--------------+---------+
87
+ | id | name | addr | ports | pods | status |
88
+ +----+----------+---------------+----------+--------------+---------+
89
+ | 2 | postgres | 10.210.198.10 | tcp/4532 | 49b5e4c8f247 | RUNNING |
90
+ +----+----------+---------------+----------+--------------+---------+
79
91
  ```
80
92
  The service `postgres` is available on IP `10.210.198.10:5432`
81
93
 
82
94
  ## Configuration
83
95
 
84
- On startup, configuration files on `config` directory will be copied to `/etc/mkit`. HAProxy config dir and control commands are defined on `mkit_config.yml`
96
+ On startup, configuration files on `config` directory will be copied to `/etc/mkit`. HAProxy config directory and control commands are defined on `mkit_config.yml`
85
97
 
86
98
  You must configure `haproxy` to use config directory. e.g. on Ubuntu
87
99
 
@@ -115,8 +127,8 @@ service:
115
127
  - 5672:5672:tcp:round_robin
116
128
  - 80:15672:http:round_robin
117
129
  resources:
118
- max_replicas: 1
119
- min_replicas: 1
130
+ min_replicas: 1 # default value
131
+ max_replicas: 1 # default value
120
132
  volumes:
121
133
  - docker://mkit_rabbitmq_data:/var/lib/rabbitmq # a docker volume - it will be created if it does not exists
122
134
  - /var/log/rabbitmq/logs:/var/log/rabbitmq # a local volume
data/Rakefile CHANGED
@@ -1,42 +1,45 @@
1
- ENV["SINATRA_ENV"] ||= "development"
1
+ # frozen_string_literal: true
2
+
3
+ ENV['SINATRA_ENV'] ||= 'development'
2
4
 
3
5
  require 'rubygems'
4
- require 'sinatra/activerecord/rake'
5
6
  require 'standalone_migrations'
6
7
  require 'rubygems/package_task'
7
8
  require 'rubygems/specification'
8
9
  require 'rake/testtask'
9
10
  require 'pry'
10
11
  require 'fileutils'
12
+ require 'bundler'
11
13
  require 'bundler/setup'
12
14
  require 'dry-container'
13
15
  require 'sinatra/activerecord'
16
+ require 'sinatra/activerecord/rake'
14
17
  require 'rubydns'
15
18
  require_relative 'lib/mkit/version.rb'
16
19
  require_relative 'lib/mkit/utils'
17
20
  require_relative 'lib/mkit'
18
21
 
19
22
  $LOAD_PATH.unshift File.expand_path('lib')
20
- rails_env=ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
23
+ rails_env = ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
21
24
  # db migrations, use database config
22
- ENV["DATABASE_URL"]=MKIt::Utils.db_config_to_uri(rails_env)
25
+ ENV['DATABASE_URL'] = MKIt::Utils.db_config_to_uri(rails_env)
23
26
 
24
27
  desc 'Builds the gem'
25
28
  task :package do
26
- sh %{gem build "mkit.gemspec"}
29
+ sh %(gem build "mkit.gemspec")
27
30
  end
28
31
 
29
- task :install => [:package] do
30
- sh %{gem install mkit-#{MKIt::VERSION}.gem}
32
+ task install: [:package] do
33
+ sh %(gem install mkit-#{MKIt::VERSION}.gem)
31
34
  end
32
35
 
33
36
  desc 'Copy rb to packaging dir'
34
- task :build => [:init] do
35
- FileUtils.cp_r('app', 'target/build', {:remove_destination=>true})
36
- FileUtils.cp_r('config', 'target/build', {:remove_destination=>true})
37
- FileUtils.cp_r('bin', 'target/build', {:remove_destination=>true})
38
- FileUtils.cp_r('lib', 'target/build', {:remove_destination=>true})
39
- FileUtils.cp_r('config.ru', 'target/build', {:remove_destination=>true})
37
+ task build: [:init] do
38
+ FileUtils.cp_r('app', 'target/build', { remove_destination: true })
39
+ FileUtils.cp_r('config', 'target/build', { remove_destination: true })
40
+ FileUtils.cp_r('bin', 'target/build', { remove_destination: true })
41
+ FileUtils.cp_r('lib', 'target/build', { remove_destination: true })
42
+ FileUtils.cp_r('config.ru', 'target/build', { remove_destination: true })
40
43
  end
41
44
 
42
45
  desc 'Create build dirs'
@@ -45,10 +48,9 @@ task :init do
45
48
  FileUtils.mkdir_p('target/package')
46
49
  end
47
50
 
48
- desc "Rake Console"
51
+ desc 'Rake Console'
49
52
  task :console do
50
53
  Pry.start
51
54
  end
52
55
 
53
56
  StandaloneMigrations::Tasks.load_tasks
54
-
data/bin/mkitc CHANGED
@@ -8,104 +8,279 @@ require 'net/http'
8
8
  require 'json'
9
9
  require 'net_http_unix'
10
10
  require 'securerandom'
11
+ require 'erb'
11
12
 
12
- class MKItClient
13
+ class InvalidParametersException < RuntimeError
14
+ attr_reader :command
15
+ def initialize(cause, command = nil)
16
+ super(cause)
17
+ @command = command
18
+ end
19
+ end
13
20
 
21
+ class MKItClient
14
22
  def initialize
15
- @client = NetX::HTTPUnix.new("localhost",4567)
23
+ @client = NetX::HTTPUnix.new('localhost', 4567)
16
24
  end
17
25
 
18
- def parse_args(args)
19
- request = nil
20
- case args[0]
21
- when /^ps$/
22
- if args.include?('-v')
23
- params = {verbose: 'true'}
24
- args.delete('-v')
25
- else
26
- params = {}
27
- end
28
- case args.size
29
- when 1
30
- #mkitc ps [-v] GET services[?verbose=true]
31
- request = { verb: :get, uri: '/services', params: params }
32
- when 2
33
- #mkitc ps {id} GET services/{id}
34
- id = args[1]
35
- request = { verb: :get, uri: "/services/#{id}" }
36
- else
37
- raise 'invalid parameters'
38
- end
39
- when /^config:show$/
40
- #mkitc config:show {id} => GET services/{id}/config
41
- #TODO
42
- when /^stop$/
43
- #mkitc stop {id} => PUT services/{id}/stop
44
- case args.size
45
- when 2
46
- id = args[1]
47
- request = { verb: :put, uri: "/services/#{id}/stop" }
48
- else
49
- raise 'invalid parameters'
26
+ def dict
27
+ global_args = [
28
+ { short: '-v', long: '--verbose', help: 'verbose', mandatory: false, value: nil }
29
+ ]
30
+ command_dict = [
31
+ {
32
+ cmd: 'ps',
33
+ args: [
34
+ { name: 'id', mandatory: false, uri: '/<%=id%>' }
35
+ ],
36
+ help: 'show services status (alias for status)',
37
+ usage: ['[service_id_or_name]'],
38
+ request: { verb: :get, uri: '/services' }
39
+ },
40
+ {
41
+ cmd: 'status',
42
+ args: [
43
+ { name: 'id', mandatory: false, uri: '/<%=id%>' }
44
+ ],
45
+ help: 'show services status',
46
+ usage: ['[service_id_or_name]'],
47
+ request: { verb: :get, uri: '/services' }
48
+ },
49
+ {
50
+ cmd: 'logs',
51
+ args: [
52
+ { name: 'id', mandatory: true }
53
+ ],
54
+ help: 'prints service logs',
55
+ usage: ['<service_id_or_name>'],
56
+ request: { verb: :get, uri: '/services/<%=id%>/logs' }
57
+ },
58
+ {
59
+ cmd: 'start',
60
+ args: [
61
+ { name: 'id', mandatory: true }
62
+ ],
63
+ help: 'start service',
64
+ usage: ['<service_id_or_name>'],
65
+ request: { verb: :put, uri: '/services/<%=id%>/start' }
66
+ },
67
+ {
68
+ cmd: 'stop',
69
+ args: [
70
+ { name: 'id', mandatory: true }
71
+ ],
72
+ help: 'stop service',
73
+ usage: ['<service_id_or_name>'],
74
+ request: { verb: :put, uri: '/services/<%=id%>/stop' }
75
+ },
76
+ {
77
+ cmd: 'restart',
78
+ args: [
79
+ { name: 'id', mandatory: true }
80
+ ],
81
+ help: 'restart service',
82
+ usage: ['<service_id_or_name>'],
83
+ request: { verb: :put, uri: '/services/<%=id%>/restart' }
84
+ },
85
+ {
86
+ cmd: 'create',
87
+ args: [
88
+ { name: 'file', mandatory: true }
89
+ ],
90
+ help: 'create new service',
91
+ usage: ['<service.yaml>'],
92
+ request: { verb: :post, uri: '/services' }
93
+ },
94
+ {
95
+ cmd: 'update',
96
+ args: [
97
+ { name: 'file', mandatory: true }
98
+ ],
99
+ help: 'update service',
100
+ usage: ['<service.yaml>'],
101
+ request: { verb: :put, uri: '/services/<%=id%>' }
102
+ },
103
+ {
104
+ cmd: 'rm',
105
+ args: [
106
+ { name: 'id', mandatory: true }
107
+ ],
108
+ help: 'remove service',
109
+ usage: ['<service_id_or_name>'],
110
+ request: { verb: :delete, uri: '/services/<%=id%>' }
111
+ },
112
+ {
113
+ cmd: 'version',
114
+ help: 'prints mkit server version',
115
+ request: { verb: :get, uri: '/mkit/version' }
116
+ },
117
+ {
118
+ cmd: 'proxy',
119
+ options: [
120
+ {
121
+ cmd: 'start',
122
+ request: { verb: :put, uri: '/mkit/proxy/start' },
123
+ help: 'start proxy service'
124
+ },
125
+ {
126
+ cmd: 'stop',
127
+ request: { verb: :put, uri: '/mkit/proxy/stop' },
128
+ help: 'stop proxy service'
129
+ },
130
+ {
131
+ cmd: 'restart',
132
+ request: { verb: :put, uri: '/mkit/proxy/restart' },
133
+ help: 'restarts proxy service'
134
+ },
135
+ {
136
+ cmd: 'status',
137
+ request: { verb: :get, uri: '/mkit/proxy/status' },
138
+ help: 'proxy service status'
139
+ }
140
+ ],
141
+ help: 'haproxy status and control',
142
+ usage: ['<start|stop|restart|status>']
143
+ }
144
+ ]
145
+ command_dict
146
+ end
147
+
148
+ def help(cause: nil, cmd: nil)
149
+ msg = ''
150
+ if cause.nil?
151
+ my_cmd = cmd
152
+ else
153
+ msg += "MKItc: #{cause.message}\n"
154
+ my_cmd = cause.command
155
+ end
156
+ if my_cmd.nil?
157
+ msg += "\nUsage: mkitc <command> [options]\n\n"
158
+ msg += "Micro k8s on Ruby - a simple tool to mimic a (very) minimalistic k8 cluster\n\n"
159
+ msg += "Commands:\n\n"
160
+ dict.each do |c|
161
+ msg += format("%-10s %s\n", c[:cmd], c[:help])
50
162
  end
51
- when /^start$/
52
- #mkitc start {id} => PUT services/{id}/start
53
- case args.size
54
- when 2
55
- id = args[1]
56
- request = { verb: :put, uri: "/services/#{id}/start" }
57
- else
58
- raise 'invalid parameters'
163
+ msg += "\n"
164
+ msg += "Run 'mkitc help <command>' for specific command information.\n\n"
165
+ else
166
+ msg += format("\nUsage: mkitc %s %s\n\n", my_cmd[:cmd], my_cmd[:usage].nil? ? '' : my_cmd[:usage].join(' '))
167
+ msg += format("%s\n", my_cmd[:help])
168
+ unless my_cmd[:options].nil?
169
+ msg += "\nOptions:\n"
170
+ my_cmd[:options].each do |c|
171
+ msg += format("%-10s %s\n", c[:cmd], c[:help])
172
+ end
59
173
  end
60
- when /^rm$/
61
- #mkitc rm {id} => DELETE services/{id}
62
- case args.size
63
- when 2
64
- id = args[1]
65
- request = { verb: :delete, uri: "/services/#{id}" }
66
- else
67
- raise 'invalid parameters'
174
+ msg += "\n"
175
+ end
176
+ puts msg
177
+ exit 1
178
+ end
179
+
180
+ def create(request, request_hash = nil)
181
+ unless File.file?(request_hash[:file])
182
+ raise InvalidParametersException.new('File not found.', c = dict.select { |k| k[:cmd] == 'create' }.first)
183
+ end
184
+
185
+ yaml = YAML.load_file(request_hash[:file])
186
+ if yaml['service'].nil?
187
+ raise InvalidParametersException.new('Invalid configuration file', c = dict.select { |k| k[:cmd] == 'create' }.first)
188
+ else
189
+ request(request, request_hash)
190
+ end
191
+ end
192
+
193
+ def update(request, request_hash = nil)
194
+ unless File.file?(request_hash[:file])
195
+ raise InvalidParametersException.new('File not found.', c = dict.select { |k| k[:cmd] == 'update' }.first)
196
+ end
197
+
198
+ yaml = YAML.load_file(request_hash[:file])
199
+ if yaml['service'].nil?
200
+ raise InvalidParametersException.new('Invalid configuration file', c = dict.select { |k| k[:cmd] == 'update' }.first)
201
+ else
202
+ id = yaml['service']['name']
203
+ request_hash[:id] = id
204
+ request(request, request_hash)
205
+ end
206
+ end
207
+
208
+ def parse_args(args)
209
+ cmd = args[0]
210
+ c = nil
211
+ # short circuit for help
212
+ if cmd == 'help' || args.empty?
213
+ if args.size > 1
214
+ c = dict.select { |k| k[:cmd] == args[1] }.first
215
+ raise InvalidParametersException, "'#{args[1]}' is not a valid help topic." if c.nil?
68
216
  end
69
- when /^create$/
70
- #mkitc create service.yaml => POST services service.yaml
71
- case args.size
72
- when 2
73
- file = args[1]
74
- request = { verb: :post, uri: "/services", file: file }
75
- else
76
- raise 'invalid parameters'
217
+ return help(cmd: c)
218
+ else
219
+ c = dict.select { |k| k[:cmd] == cmd }.first
220
+ end
221
+ raise InvalidParametersException, 'Command not found' if c.nil?
222
+
223
+ myargs = args.dup
224
+ myargs.delete(cmd)
225
+
226
+ max_args_size = c[:args].nil? ? 0 : c[:args].size
227
+ max_options_size = c[:options].nil? ? 0 : 1
228
+ max_args_size += max_options_size
229
+
230
+ min_args_size = c[:args].nil? ? 0 : c[:args].select { |a| a[:mandatory] == true }.size
231
+ min_options_size = c[:options].nil? ? 0 : 1
232
+ min_args_size += min_options_size
233
+
234
+ if myargs.size > max_args_size || myargs.size < min_args_size
235
+ raise InvalidParametersException.new('Invalid parameters found.', c)
236
+ end
237
+
238
+ request_hash = {}
239
+ request = c[:request]
240
+ unless myargs.empty?
241
+ unless c[:args].nil?
242
+ idx = 0
243
+ c[:args].each do |a|
244
+ request_hash[a[:name].to_sym] = myargs[idx]
245
+ request[:uri] = request[:uri] + a[:uri] unless a[:uri].nil?
246
+ idx += 1
247
+ end
77
248
  end
78
- when /^update$/
79
- #mkitc update service.yaml => PUT services/{id} service.yaml
80
- case args.size
81
- when 2
82
- file = args[1]
83
- yaml = YAML.load_file(file)
84
- if yaml["service"].nil?
85
- raise 'invalid configuration file'
86
- else
87
- id = yaml["service"]["name"]
88
- request = { verb: :put, uri: "/services/#{id}", file: file }
249
+ # options
250
+ unless c[:options].nil?
251
+ option = nil
252
+ myargs.each do |s|
253
+ option = c[:options].select { |o| o[:cmd] == s }.first
254
+ raise InvalidParametersException.new('Invalid parameters found.', c) if option.nil? || option.empty?
89
255
  end
90
- else
91
- raise 'invalid parameters'
256
+ raise InvalidParametersException.new('Invalid parameters found.', c) if option.nil? || option.empty?
257
+
258
+ request = option[:request]
92
259
  end
260
+ end
261
+ raise InvalidParametersException, "Can't find request." if request.nil?
262
+
263
+ if respond_to? c[:cmd]
264
+ send(c[:cmd], request, request_hash)
93
265
  else
94
- raise "Usage: invalid parameters"
266
+ request(request, request_hash)
95
267
  end
96
- request
97
268
  end
98
269
 
99
270
  def doIt(args)
100
- operation = parse_args(args)
101
- puts request(operation).body
271
+ result = parse_args(args)
272
+ puts result
273
+ rescue InvalidParametersException => e
274
+ help(cause: e)
102
275
  end
103
276
 
104
- def request(request)
277
+ def request(request, request_args = nil)
105
278
  req = nil
106
- uri = request[:uri]
279
+ uri = ERB.new(request[:uri]).result_with_hash(request_args)
280
+ request[:file] = request_args[:file]
281
+
107
282
  unless request[:params].nil? || request[:params].empty?
108
- uri = uri + '?' + request[:params].map{|k,v| "#{k}=#{v}"}.join('&')
283
+ uri = uri + '?' + request[:params].map { |k, v| "#{k}=#{v}" }.join('&')
109
284
  end
110
285
  case request[:verb]
111
286
  when :post
@@ -113,14 +288,14 @@ class MKItClient
113
288
  unless request[:file].nil?
114
289
  (body, boundary) = attach(request[:file])
115
290
  req.body = body
116
- req["Content-Type"] = "multipart/form-data, boundary=#{boundary}"
291
+ req['Content-Type'] = "multipart/form-data, boundary=#{boundary}"
117
292
  end
118
293
  when :put
119
294
  req = Net::HTTP::Put.new(uri)
120
295
  unless request[:file].nil?
121
296
  (body, boundary) = attach(request[:file])
122
297
  req.body = body
123
- req["Content-Type"] = "multipart/form-data, boundary=#{boundary}"
298
+ req['Content-Type'] = "multipart/form-data, boundary=#{boundary}"
124
299
  end
125
300
  when :patch
126
301
  req = Net::HTTP::Patch.new(uri)
@@ -129,11 +304,11 @@ class MKItClient
129
304
  when :delete
130
305
  req = Net::HTTP::Delete.new(uri)
131
306
  end
132
- @client.request(req)
307
+ @client.request(req).body
133
308
  end
134
309
 
135
310
  def attach(file)
136
- boundary=SecureRandom.alphanumeric
311
+ boundary = SecureRandom.alphanumeric
137
312
  body = []
138
313
  body << "--#{boundary}\r\n"
139
314
  body << "Content-Disposition: form-data; name=file; filename='#{File.basename(file)}'\r\n"
@@ -141,7 +316,7 @@ class MKItClient
141
316
  body << "\r\n"
142
317
  body << File.read(file)
143
318
  body << "\r\n--#{boundary}--\r\n"
144
- [ body.join, boundary]
319
+ [body.join, boundary]
145
320
  end
146
321
  end
147
322
 
@@ -155,4 +330,3 @@ client.doIt(ARGV.dup)
155
330
  # parse args
156
331
  # host, socket, config file
157
332
  # end
158
-