rest-ftp-daemon 0.423.3 → 0.424.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/.codeclimate.yml +30 -0
- data/Gemfile.lock +9 -8
- data/README.md +1 -5
- data/bin/rest-ftp-daemon +11 -5
- data/defaults.yml +16 -10
- data/lib/rest-ftp-daemon.rb +14 -10
- data/lib/rest-ftp-daemon/api/jobs.rb +42 -18
- data/lib/rest-ftp-daemon/api/root.rb +5 -1
- data/lib/rest-ftp-daemon/constants.rb +0 -1
- data/lib/rest-ftp-daemon/{api/entities → entities}/job.rb +0 -0
- data/lib/rest-ftp-daemon/{api/entities → entities}/location.rb +0 -0
- data/lib/rest-ftp-daemon/{api/entities → entities}/options.rb +0 -0
- data/lib/rest-ftp-daemon/exceptions.rb +1 -0
- data/lib/rest-ftp-daemon/helpers/views.rb +7 -2
- data/lib/rest-ftp-daemon/initialize.rb +3 -0
- data/lib/rest-ftp-daemon/job.rb +3 -0
- data/lib/rest-ftp-daemon/jobs/transfer.rb +4 -4
- data/lib/rest-ftp-daemon/location.rb +5 -0
- data/lib/rest-ftp-daemon/remote/base.rb +76 -0
- data/lib/rest-ftp-daemon/remote/ftp.rb +144 -0
- data/lib/rest-ftp-daemon/remote/s3.rb +78 -0
- data/lib/rest-ftp-daemon/remote/sftp.rb +147 -0
- data/lib/rest-ftp-daemon/static/images/feature_reload.png +0 -0
- data/lib/rest-ftp-daemon/static/images/feature_rollbar.png +0 -0
- data/lib/rest-ftp-daemon/static/swagger/css/print.css +2 -2
- data/lib/rest-ftp-daemon/static/swagger/css/screen.css +2 -2
- data/lib/rest-ftp-daemon/views/dashboard_footer.haml +3 -2
- data/lib/rest-ftp-daemon/views/dashboard_jobs.haml +3 -3
- data/lib/rest-ftp-daemon/views/dashboard_table.haml +5 -4
- data/lib/rest-ftp-daemon/workers/reporter.rb +2 -2
- data/rest-ftp-daemon.gemspec +4 -7
- metadata +28 -25
- data/lib/rest-ftp-daemon/remote.rb +0 -74
- data/lib/rest-ftp-daemon/remote_ftp.rb +0 -142
- data/lib/rest-ftp-daemon/remote_s3.rb +0 -76
- data/lib/rest-ftp-daemon/remote_sftp.rb +0 -145
@@ -1,76 +0,0 @@
|
|
1
|
-
require 'aws-sdk-resources'
|
2
|
-
|
3
|
-
# Handle sFTP transfers for Remote class
|
4
|
-
module RestFtpDaemon
|
5
|
-
class RemoteS3 < Remote
|
6
|
-
|
7
|
-
MULTIPART_THRESHOLD_MB = 4
|
8
|
-
|
9
|
-
# Class options
|
10
|
-
attr_reader :client
|
11
|
-
attr_reader :target
|
12
|
-
|
13
|
-
def prepare
|
14
|
-
@multipart_threshold = MULTIPART_THRESHOLD_MB.to_i * 1024 * 1024
|
15
|
-
log_debug "RemoteS3.prepare target[#{@target.inspect}] #{@multipart_threshold}"
|
16
|
-
end
|
17
|
-
|
18
|
-
def connect
|
19
|
-
super
|
20
|
-
|
21
|
-
# Connect init
|
22
|
-
log_debug "RemoteS3.connect region[#{target.aws_region}] id[#{target.aws_id}]"
|
23
|
-
|
24
|
-
# Connect remote server
|
25
|
-
@client = Aws::S3::Resource.new(
|
26
|
-
region: @target.aws_region,
|
27
|
-
credentials: Aws::Credentials.new(@target.aws_id, @target.aws_secret),
|
28
|
-
http_wire_trace: @debug
|
29
|
-
)
|
30
|
-
#s3 = Aws::S3::Client.new(http_wire_trace: true)
|
31
|
-
end
|
32
|
-
|
33
|
-
def upload source, target, use_temp_name = false, &callback
|
34
|
-
# Push init
|
35
|
-
raise RestFtpDaemon::AssertionFailed, "upload/client" if @client.nil?
|
36
|
-
log_debug "RemoteS3.upload bucket[#{target.aws_bucket}] name[#{target.name}]"
|
37
|
-
|
38
|
-
# Update progress before
|
39
|
-
#yield 0, target.name
|
40
|
-
# Point to the right bucket and object
|
41
|
-
bucket = @client.bucket(target.aws_bucket)
|
42
|
-
object = bucket.object(target.name)
|
43
|
-
|
44
|
-
# Do the transfer
|
45
|
-
object.upload_file(source.path, {
|
46
|
-
multipart_threshold: @multipart_threshold
|
47
|
-
})
|
48
|
-
|
49
|
-
# Wait for transfer to complete
|
50
|
-
object.wait_until_exists do |waiter|
|
51
|
-
# waiter.delay = 1
|
52
|
-
# # log_debug "- progress[#{progress}] total[#{total}]"
|
53
|
-
# waiter.before_wait do |attempts, response|
|
54
|
-
# puts "#{attempts} made"
|
55
|
-
# puts response.error.inspect
|
56
|
-
# puts response.data.inspect
|
57
|
-
# end
|
58
|
-
# log_debug "- progress[] #{waiter.inspect}"
|
59
|
-
end
|
60
|
-
|
61
|
-
# Update progress after
|
62
|
-
#yield target.size, target.name
|
63
|
-
|
64
|
-
# Dump information about this file
|
65
|
-
log_debug "RemoteS3.upload url[#{object.public_url}]"
|
66
|
-
log_debug "RemoteS3.upload etag[#{object.etag}]"
|
67
|
-
set_info :target_aws_public_url, object.public_url
|
68
|
-
set_info :target_aws_etag, object.etag
|
69
|
-
end
|
70
|
-
|
71
|
-
def connected?
|
72
|
-
!@client.nil?
|
73
|
-
end
|
74
|
-
|
75
|
-
end
|
76
|
-
end
|
@@ -1,145 +0,0 @@
|
|
1
|
-
require "net/sftp"
|
2
|
-
|
3
|
-
# Handle sFTP transfers for Remote class
|
4
|
-
module RestFtpDaemon
|
5
|
-
class RemoteSFTP < Remote
|
6
|
-
|
7
|
-
# Class options
|
8
|
-
attr_reader :sftp
|
9
|
-
|
10
|
-
def prepare
|
11
|
-
end
|
12
|
-
|
13
|
-
def connect
|
14
|
-
super
|
15
|
-
|
16
|
-
# Connect init
|
17
|
-
log_debug "RemoteSFTP.connect [#{@target.user}]@[#{@target.host}]:[#{@target.port}]"
|
18
|
-
|
19
|
-
# Debug level
|
20
|
-
verbosity = @debug ? Logger::DEBUG : false
|
21
|
-
|
22
|
-
# Connect remote server
|
23
|
-
@sftp = Net::SFTP.start(@target.host.to_s, @target.user.to_s,
|
24
|
-
password: @target.password.to_s,
|
25
|
-
verbose: verbosity,
|
26
|
-
port: @target.port,
|
27
|
-
non_interactive: true,
|
28
|
-
timeout: DEFAULT_SFTP_TIMEOUT
|
29
|
-
)
|
30
|
-
end
|
31
|
-
|
32
|
-
def present? target
|
33
|
-
log_debug "RemoteSFTP.present? [#{target.name}]"
|
34
|
-
stat = @sftp.stat! target.path
|
35
|
-
|
36
|
-
rescue Net::SFTP::StatusException
|
37
|
-
return false
|
38
|
-
else
|
39
|
-
return stat.size
|
40
|
-
end
|
41
|
-
|
42
|
-
def remove! target
|
43
|
-
log_debug "RemoteSFTP.remove! [#{target.name}]"
|
44
|
-
@sftp.remove target.path
|
45
|
-
|
46
|
-
rescue Net::SFTP::StatusException
|
47
|
-
log_debug "#{LOG_INDENT}[#{target.name}] file not found"
|
48
|
-
else
|
49
|
-
log_debug "#{LOG_INDENT}[#{target.name}] removed"
|
50
|
-
end
|
51
|
-
|
52
|
-
def mkdir directory
|
53
|
-
log_debug "RemoteSFTP.mkdir [#{directory}]"
|
54
|
-
@sftp.mkdir! directory
|
55
|
-
|
56
|
-
rescue StandardError => ex
|
57
|
-
raise TargetPermissionError, ex.message
|
58
|
-
end
|
59
|
-
|
60
|
-
def chdir_or_create directory, mkdir = false
|
61
|
-
# Init, extract my parent name and my own name
|
62
|
-
log_debug "RemoteSFTP.chdir_or_create mkdir[#{mkdir}] dir[#{directory}]"
|
63
|
-
parent, _current = extract_parent(directory)
|
64
|
-
|
65
|
-
# Access this directory
|
66
|
-
begin
|
67
|
-
#log_debug "chdir [/#{directory}]"
|
68
|
-
@sftp.opendir! directory
|
69
|
-
|
70
|
-
rescue Net::SFTP::StatusException => _e
|
71
|
-
# If not allowed to create path, that's over, we're stuck
|
72
|
-
return false unless mkdir
|
73
|
-
|
74
|
-
# Recurse upward
|
75
|
-
chdir_or_create parent, mkdir
|
76
|
-
|
77
|
-
# Now I was able to chdir into my parent, create the current directory
|
78
|
-
mkdir directory
|
79
|
-
|
80
|
-
# Finally retry the chdir
|
81
|
-
retry
|
82
|
-
else
|
83
|
-
return true
|
84
|
-
end
|
85
|
-
|
86
|
-
# We should never get here
|
87
|
-
raise JobTargetShouldBeDirectory
|
88
|
-
end
|
89
|
-
|
90
|
-
def upload source, target, use_temp_name = false, &callback
|
91
|
-
# Push init
|
92
|
-
raise RestFtpDaemon::AssertionFailed, "upload/sftp" if @sftp.nil?
|
93
|
-
|
94
|
-
# Temp file if needed
|
95
|
-
dest = target.clone
|
96
|
-
if use_temp_name
|
97
|
-
dest.generate_temp_name!
|
98
|
-
end
|
99
|
-
|
100
|
-
# Do the transfer
|
101
|
-
log_debug "RemoteSFTP.upload temp[#{use_temp_name}] name[#{dest.name}]"
|
102
|
-
@sftp.upload! source.path, dest.path do |event, _uploader, *args|
|
103
|
-
case event
|
104
|
-
when :open then
|
105
|
-
# args[0] : file metadata
|
106
|
-
when :put then
|
107
|
-
# args[0] : file metadata
|
108
|
-
# args[1] : byte offset in remote file
|
109
|
-
# args[2] : data being written (as string)
|
110
|
-
# puts "writing #{args[2].length} bytes to #{args[0].remote} starting at #{args[1]}"
|
111
|
-
|
112
|
-
# Update job status after this block transfer
|
113
|
-
yield args[2].length, dest.name
|
114
|
-
|
115
|
-
when :close then
|
116
|
-
# args[0] : file metadata
|
117
|
-
when :mkdir
|
118
|
-
# args[0] : remote path name
|
119
|
-
when :finish
|
120
|
-
end
|
121
|
-
|
122
|
-
end
|
123
|
-
|
124
|
-
# Move the file back to its original name
|
125
|
-
if use_temp_name
|
126
|
-
flags = 0x00000001
|
127
|
-
log_debug "RemoteSFTP.upload rename [#{dest.name}] > [#{target.name}]"
|
128
|
-
@sftp.rename! dest.path, target.path, flags
|
129
|
-
end
|
130
|
-
|
131
|
-
# progress:
|
132
|
-
# Net::SFTP::StatusException
|
133
|
-
end
|
134
|
-
|
135
|
-
def close
|
136
|
-
# Close init
|
137
|
-
super
|
138
|
-
end
|
139
|
-
|
140
|
-
def connected?
|
141
|
-
@sftp && !@sftp.closed?
|
142
|
-
end
|
143
|
-
|
144
|
-
end
|
145
|
-
end
|