rest-ftp-daemon 0.400.0 → 0.410.0.pre.1

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.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +26 -6
  3. data/Rakefile +5 -3
  4. data/bin/rest-ftp-daemon +2 -1
  5. data/config.ru +8 -2
  6. data/lib/rest-ftp-daemon.rb +10 -2
  7. data/lib/rest-ftp-daemon/api/debug.rb +17 -5
  8. data/lib/rest-ftp-daemon/api/{job_presenter.rb → entities/job.rb} +25 -2
  9. data/lib/rest-ftp-daemon/api/entities/options.rb +15 -0
  10. data/lib/rest-ftp-daemon/api/jobs.rb +46 -13
  11. data/lib/rest-ftp-daemon/api/root-real.rb +80 -0
  12. data/lib/rest-ftp-daemon/api/root-test.rb +69 -0
  13. data/lib/rest-ftp-daemon/api/root.rb +21 -5
  14. data/lib/rest-ftp-daemon/constants.rb +18 -1
  15. data/lib/rest-ftp-daemon/counters.rb +0 -3
  16. data/lib/rest-ftp-daemon/exceptions.rb +16 -12
  17. data/lib/rest-ftp-daemon/helpers/api.rb +3 -3
  18. data/lib/rest-ftp-daemon/helpers/common.rb +12 -5
  19. data/lib/rest-ftp-daemon/helpers/views.rb +41 -11
  20. data/lib/rest-ftp-daemon/job.rb +118 -420
  21. data/lib/rest-ftp-daemon/job_queue.rb +34 -5
  22. data/lib/rest-ftp-daemon/jobs/dummy.rb +20 -0
  23. data/lib/rest-ftp-daemon/jobs/transfer.rb +319 -0
  24. data/lib/rest-ftp-daemon/jobs/video.rb +107 -0
  25. data/lib/rest-ftp-daemon/location.rb +125 -0
  26. data/lib/rest-ftp-daemon/path.rb +3 -0
  27. data/lib/rest-ftp-daemon/remote_ftp.rb +2 -2
  28. data/lib/rest-ftp-daemon/remote_sftp.rb +2 -2
  29. data/lib/rest-ftp-daemon/static/config.json +411 -0
  30. data/lib/rest-ftp-daemon/static/css/bootstrap.min.css +14 -0
  31. data/lib/rest-ftp-daemon/static/css/{bootstrap.css → bootstrap.old.css} +0 -0
  32. data/lib/rest-ftp-daemon/static/fonts/glyphicons-halflings-regular.eot +0 -0
  33. data/lib/rest-ftp-daemon/static/fonts/glyphicons-halflings-regular.svg +288 -0
  34. data/lib/rest-ftp-daemon/static/fonts/glyphicons-halflings-regular.ttf +0 -0
  35. data/lib/rest-ftp-daemon/static/fonts/glyphicons-halflings-regular.woff +0 -0
  36. data/lib/rest-ftp-daemon/static/fonts/glyphicons-halflings-regular.woff2 +0 -0
  37. data/lib/rest-ftp-daemon/static/swagger.html +83 -0
  38. data/lib/rest-ftp-daemon/static/swagger/css/print.css +1362 -0
  39. data/lib/rest-ftp-daemon/static/swagger/css/reset.css +125 -0
  40. data/lib/rest-ftp-daemon/static/swagger/css/screen.css +1489 -0
  41. data/lib/rest-ftp-daemon/static/swagger/css/style.css +250 -0
  42. data/lib/rest-ftp-daemon/static/swagger/css/typography.css +14 -0
  43. data/lib/rest-ftp-daemon/static/swagger/fonts/DroidSans-Bold.ttf +0 -0
  44. data/lib/rest-ftp-daemon/static/swagger/fonts/DroidSans.ttf +0 -0
  45. data/lib/rest-ftp-daemon/static/swagger/images/collapse.gif +0 -0
  46. data/lib/rest-ftp-daemon/static/swagger/images/expand.gif +0 -0
  47. data/lib/rest-ftp-daemon/static/swagger/images/explorer_icons.png +0 -0
  48. data/lib/rest-ftp-daemon/static/swagger/images/favicon-16x16.png +0 -0
  49. data/lib/rest-ftp-daemon/static/swagger/images/favicon-32x32.png +0 -0
  50. data/lib/rest-ftp-daemon/static/swagger/images/favicon.ico +0 -0
  51. data/lib/rest-ftp-daemon/static/swagger/images/logo_small.png +0 -0
  52. data/lib/rest-ftp-daemon/static/swagger/images/pet_store_api.png +0 -0
  53. data/lib/rest-ftp-daemon/static/swagger/images/throbber.gif +0 -0
  54. data/lib/rest-ftp-daemon/static/swagger/images/wordnik_api.png +0 -0
  55. data/lib/rest-ftp-daemon/static/swagger/lib/backbone-min.js +15 -0
  56. data/lib/rest-ftp-daemon/static/swagger/lib/es5-shim.js +2065 -0
  57. data/lib/rest-ftp-daemon/static/swagger/lib/handlebars-4.0.5.js +4608 -0
  58. data/lib/rest-ftp-daemon/static/swagger/lib/highlight.9.1.0.pack.js +2 -0
  59. data/lib/rest-ftp-daemon/static/swagger/lib/highlight.9.1.0.pack_extended.js +34 -0
  60. data/lib/rest-ftp-daemon/static/swagger/lib/jquery-1.8.0.min.js +2 -0
  61. data/lib/rest-ftp-daemon/static/swagger/lib/jquery.ba-bbq.min.js +18 -0
  62. data/lib/rest-ftp-daemon/static/swagger/lib/jquery.slideto.min.js +1 -0
  63. data/lib/rest-ftp-daemon/static/swagger/lib/jquery.wiggle.min.js +8 -0
  64. data/lib/rest-ftp-daemon/static/swagger/lib/js-yaml.min.js +3 -0
  65. data/lib/rest-ftp-daemon/static/swagger/lib/jsoneditor.min.js +11 -0
  66. data/lib/rest-ftp-daemon/static/swagger/lib/lodash.min.js +102 -0
  67. data/lib/rest-ftp-daemon/static/swagger/lib/marked.js +1272 -0
  68. data/lib/rest-ftp-daemon/static/swagger/lib/object-assign-pollyfill.js +23 -0
  69. data/lib/rest-ftp-daemon/static/swagger/lib/swagger-oauth.js +347 -0
  70. data/lib/rest-ftp-daemon/static/swagger/lib/swagger-ui.min.js +10 -0
  71. data/lib/rest-ftp-daemon/uri.rb +9 -1
  72. data/lib/rest-ftp-daemon/views/dashboard.haml +1 -1
  73. data/lib/rest-ftp-daemon/views/dashboard_footer.haml +6 -3
  74. data/lib/rest-ftp-daemon/views/dashboard_jobs.haml +3 -3
  75. data/lib/rest-ftp-daemon/views/dashboard_table.haml +25 -20
  76. data/lib/rest-ftp-daemon/workers/transfer.rb +14 -0
  77. data/rest-ftp-daemon.gemspec +14 -4
  78. data/spec/rest-ftp-daemon/features/swagger_spec.rb +24 -0
  79. data/spec/spec_helper.rb +4 -4
  80. metadata +119 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ddc0fb0b76fb6590512af92bcff70b63b03d770
