you can add usage in changelog
Thanks, Shenwei
On Fri, Jan 15, 2021 at 11:36:13AM +0800, Ren Wen wrote:
Signed-off-by: Ren Wen 15991987063@163.com
container/libvirt-helper/libvirt_app.rb | 37 +++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 container/libvirt-helper/libvirt_app.rb
diff --git a/container/libvirt-helper/libvirt_app.rb b/container/libvirt-helper/libvirt_app.rb new file mode 100755 index 0000000..551dfc4 --- /dev/null +++ b/container/libvirt-helper/libvirt_app.rb @@ -0,0 +1,37 @@ +#!/usr/bin/env ruby +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# frozen_string_literal: true
+require 'sinatra' +require 'digest/md5'
+configure do
- set :bind, '0.0.0.0'
- set :port, ENV['LIBVIRT_HELPER_PORT']
+end
+LIBVIRT_PATH = ENV['LIBVIRT_PATH'] +VERSION = '0.1'
+get '/' do
- "version: #{VERSION}"
+end
+post '/upload' do
- if params[:file] && (tempfile = params[:file][:tempfile]) && (filename = params[:file][:filename])
- dirname = File.basename(filename, '.xml')
- content = tempfile.read
- md5_filename = Digest::MD5.hexdigest(content) + '.xml'
- dir_path = "#{LIBVIRT_PATH}/#{dirname}"
- Dir.exist?(dir_path) || Dir.mkdir(dir_path)
- target = "#{dir_path}/#{md5_filename}"
- File.open(target, 'wb') { |f| f.write content }
- File.join(dirname, md5_filename)
- else
- ''
- end
+end
2.23.0