rest-ftp-daemon 0.221.2 → 0.222.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.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/.rubocop.yml +859 -0
- data/Gemfile.lock +34 -3
- data/README.md +6 -1
- data/Rakefile +8 -1
- data/bin/rest-ftp-daemon +9 -9
- data/config.ru +3 -3
- data/lib/rest-ftp-daemon.rb +43 -43
- data/lib/rest-ftp-daemon/api/dashboard.rb +14 -4
- data/lib/rest-ftp-daemon/api/job_presenter.rb +1 -1
- data/lib/rest-ftp-daemon/api/jobs.rb +42 -42
- data/lib/rest-ftp-daemon/api/root.rb +37 -17
- data/lib/rest-ftp-daemon/constants.rb +8 -8
- data/lib/rest-ftp-daemon/helpers.rb +12 -13
- data/lib/rest-ftp-daemon/job.rb +24 -23
- data/lib/rest-ftp-daemon/job_queue.rb +8 -9
- data/lib/rest-ftp-daemon/logger.rb +2 -14
- data/lib/rest-ftp-daemon/logger_pool.rb +1 -1
- data/lib/rest-ftp-daemon/notification.rb +5 -5
- data/lib/rest-ftp-daemon/paginate.rb +4 -3
- data/lib/rest-ftp-daemon/settings.rb +11 -11
- data/lib/rest-ftp-daemon/uri.rb +2 -2
- data/lib/rest-ftp-daemon/views/dashboard_table.haml +1 -1
- data/lib/rest-ftp-daemon/worker.rb +1 -1
- data/lib/rest-ftp-daemon/worker_conchita.rb +3 -3
- data/lib/rest-ftp-daemon/worker_job.rb +3 -3
- data/lib/rest-ftp-daemon/worker_pool.rb +6 -9
- data/rest-ftp-daemon.gemspec +3 -1
- data/rest-ftp-daemon.yml.sample +12 -11
- data/spec/rest-ftp-daemon/features/dashboard_spec.rb +23 -0
- data/spec/spec_helper.rb +62 -0
- data/spec/support/config.yml +26 -0
- metadata +35 -4
- data/lib/rest-ftp-daemon/api/debug.rb +0 -31
- data/lib/rest-ftp-daemon/api/status.rb +0 -33
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rest-ftp-daemon (0.
|
4
|
+
rest-ftp-daemon (0.222.0)
|
5
5
|
double-bag-ftps
|
6
6
|
facter
|
7
7
|
get_process_mem
|
@@ -25,6 +25,7 @@ GEM
|
|
25
25
|
minitest (~> 5.1)
|
26
26
|
thread_safe (~> 0.3, >= 0.3.4)
|
27
27
|
tzinfo (~> 1.1)
|
28
|
+
addressable (2.3.8)
|
28
29
|
axiom-types (0.1.1)
|
29
30
|
descendants_tracker (~> 0.0.4)
|
30
31
|
ice_nine (~> 0.11.0)
|
@@ -35,6 +36,9 @@ GEM
|
|
35
36
|
daemons (1.2.2)
|
36
37
|
descendants_tracker (0.0.4)
|
37
38
|
thread_safe (~> 0.3, >= 0.3.1)
|
39
|
+
diff-lcs (1.2.5)
|
40
|
+
domain_name (0.5.24)
|
41
|
+
unf (>= 0.0.5, < 1.0.0)
|
38
42
|
double-bag-ftps (0.1.2)
|
39
43
|
equalizer (0.0.11)
|
40
44
|
eventmachine (1.0.7)
|
@@ -58,10 +62,19 @@ GEM
|
|
58
62
|
haml (4.0.6)
|
59
63
|
tilt
|
60
64
|
hashie (3.4.1)
|
65
|
+
http (0.8.12)
|
66
|
+
addressable (~> 2.3)
|
67
|
+
http-cookie (~> 1.0)
|
68
|
+
http-form_data (~> 1.0.1)
|
69
|
+
http_parser.rb (~> 0.6.0)
|
70
|
+
http-cookie (1.0.2)
|
71
|
+
domain_name (~> 0.5)
|
72
|
+
http-form_data (1.0.1)
|
73
|
+
http_parser.rb (0.6.0)
|
61
74
|
i18n (0.7.0)
|
62
75
|
ice_nine (0.11.1)
|
63
|
-
json (1.8.
|
64
|
-
minitest (5.
|
76
|
+
json (1.8.3)
|
77
|
+
minitest (5.7.0)
|
65
78
|
multi_json (1.11.0)
|
66
79
|
multi_xml (0.5.5)
|
67
80
|
newrelic_rpm (3.12.0.288)
|
@@ -71,6 +84,19 @@ GEM
|
|
71
84
|
rack-mount (0.8.3)
|
72
85
|
rack (>= 1.0.0)
|
73
86
|
rake (10.4.2)
|
87
|
+
rspec (3.2.0)
|
88
|
+
rspec-core (~> 3.2.0)
|
89
|
+
rspec-expectations (~> 3.2.0)
|
90
|
+
rspec-mocks (~> 3.2.0)
|
91
|
+
rspec-core (3.2.3)
|
92
|
+
rspec-support (~> 3.2.0)
|
93
|
+
rspec-expectations (3.2.1)
|
94
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
95
|
+
rspec-support (~> 3.2.0)
|
96
|
+
rspec-mocks (3.2.1)
|
97
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
98
|
+
rspec-support (~> 3.2.0)
|
99
|
+
rspec-support (3.2.2)
|
74
100
|
settingslogic (2.0.9)
|
75
101
|
sys-cpu (0.7.1)
|
76
102
|
ffi (>= 1.0.0)
|
@@ -85,6 +111,9 @@ GEM
|
|
85
111
|
timeout-extensions (0.0.0)
|
86
112
|
tzinfo (1.2.2)
|
87
113
|
thread_safe (~> 0.1)
|
114
|
+
unf (0.1.4)
|
115
|
+
unf_ext
|
116
|
+
unf_ext (0.0.7.1)
|
88
117
|
virtus (1.0.5)
|
89
118
|
axiom-types (~> 0.1)
|
90
119
|
coercible (~> 1.0)
|
@@ -96,5 +125,7 @@ PLATFORMS
|
|
96
125
|
|
97
126
|
DEPENDENCIES
|
98
127
|
bundler (~> 1.6)
|
128
|
+
http (~> 0.8)
|
99
129
|
rake
|
100
130
|
rest-ftp-daemon!
|
131
|
+
rspec (~> 3.1)
|
data/README.md
CHANGED
@@ -1,13 +1,18 @@
|
|
1
1
|
rest-ftp-daemon
|
2
2
|
====================================================================================
|
3
3
|
|
4
|
+
[](http://badge.fury.io/rb/rest-ftp-daemon)
|
5
|
+
[](https://codeclimate.com/github/bmedici/rest-ftp-daemon)
|
6
|
+
[](https://codeclimate.com/github/bmedici/rest-ftp-daemon/coverage)
|
4
7
|
|
5
|
-
|
8
|
+
|
9
|
+
A pretty simple FTP-client daemon, driven through a RESTful API.
|
6
10
|
|
7
11
|
API documentation is [maintained on Apiary](http://docs.restftpdaemon.apiary.io/)
|
8
12
|
|
9
13
|
|
10
14
|
|
15
|
+
|
11
16
|
Features
|
12
17
|
------------------------------------------------------------------------------------
|
13
18
|
|
data/Rakefile
CHANGED
data/bin/rest-ftp-daemon
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
# Try to load external libs
|
4
|
-
app_root = File.dirname(__FILE__) +
|
4
|
+
app_root = File.dirname(__FILE__) + "/../"
|
5
5
|
begin
|
6
6
|
require "thin"
|
7
|
-
require
|
8
|
-
require
|
9
|
-
# require
|
7
|
+
require "optparse"
|
8
|
+
require "socket"
|
9
|
+
# require "timeout"
|
10
10
|
require "settingslogic"
|
11
11
|
rescue LoadError
|
12
12
|
raise "EXITING: some of basic libs were not found: thin, optparse, socket, settingslogic"
|
@@ -15,7 +15,7 @@ end
|
|
15
15
|
|
16
16
|
# Load helpers and constants
|
17
17
|
[:constants, :helpers].each do |lib|
|
18
|
-
require File.expand_path("#{app_root}/lib/rest-ftp-daemon/#{lib
|
18
|
+
require File.expand_path("#{app_root}/lib/rest-ftp-daemon/#{lib}")
|
19
19
|
end
|
20
20
|
puts
|
21
21
|
|
@@ -36,7 +36,7 @@ parser = OptionParser.new do |opts|
|
|
36
36
|
opts.on("-g", "--group NAME", "Group to run daemon as (use with -u)"){ |group| options["group"] = group }
|
37
37
|
|
38
38
|
opts.on_tail("-h", "--help", "Show this message") { puts opts; exit }
|
39
|
-
opts.on_tail(
|
39
|
+
opts.on_tail("-v", "--version", "Show version (#{APP_VER})") { puts APP_VER; exit }
|
40
40
|
end
|
41
41
|
|
42
42
|
|
@@ -69,7 +69,7 @@ begin
|
|
69
69
|
|
70
70
|
rescue Psych::SyntaxError => e
|
71
71
|
abort "EXITING: config file syntax error: #{e.message}"
|
72
|
-
rescue
|
72
|
+
rescue StandardError => e
|
73
73
|
abort "EXITING: unknow error loading settings #{e.inspect}"
|
74
74
|
end
|
75
75
|
|
@@ -109,7 +109,7 @@ argv << command unless command.nil?
|
|
109
109
|
puts "--- #{APP_NAME} #{APP_VER}"
|
110
110
|
puts "Config file \t #{APP_CONF}"
|
111
111
|
puts "PID file \t #{Settings.pidfile}"
|
112
|
-
puts "Daemonize \t #{Settings.daemonize ?
|
112
|
+
puts "Daemonize \t #{Settings.daemonize ? "YES" : "no (PID: #{Process.pid})"}"
|
113
113
|
puts "Host \t #{Settings.host}"
|
114
114
|
puts "Namespace \t #{Settings.namespace}"
|
115
115
|
puts "Network port \t #{Settings.port}"
|
@@ -118,7 +118,7 @@ puts "Newrelic \t #{Settings.newrelic_enabled? ? Settings.at(:debug, :newrel
|
|
118
118
|
# puts Settings.dump
|
119
119
|
puts
|
120
120
|
puts "--- Thin ARGV"
|
121
|
-
puts argv.flatten.join(
|
121
|
+
puts argv.flatten.join(" ")
|
122
122
|
puts
|
123
123
|
|
124
124
|
|
data/config.ru
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Load gem files
|
2
|
-
load_path_libs = File.expand_path(File.join(File.dirname(__FILE__),
|
2
|
+
load_path_libs = File.expand_path(File.join(File.dirname(__FILE__), "lib"))
|
3
3
|
$LOAD_PATH.unshift(load_path_libs) unless $LOAD_PATH.include?(load_path_libs)
|
4
|
-
require
|
4
|
+
require "rest-ftp-daemon"
|
5
5
|
|
6
6
|
# Create global queue
|
7
7
|
$queue = RestFtpDaemon::JobQueue.new
|
@@ -17,7 +17,7 @@ end
|
|
17
17
|
# Rack authent
|
18
18
|
unless Settings.adminpwd.nil?
|
19
19
|
use Rack::Auth::Basic, "Restricted Area" do |username, password|
|
20
|
-
[username, password] == [
|
20
|
+
[username, password] == ["admin", Settings.adminpwd]
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
data/lib/rest-ftp-daemon.rb
CHANGED
@@ -1,49 +1,49 @@
|
|
1
1
|
# Global libs
|
2
|
-
require
|
2
|
+
require "rubygems"
|
3
3
|
require "settingslogic"
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
17
|
-
require
|
18
|
-
require
|
19
|
-
require
|
20
|
-
require
|
4
|
+
require "json"
|
5
|
+
require "grape"
|
6
|
+
require "grape-entity"
|
7
|
+
require "haml"
|
8
|
+
require "facter"
|
9
|
+
require "uri"
|
10
|
+
require "securerandom"
|
11
|
+
require "timeout"
|
12
|
+
require "sys/cpu"
|
13
|
+
require "syslog"
|
14
|
+
require "net/ftp"
|
15
|
+
require "net/http"
|
16
|
+
require "double_bag_ftps"
|
17
|
+
require "thread"
|
18
|
+
require "securerandom"
|
19
|
+
require "singleton"
|
20
|
+
require "logger"
|
21
21
|
|
22
|
-
require
|
23
|
-
require
|
22
|
+
require "newrelic_rpm"
|
23
|
+
require "get_process_mem"
|
24
24
|
|
25
25
|
|
26
26
|
# Project's libs
|
27
|
-
require
|
28
|
-
require
|
29
|
-
require
|
30
|
-
require
|
31
|
-
require
|
32
|
-
require
|
33
|
-
require
|
34
|
-
require
|
35
|
-
require
|
36
|
-
require
|
37
|
-
|
38
|
-
require
|
39
|
-
require
|
40
|
-
require
|
41
|
-
require
|
42
|
-
require
|
43
|
-
|
44
|
-
require
|
45
|
-
require
|
46
|
-
require
|
47
|
-
|
48
|
-
require
|
49
|
-
|
27
|
+
require "rest-ftp-daemon/constants"
|
28
|
+
require "rest-ftp-daemon/settings"
|
29
|
+
require "rest-ftp-daemon/exceptions"
|
30
|
+
require "rest-ftp-daemon/helpers"
|
31
|
+
require "rest-ftp-daemon/logger_helper"
|
32
|
+
require "rest-ftp-daemon/logger_pool"
|
33
|
+
require "rest-ftp-daemon/logger"
|
34
|
+
require "rest-ftp-daemon/paginate"
|
35
|
+
require "rest-ftp-daemon/uri"
|
36
|
+
require "rest-ftp-daemon/job_queue"
|
37
|
+
require "rest-ftp-daemon/worker"
|
38
|
+
require "rest-ftp-daemon/worker_conchita"
|
39
|
+
require "rest-ftp-daemon/worker_job"
|
40
|
+
require "rest-ftp-daemon/worker_pool"
|
41
|
+
require "rest-ftp-daemon/job"
|
42
|
+
require "rest-ftp-daemon/notification"
|
43
|
+
|
44
|
+
require "rest-ftp-daemon/api/job_presenter"
|
45
|
+
require "rest-ftp-daemon/api/jobs"
|
46
|
+
require "rest-ftp-daemon/api/dashboard"
|
47
|
+
|
48
|
+
require "rest-ftp-daemon/api/root"
|
49
|
+
|
@@ -1,18 +1,28 @@
|
|
1
1
|
module RestFtpDaemon
|
2
2
|
module API
|
3
|
-
class
|
4
|
-
|
3
|
+
class Dashbaord < Grape::API
|
5
4
|
|
6
5
|
####### HELPERS
|
7
6
|
|
8
7
|
helpers do
|
8
|
+
|
9
|
+
def logger
|
10
|
+
Root.logger
|
11
|
+
end
|
12
|
+
|
13
|
+
def render name, values={}
|
14
|
+
template = File.read("#{APP_LIBS}/views/#{name}.haml")
|
15
|
+
haml_engine = Haml::Engine.new(template)
|
16
|
+
haml_engine.render(binding, values)
|
17
|
+
end
|
18
|
+
|
9
19
|
end
|
10
20
|
|
11
21
|
|
12
22
|
####### DASHBOARD - GET /
|
13
23
|
|
14
24
|
# Server global status
|
15
|
-
get
|
25
|
+
get "/" do
|
16
26
|
log_info "GET /"
|
17
27
|
|
18
28
|
# Initialize Facter
|
@@ -40,7 +50,7 @@ module RestFtpDaemon
|
|
40
50
|
output = render :dashboard
|
41
51
|
|
42
52
|
# Send response
|
43
|
-
env[
|
53
|
+
env["api.format"] = :html
|
44
54
|
format "html"
|
45
55
|
status 200
|
46
56
|
content_type "text/html"
|
@@ -10,7 +10,7 @@ module RestFtpDaemon
|
|
10
10
|
Job::FIELDS.each { |name| expose name }
|
11
11
|
|
12
12
|
# Technical fields
|
13
|
-
expose :wid, unless: lambda { |object,
|
13
|
+
expose :wid, unless: lambda { |object, _options| object.wid.nil? }
|
14
14
|
|
15
15
|
expose :error
|
16
16
|
expose :status
|
@@ -1,14 +1,24 @@
|
|
1
1
|
module RestFtpDaemon
|
2
2
|
module API
|
3
|
-
class
|
3
|
+
class Jobs < Grape::API
|
4
|
+
|
5
|
+
####### HELPERS
|
6
|
+
|
7
|
+
helpers do
|
8
|
+
|
9
|
+
def logger
|
10
|
+
Root.logger
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
4
14
|
|
5
15
|
|
6
16
|
####### GET /jobs/:id
|
7
17
|
|
8
18
|
params do
|
9
|
-
requires :id, type: String, desc:
|
19
|
+
requires :id, type: String, desc: "ID of the Job to read", regexp: /[^\/]+/
|
10
20
|
end
|
11
|
-
get
|
21
|
+
get "/*id" do
|
12
22
|
log_info "GET /jobs/#{params[:id]}"
|
13
23
|
|
14
24
|
begin
|
@@ -19,21 +29,17 @@ module RestFtpDaemon
|
|
19
29
|
|
20
30
|
rescue RestFtpDaemon::JobNotFound => exception
|
21
31
|
log_error "JobNotFound: #{exception.message}"
|
22
|
-
|
23
|
-
|
24
|
-
rescue
|
25
|
-
log_error "RestFtpDaemonException: #{exception.message}"
|
26
|
-
status 500
|
27
|
-
api_error exception
|
28
|
-
rescue Exception => exception
|
32
|
+
error!({error: :api_job_not_found, message: exception.message}, 404)
|
33
|
+
|
34
|
+
rescue StandardError => exception
|
29
35
|
log_error "Exception: #{exception.message}"
|
30
|
-
|
31
|
-
|
36
|
+
error!({error: :api_exception, message: exception.message}, 500)
|
37
|
+
|
32
38
|
else
|
33
39
|
status 200
|
34
|
-
present job, :
|
35
|
-
end
|
40
|
+
present job, with: RestFtpDaemon::API::Entities::JobPresenter, type: "complete"
|
36
41
|
|
42
|
+
end
|
37
43
|
end
|
38
44
|
|
39
45
|
|
@@ -41,33 +47,25 @@ module RestFtpDaemon
|
|
41
47
|
|
42
48
|
desc "List all Jobs"
|
43
49
|
|
44
|
-
get
|
50
|
+
get "/" do
|
45
51
|
log_info "GET /jobs"
|
46
52
|
|
47
53
|
begin
|
48
|
-
# Detect QS filters
|
49
|
-
only = params["only"].to_s
|
50
|
-
|
51
54
|
# Get jobs to display
|
52
|
-
# jobs = $queue.sorted_by_status(only)
|
53
55
|
jobs = $queue.jobs
|
54
56
|
|
55
|
-
rescue
|
56
|
-
log_error "RestFtpDaemonException: #{exception.message}"
|
57
|
-
status 501
|
58
|
-
api_error exception
|
59
|
-
rescue Exception => exception
|
57
|
+
rescue StandardError => exception
|
60
58
|
log_error "Exception: #{exception.message}"
|
61
|
-
|
62
|
-
|
59
|
+
error!({error: :api_exception, message: exception.message}, 500)
|
60
|
+
|
63
61
|
else
|
64
62
|
status 200
|
65
|
-
present jobs, :
|
63
|
+
present jobs, with: RestFtpDaemon::API::Entities::JobPresenter
|
64
|
+
|
66
65
|
end
|
67
66
|
end
|
68
67
|
|
69
68
|
|
70
|
-
|
71
69
|
####### POST /jobs/
|
72
70
|
|
73
71
|
desc "Create a new job"
|
@@ -78,16 +76,21 @@ module RestFtpDaemon
|
|
78
76
|
optional :label, type: String, desc: "Descriptive label for this job"
|
79
77
|
optional :notify, type: String, desc: "URL to get POST'ed notifications back"
|
80
78
|
optional :priority, type: Integer, desc: "Priority level of the job (lower is stronger)"
|
81
|
-
|
82
|
-
|
79
|
+
optional :overwrite,
|
80
|
+
type: Boolean,
|
81
|
+
desc: "Overwrites files at target server",
|
83
82
|
default: Settings.transfer[:overwrite]
|
84
|
-
optional :mkdir,
|
83
|
+
optional :mkdir,
|
84
|
+
type: Boolean,
|
85
|
+
desc: "Create missing directories on target server",
|
85
86
|
default: Settings.transfer[:mkdir]
|
86
|
-
optional :tempfile,
|
87
|
+
optional :tempfile,
|
88
|
+
type: Boolean,
|
89
|
+
desc: "Upload to a temp file before renaming it to the target filename",
|
87
90
|
default: Settings.transfer[:tempfile]
|
88
91
|
end
|
89
92
|
|
90
|
-
post
|
93
|
+
post "/" do
|
91
94
|
log_info "POST /jobs", params
|
92
95
|
|
93
96
|
begin
|
@@ -104,19 +107,16 @@ module RestFtpDaemon
|
|
104
107
|
|
105
108
|
rescue JSON::ParserError => exception
|
106
109
|
log_error "JSON::ParserError: #{exception.message}"
|
107
|
-
|
108
|
-
|
110
|
+
error!({error: :api_parse_error, message: exception.message}, 422)
|
111
|
+
|
109
112
|
rescue RestFtpDaemonException => exception
|
110
113
|
log_error "RestFtpDaemonException: #{exception.message}"
|
111
|
-
|
112
|
-
|
113
|
-
rescue Exception => exception
|
114
|
-
log_error "Exception: #{exception.message}"
|
115
|
-
status 501
|
116
|
-
api_error exception
|
114
|
+
error!({error: :api_exception, message: exception.message}, 500)
|
115
|
+
|
117
116
|
else
|
118
117
|
status 201
|
119
|
-
present job, :
|
118
|
+
present job, with: RestFtpDaemon::API::Entities::JobPresenter, hide_params: true
|
119
|
+
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|