4
- data.tar.gz: e43a27f7cc877d49bc965493aedd7a97cad1ff3a
3
+ metadata.gz: aef3a9c63e1ea02a0a3c79704750ab76ee2c8808
4
+ data.tar.gz: 9caa5c76fda9ae48b13a74d668967648a2c50e1c
5
5
  SHA512:
6
- metadata.gz: 0b39316f2dc7892f5b77fb27a6e7f9b46df8dbb43be7382218ca25d49681114be8d4e5b99ef8e59e341d18da62302322b1431bb789a8dbc11b15bdbdf241f53e
7
- data.tar.gz: b2a2e0a9c4f1a1737ce42e8e767c8ae3ffa19dfa30e12b63ebde9fd9492aa4f835436ed797c2fd93557392f5122a0f6a62255da738bd759faf57efa34ea9515a
6
+ metadata.gz: d24876af6c2818633132aef618fe808c1f09d4f624c01c436dfcd1217e455eaaa851fd07381cbe9f8f3b3f9aa54bd6ea54384f8ce8dcb556a29acb32f9e96349
7
+ data.tar.gz: b2de79768b659cec1428f37ef3ae42f23d7c0ff6c8c282c8bf148a8e178017f7ac2d87a538849f8d6f554d3c8a7f0b59651f0edf291f5db20cc111f4e86ccd71
data/Gemfile.lock CHANGED
@@ -1,21 +1,25 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rest-ftp-daemon (0.400.0)
4
+ rest-ftp-daemon (0.410.0.pre.1)
5
5
  activesupport (~> 4.2)
