rest-ftp-daemon 0.221.2 → 0.222.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rest-ftp-daemon (0.221.2)
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.2)
64
- minitest (5.6.1)
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
+ [![Gem Version](https://badge.fury.io/rb/rest-ftp-daemon.svg)](http://badge.fury.io/rb/rest-ftp-daemon)
5
+ [![Code Climate](https://codeclimate.com/github/bmedici/rest-ftp-daemon/badges/gpa.svg)](https://codeclimate.com/github/bmedici/rest-ftp-daemon)
6
+ [![Test Coverage](https://codeclimate.com/github/bmedici/rest-ftp-daemon/badges/coverage.svg)](https://codeclimate.com/github/bmedici/rest-ftp-daemon/coverage)
4
7
 
5
- This is a pretty simple FTP client daemon, controlled through a RESTful API.
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
@@ -1,3 +1,10 @@
1
1
  # encoding: utf-8
2
2
  require "bundler/gem_tasks"
3
- require 'rubygems'
3
+ require "rubygems"
4
+
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ # Run specs by default
9
+ desc 'Run all tests'
10
+ task :default => :spec
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 'optparse'
8
- require 'socket'
9
- # require 'timeout'
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.to_s}")
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('-v', '--version', "Show version (#{APP_VER})") { puts APP_VER; exit }
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 Exception => e
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 ? 'YES' : "no (PID: #{Process.pid})"}"
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__), 'lib'))
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 'rest-ftp-daemon'
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] == ['admin', Settings.adminpwd]
20
+ [username, password] == ["admin", Settings.adminpwd]
21
21
  end
22
22
  end
23
23
 
@@ -1,49 +1,49 @@
1
1
  # Global libs
2
- require 'rubygems'
2
+ require "rubygems"
3
3
  require "settingslogic"
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'
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 'newrelic_rpm'
23
- require 'get_process_mem'
22
+ require "newrelic_rpm"
23
+ require "get_process_mem"
24
24
 
25
25
 
26
26
  # Project's libs
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'
39
- require 'rest-ftp-daemon/worker_conchita'
40
- require 'rest-ftp-daemon/worker_job'
41
- require 'rest-ftp-daemon/worker_pool'
42
- require 'rest-ftp-daemon/job'
43
- require 'rest-ftp-daemon/notification'
44
- require 'rest-ftp-daemon/api/root'
45
- require 'rest-ftp-daemon/api/jobs'
46
- require 'rest-ftp-daemon/api/dashboard'
47
- require 'rest-ftp-daemon/api/status'
48
- require 'rest-ftp-daemon/api/debug'
49
- require 'rest-ftp-daemon/api/job_presenter'
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 Root < Grape::API
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 '/' do
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['api.format'] = :html
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, options| object.wid.nil? }
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 Root < Grape::API
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: 'ID of the Job to read', regexp: /[^\/]+/
19
+ requires :id, type: String, desc: "ID of the Job to read", regexp: /[^\/]+/
10
20
  end
11
- get '/jobs/*id' do
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
- status 404
23
- api_error exception
24
- rescue RestFtpDaemonException => exception
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
- status 501
31
- api_error exception
36
+ error!({error: :api_exception, message: exception.message}, 500)
37
+
32
38
  else
33
39
  status 200
34
- present job, :with => RestFtpDaemon::API::Entities::JobPresenter, type: "complete"
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 '/jobs/' do
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 RestFtpDaemonException => exception
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
- status 501
62
- api_error exception
59
+ error!({error: :api_exception, message: exception.message}, 500)
60
+
63
61
  else
64
62
  status 200
65
- present jobs, :with => RestFtpDaemon::API::Entities::JobPresenter
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
- optional :overwrite, type: Boolean, desc: "overwrites files at target server",
79
+ optional :overwrite,
80
+ type: Boolean,
81
+ desc: "Overwrites files at target server",
83
82
  default: Settings.transfer[:overwrite]
84
- optional :mkdir, type: Boolean, desc: "create missing directories on target server",
83
+ optional :mkdir,
84
+ type: Boolean,
85
+ desc: "Create missing directories on target server",
85
86
  default: Settings.transfer[:mkdir]
86
- optional :tempfile, type: Boolean, desc: "upload to a temp file before renaming it to the target filename",
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 '/jobs/' do
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
- status 406
108
- api_error exception
110
+ error!({error: :api_parse_error, message: exception.message}, 422)
111
+
109
112
  rescue RestFtpDaemonException => exception
110
113
  log_error "RestFtpDaemonException: #{exception.message}"
111
- status 412
112
- api_error exception
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, :with => RestFtpDaemon::API::Entities::JobPresenter, hide_params: true
118
+ present job, with: RestFtpDaemon::API::Entities::JobPresenter, hide_params: true
119
+
120
120
  end
121
121
  end
122
122