6
6
  api-auth
7
- bmc-daemon-lib (~> 0.3.3)
7
+ bmc-daemon-lib (~> 0.3.4)
8
8
  double-bag-ftps
9
9
  facter
10
10
  get_process_mem
11
11
  grape
12
12
  grape-entity
13
+ grape-swagger
14
+ grape-swagger-entity
15
+ grape-swagger-representable
13
16
  haml
14
17
  json (~> 1.8)
15
18
  net-sftp
16
19
  newrelic_rpm
17
20
  rest-client (~> 1.8)
18
21
  settingslogic
22
+ streamio-ffmpeg
19
23
  sys-cpu
20
24
  thin (~> 1.7)
21
25
 
@@ -38,20 +42,22 @@ GEM
38
42
  descendants_tracker (~> 0.0.4)
39
43
  ice_nine (~> 0.11.0)
40
44
  thread_safe (~> 0.3, >= 0.3.1)
41
- bmc-daemon-lib (0.3.3)
45
+ bmc-daemon-lib (0.3.4)
42
46
  chamber (~> 2.9)
43
47
  builder (3.2.2)
44
- chamber (2.9.0)
48
+ chamber (2.9.1)
45
49
  hashie (~> 3.3)
46
50
  thor (~> 0.19.1)
47
51
  coderay (1.1.1)
48
52
  coercible (1.0.0)
49
53
  descendants_tracker (~> 0.0.1)
50
54
  daemons (1.2.4)
55
+ declarative (0.0.8)
56
+ uber (>= 0.0.15)
51
57
  descendants_tracker (0.0.4)
52
58
  thread_safe (~> 0.3, >= 0.3.1)
53
59
  diff-lcs (1.2.5)
54
- domain_name (0.5.20160615)
60
+ domain_name (0.5.20160826)
55
61
  unf (>= 0.0.5, < 1.0.0)
56
62
  double-bag-ftps (0.1.3)
57
63
  enumerable-lazy (0.0.1)
@@ -74,6 +80,14 @@ GEM
74
80
  grape-entity (0.5.1)
75
81
  activesupport
76
82
  multi_json (>= 1.3.2)
83
+ grape-swagger (0.23.0)
84
+ grape (>= 0.12.0)
85
+ grape-swagger-entity (0.1.4)
86
+ grape-entity
87
+ grape-swagger (>= 0.20.4)
88
+ grape-swagger-representable (0.1.3)
89
+ grape-swagger (>= 0.20.2)
90
+ representable
77
91
  haml (4.0.7)
78
92
  tilt
79
93
  hashie (3.4.4)
@@ -100,7 +114,7 @@ GEM
100
114
  net-ssh (>= 2.6.5)
101
115
  net-ssh (3.2.0)
102
116
  netrc (0.11.0)
103
- newrelic_rpm (3.16.1.320)
117
+ newrelic_rpm (3.16.2.321)
104
118
  parser (2.3.1.2)
105
119
  ast (~> 2.2)
106
120
  powerpack (0.1.1)
@@ -113,6 +127,9 @@ GEM
113
127
  rack (>= 0.4)
114
128
  rainbow (2.1.0)
115
129
  rake (11.2.2)
130
+ representable (3.0.0)
131
+ declarative (~> 0.0.5)
132
+ uber (~> 0.0.15)
116
133
  rest-client (1.8.0)
117
134
  http-cookie (>= 1.0.2, < 2.0)
118
135
  mime-types (>= 1.16, < 3.0)
@@ -139,6 +156,8 @@ GEM
139
156
  ruby-progressbar (1.8.1)
140
157
  settingslogic (2.0.9)
141
158
  slop (3.6.0)
159
+ streamio-ffmpeg (2.1.0)
160
+ multi_json (~> 1.8)
142
161
  sys-cpu (0.7.2)
143
162
  ffi
144
163
  thin (1.7.0)
@@ -150,6 +169,7 @@ GEM
150
169
  tilt (2.0.5)
151
170
  tzinfo (1.2.2)
152
171
  thread_safe (~> 0.1)
172
+ uber (0.0.15)
153
173
  unf (0.1.4)
154
174
  unf_ext
155
175
  unf_ext (0.0.7.2)
data/Rakefile CHANGED
@@ -5,12 +5,14 @@ require "rubygems"
5
5
  require "rspec/core/rake_task"
6
6
  RSpec::Core::RakeTask.new(:spec)
7
7
 
8
- # Run specs by default
9
- desc "Run all tests"
10
-
11
8
  require "rubocop/rake_task"
12
9
  RuboCop::RakeTask.new(:rubocop) do |task|
13
10
  task.fail_on_error = false
14
11
  end
15
12
 
13
+ # Load my own tasks
14
+ # Dir.glob('lib/tasks/*.rake').each { |r| import r }
15
+
16
+ # Run specs by default
17
+ desc "Run all tests"
16
18
  task default: [:spec, :rubocop]
data/bin/rest-ftp-daemon CHANGED
@@ -89,7 +89,8 @@ end
89
89
 
90
90
 
91
91
  # Thin: basic options
92
- thin_logfile = Conf.at(:logs, :thin)
92
+ thin_logfile = Conf.logfile_path(:thin)
93
+
93
94
  argv = []
94
95
  argv << ["-e", Conf.app_env]
95
96
  argv << ["-p", Conf[:port].to_s]
data/config.ru CHANGED
@@ -12,7 +12,14 @@ unless Conf[:adminpwd].nil?
12
12
  end
13
13
 
14
14
  # Serve static assets
15
- use Rack::Static, urls: ["/css", "/js", "/images"], root: "#{Conf.app_libs}/static/"
15
+ use Rack::Static, root: "#{Conf.app_libs}/static/", urls: [
16
+ "/css/",
17
+ "/js/",
18
+ "/fonts/",
19
+ "/images/",
20
+ "/swagger/",
21
+ MOUNT_SWAGGER_UI,
22
+ ]
16
23
 
17
24
  # Rack reloader and mini-profiler
18
25
  unless Conf.app_env == "production"
@@ -20,7 +27,6 @@ unless Conf.app_env == "production"
20
27
  # use Rack::MiniProfiler
21
28
  end
22
29
 
23
-
24
30
  # Initialize workers
25
31
  RestFtpDaemon::WorkerPool.instance.start_em_all
26
32
 
@@ -26,21 +26,29 @@ require_relative "rest-ftp-daemon/paginate"
26
26
  require_relative "rest-ftp-daemon/uri"
27
27
  require_relative "rest-ftp-daemon/job_queue"
28
28
  require_relative "rest-ftp-daemon/counters"
29
- require_relative "rest-ftp-daemon/job"
30
29
  require_relative "rest-ftp-daemon/notification"
31
30
 
32
31
  require_relative "rest-ftp-daemon/path"
32
+ require_relative "rest-ftp-daemon/location"
33
+
33
34
  require_relative "rest-ftp-daemon/remote"
34
35
  require_relative "rest-ftp-daemon/remote_ftp"
35
36
  require_relative "rest-ftp-daemon/remote_sftp"
36
37
 
38
+ require_relative "rest-ftp-daemon/job"
39
+ require_relative "rest-ftp-daemon/jobs/dummy"
40
+ require_relative "rest-ftp-daemon/jobs/transfer"
41
+ require_relative "rest-ftp-daemon/jobs/video"
42
+
37
43
  require_relative "rest-ftp-daemon/worker_pool"
38
44
  require_relative "rest-ftp-daemon/workers/worker"
39
45
  require_relative "rest-ftp-daemon/workers/conchita"
40
46
  require_relative "rest-ftp-daemon/workers/reporter"
41
47
  require_relative "rest-ftp-daemon/workers/transfer"
42
48
 
43
- require_relative "rest-ftp-daemon/api/job_presenter"
49
+ require_relative "rest-ftp-daemon/api/entities/options"
50
+ require_relative "rest-ftp-daemon/api/entities/job"
51
+
44
52
  require_relative "rest-ftp-daemon/api/jobs"
45
53
  require_relative "rest-ftp-daemon/api/dashboard"
46
54
  require_relative "rest-ftp-daemon/api/status"
@@ -23,7 +23,7 @@ module RestFtpDaemon
23
23
  me[:error] = job.error.encoding.to_s unless job.error.nil?
24
24
  me[:status] = job.status.encoding.to_s unless job.status.nil?
25
25
 
26
- Job::FIELDS.each do |name|
26
+ RestFtpDaemon::Job::FIELDS.each do |name|
27
27
  value = job.send(name)
28
28
  me[name] = value.encoding.to_s if value.is_a? String
29
29
  end
@@ -37,13 +37,25 @@ module RestFtpDaemon
37
37
  end
38
38
 
39
39
  ### ENDPOINTS
40
- desc "debug"
40
+ desc "debug"#, hidden: true
41
41
  get "/" do
42
- # Build response
43
- return {
42
+
43
+ # Extract routes
44
+ routes = []
45
+ RestFtpDaemon::API::Root.routes.each do |route|
46
+ routes << {
47
+ url: "#{route.options[:method]} #{route.pattern.path}",
48
+ vars: route.instance_variables,
49
+ options: route.options
50
+ }
51
+
52
+ end
53
+
54
+ # Build response
55
+ return {
44
56
  metrics: debug_metrics,
45
- routes: RestFtpDaemon::API::Root.routes,
46
57
  encodings: debug_encodings,
58
+ routes: routes,
47
59
  }
48
60
  end
49
61
 
@@ -3,12 +3,13 @@ require "grape-entity"
3
3
  module RestFtpDaemon
4
4
  module API
5
5
  module Entities
6
- class JobPresenter < Grape::Entity
6
+ class Job < Grape::Entity
7
+
7
8
  # Job ID
8
9
  expose :id
9
10
 
10
11
  # Job specific attributes and flags
11
- Job::FIELDS.each { |name| expose name }
12
+ RestFtpDaemon::Job::FIELDS.each { |name| expose name }
12
13
 
13
14
  # Technical fields
14
15
  expose :wid, unless: lambda { |object, _options| object.wid.nil? }
@@ -30,6 +31,28 @@ module RestFtpDaemon
30
31
  # Params
31
32
  expose :infos, unless: :hide_infos
32
33
 
34
+ # Options
35
+ # expose :options, using: API::Entities::Options
36
+ # expose :video_ac
37
+ # expose :video_custom
38
+
39
+ # with_options(format_with: :iso_timestamp) do
40
+ # expose :created_at
41
+ # expose :updated_at
42
+ # end
43
+
44
+ # expose :age do
45
+ # end
46
+
47
+ # expose :slots do |station,options|
48
+ # station.slots.map{ |slot| SlotEntity.new(slot).serializable_hash }
49
+ # end
50
+
51
+ private
52
+
53
+ def priv_func
54
+ end
55
+
33
56
  end
34
57
  end
35
58
  end
@@ -0,0 +1,15 @@
1
+ require "grape-entity"
2
+
3
+ module RestFtpDaemon
4
+ module API
5
+ module Entities
6
+ class Options < Grape::Entity
7
+
8
+ # expose :opt1, documentation: { type: 'Boolean', desc: 'opt UN', required: false }
9
+ expose :opt2
10
+ # expose :opt6
11
+
12
+ end
13
+ end
14
+ end
15
+ end
@@ -5,7 +5,11 @@ module RestFtpDaemon
5
5
  class Jobs < Grape::API
6
6
 
7
7
  ### ENDPOINTS
8
- desc "Read job with ID"
8
+ desc "Read job with ID", http_codes: [
9
+ { code: 200, message: "Here is the job you requested" },
10
+ { code: 404, message: "Job not found" }
11
+ ],
12
+ is_array: false
9
13
  params do
10
14
  requires :id, type: String, desc: "ID of the Job to read"
11
15
  end
@@ -16,6 +20,8 @@ module RestFtpDaemon
16
20
  job = RestFtpDaemon::JobQueue.instance.find_by_id(params[:id]) || RestFtpDaemon::JobQueue.instance.find_by_id(params[:id], true)
17
21
  raise RestFtpDaemon::JobNotFound if job.nil?
18
22
 
23
+ log_debug "found job: #{job.inspect}"
24
+
19
25
  rescue RestFtpDaemon::JobNotFound => exception
20
26
  log_error "JobNotFound: #{exception.message}"
21
27
  error!({ error: :api_job_not_found, message: exception.message }, 404)
@@ -26,12 +32,15 @@ module RestFtpDaemon
26
32
 
27
33
  else
28
34
  status 200
29
- present job, with: RestFtpDaemon::API::Entities::JobPresenter, type: "complete"
35
+ present job, with: RestFtpDaemon::API::Entities::Job, type: "complete"
30
36
 
31
37
  end
32
38
  end
33
39
 
34
- desc "List all Jobs"
40
+ desc "List all Jobs", http_codes: [
41
+ { code: 200, message: "Here are the jobs you requested" },
42
+ ],
43
+ is_array: true
35
44
  get "/" do
36
45
  begin
37
46
  # Get jobs to display
@@ -43,7 +52,7 @@ module RestFtpDaemon
43
52
 
44
53
  else
45
54
  status 200
46
- present jobs, with: RestFtpDaemon::API::Entities::JobPresenter
55
+ present jobs, with: RestFtpDaemon::API::Entities::Job
47
56
 
48
57
  end
49
58
  end
@@ -52,10 +61,31 @@ module RestFtpDaemon
52
61
  params do
53
62
  requires :source, type: String, desc: "Source file pattern"
54
63
  requires :target, type: String, desc: "Target remote path"
64
+
55
65
  optional :label, type: String, desc: "Descriptive label for this job"
56
66
  optional :notify, type: String, desc: "URL to get POST'ed notifications back"
57
67
  optional :priority, type: Integer, desc: "Priority level of the job (lower is stronger)"
58
68
  optional :pool, type: String, desc: "Pool of worker to be used"
69
+ optional :type,
70
+ type: String,
71
+ desc: "Type of job",
72
+ default: JOB_TYPE_TRANSFER,
73
+ values: {value: JOB_TYPES, message: "should be one of: #{JOB_TYPES.join', '}"},
74
+ allow_blank: { value: false, message: 'cannot be empty' }
75
+
76
+ optional :video_vc,
77
+ type: String,
78
+ desc: "video: video codec",
79
+ default: ""
80
+ optional :video_ac,
81
+ type: String,
82
+ desc: "video: audio codec",
83
+ default: ""
84
+ optional :video_custom,
85
+ type: Hash,
86
+ desc: "video: custom options passed to FFMPEG encoder",
87
+ default: {}
88
+
59
89
  optional :overwrite,
60
90
  type: Boolean,
61
91
  desc: "Overwrites files at target server",
@@ -68,16 +98,15 @@ module RestFtpDaemon
68
98
  type: Boolean,
69
99
  desc: "Upload to a temp file before renaming it to the target filename",
70
100
  default: Conf.at(:transfer, :tempfile)
101
+ # optional :options, desc: "", type: API::Entities::Options
102
+
71
103
  end
104
+
72
105
  post "/" do
73
106
  # log_debug params.to_json
74
107
  begin
75
- # Create a new job
76
- job_id = RestFtpDaemon::JobQueue.instance.generate_id
77
- job = Job.new(job_id, params)
78
-
79
- # And push it to the queue
80
- RestFtpDaemon::JobQueue.instance.push job
108
+ # Add up the new job on the queue
109
+ job = RestFtpDaemon::JobQueue.instance.create_job(params)
81
110
 
82
111
  # Increment a counter
83
112
  RestFtpDaemon::Counters.instance.increment :jobs, :received
@@ -86,13 +115,17 @@ module RestFtpDaemon
86
115
  log_error "JSON::ParserError: #{exception.message}"
87
116
  error!({error: :api_parse_error, message: exception.message}, 422)
88
117
 
118
+ rescue QueueCantCreateJob => exception
119
+ log_error "QueueCantCreateJob: #{exception.message}"
120
+ error!({error: :api_cant_create_job, message: exception.message}, 422)
121
+
89
122
  rescue RestFtpDaemonException => exception
90
- log_error "RestFtpDaemonException: #{exception.message}"
91
- error!({error: :api_exception, message: exception.message}, 500)
123
+ log_error "#{exception.class.to_s} #{exception.message}"
124
+ error!({error: exception_to_error(exception), message: exception.message}, 500)
92
125
 
93
126
  else
94
127
  status 201
95
- present job, with: RestFtpDaemon::API::Entities::JobPresenter, hide_params: true
128
+ present job, with: RestFtpDaemon::API::Entities::Job, hide_params: true
96
129
 
97
130
  end
98
131
  end
@@ -0,0 +1,80 @@
1
+ require "grape"
2
+ require 'grape-swagger'
3
+
4
+ module RestFtpDaemon
5
+ module API
6
+ class Root < Grape::API
7
+ include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
8
+
9
+ ### LOGGING & HELPERS
10
+ helpers RestFtpDaemon::CommonHelpers
11
+ helpers RestFtpDaemon::ApiHelpers
12
+ helpers BmcDaemonLib::LoggerHelper
13
+
14
+ helpers do
15
+ def log_prefix
16
+ ['API', nil, nil]
17
+ end
18
+
19
+ def logger
20
+ Root.logger
21
+ end
22
+ end
23
+
24
+ before do
25
+ log_request
26
+ end
27
+
28
+ ### CLASS CONFIG
29
+ logger BmcDaemonLib::LoggerPool.instance.get :api
30
+ do_not_route_head!
31
+ do_not_route_options!
32
+ # version 'v1'
33
+ format :json
34
+ content_type :json, 'application/json; charset=utf-8'
35
+
36
+
37
+ desc 'API Root'
38
+
39
+ ### MOUNTPOINTS
40
+ # mount RestFtpDaemon::API::Status => MOUNT_STATUS
41
+ # mount RestFtpDaemon::API::Jobs => MOUNT_JOBS
42
+ # mount RestFtpDaemon::API::Dashbaord => MOUNT_BOARD
43
+ # mount RestFtpDaemon::API::Config => MOUNT_CONFIG
44
+ # mount RestFtpDaemon::API::Debug => MOUNT_DEBUG
45
+
46
+
47
+ ### API Documentation
48
+ add_swagger_documentation hide_documentation_path: true,
49
+ api_version: BmcDaemonLib::Conf.app_ver,
50
+ doc_version: BmcDaemonLib::Conf.app_ver,
51
+ mount_path: MOUNT_SWAGGER_JSON,
52
+ info: {
53
+ title: BmcDaemonLib::Conf.app_name,
54
+ version: BmcDaemonLib::Conf.app_ver,
55
+ description: "API description for #{BmcDaemonLib::Conf.app_name} #{BmcDaemonLib::Conf.app_ver}",
56
+ }
57
+ # models: [
58
+ # RestFtpDaemon::API::Entities::Job,
59
+ # ]
60
+
61
+ ### GLOBAL EXCEPTION HANDLING
62
+ # rescue_from :all do |e|
63
+ # raise e
64
+ # error_response(message: "Internal server error: #{e}", status: 500)
65
+ # end
66
+
67
+
68
+ ### INITIALIZATION
69
+ def initialize
70
+ super
71
+ end
72
+
73
+ ### ENDPOINTS
74
+ get "/" do
75
+ redirect dashboard_url()
76
+ end
77
+
78
+ end
79
+ end
80
+ end