spectre-ftp 1.1.1 → 2.0.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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/spectre/ftp.rb +48 -49
  3. metadata +7 -24
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7a902a8c177730c407b7828f6b60d6bf592402d2b7b5b6103b2c13fdb1ca77ce
4
- data.tar.gz: a7612890b94aafb60c3723e0b9515ea0f8859d62578f0ce1cee30767517d41fc
3
+ metadata.gz: 78abb94631853f8555a1c8140d6ff635d9c52da476df9fcca459b04bc4e56e7a
4
+ data.tar.gz: 640cfafddb1a3c1893c8ce28d3ca85aa884e4ac0b82e368fcc015a9ff1c54eda
5
5
  SHA512:
6
- metadata.gz: 2680bc0403cf0eb0e57a039bd42103a72de3b1d8ea303f1a39a00100ff978932c7c6c317fe99333a2c858f7325b90a7b0bf14b56923aac8accd8c007aa91be08
7
- data.tar.gz: 739171c88d9513517b143f4d106b2d352457d914a373653093494d93ac89e8aa817badf8fc3dbdaa8b37ab5bde3d8be2d8559285409cef5949c24374da1c6f05
6
+ metadata.gz: e0d15287e01e895a164404b1259a44e8ca0e06ef08c7da4d0a8d7992d6294df72d748177bc133ee72c904d0be6e8f3f60554c38e44d0bd65d24d22952d555957
7
+ data.tar.gz: b39d5b16b6f081cb24eb3d49021a1075400b8379c71e25667cba32252f7dae078689281bca2739016cf6f5f057939088f41a2b47bede388cd6b2407c297593fa
data/lib/spectre/ftp.rb CHANGED
@@ -3,12 +3,11 @@ require 'net/sftp'
3
3
  require 'logger'
4
4
  require 'json'
5
5
 
6
-
7
6
  module Spectre
8
7
  module FTP
9
- @@cfg = {}
8
+ class FTPConnection
9
+ include Spectre::Delegate if defined? Spectre::Delegate
10
10
 
11
- class FTPConnection < DslClass
12
11
  def initialize host, username, password, opts, logger
13
12
  @__logger = logger
14
13
  @__session = nil
@@ -28,7 +27,7 @@ module Spectre
28
27
  end
29
28
 
30
29
  def connect!
31
- return unless @__session == nil or @__session.closed?
30
+ return unless @__session.nil? or @__session.closed?
32
31
 
33
32
  @__logger.info "Connecting to '#{@__host}' with user '#{@__username}'"
34
33
  @__session = Net::FTP.new(@__host, @__opts)
@@ -36,29 +35,34 @@ module Spectre
36
35
  end
37
36
 
38
37
  def close
39
- return unless @__session and not @__session.closed?
38
+ return unless @__session and !@__session.closed?
40
39
 
41
40
  @__session.close
42
41
  end
43
42
 
44
43
  def can_connect?
45
- begin
46
- connect!
47
- return true
48
- rescue
49
- return false
50
- end
44
+ connect!
45
+ true
46
+ rescue StandardError
47
+ false
51
48
  end
52
49
 
53
50
  def download remotefile, to: File.basename(remotefile)
54
51
  connect!
55
- @__logger.info("Downloading '#{@__username}@#{@__host}:#{File.join @__session.pwd, remotefile}' to '#{File.expand_path to}'")
52
+ @__logger.info(
53
+ "Downloading \
54
+ '#{@__username}@#{@__host}:#{File.join @__session.pwd, remotefile}' \
55
+ to '#{File.expand_path to}'"
56
+ )
56
57
  @__session.getbinaryfile(remotefile, to)
57
58
  end
58
59
 
59
60
  def upload localfile, to: File.basename(localfile)
60
61
  connect!
61
- @__logger.info("Uploading '#{File.expand_path localfile}' to '#{@__username}@#{@__host}:#{File.join @__session.pwd, to}'")
62
+ @__logger.info(
63
+ "Uploading '#{File.expand_path localfile}' \
64
+ to '#{@__username}@#{@__host}:#{File.join @__session.pwd, to}'"
65
+ )
62
66
  @__session.putbinaryfile(localfile, to)
63
67
  end
64
68
 
@@ -70,10 +74,10 @@ module Spectre
70
74
  end
71
75
  end
72
76
 
73
- class SFTPConnection < DslClass
74
- def initialize host, username, opts, logger
75
- opts[:non_interactive] = true
77
+ class SFTPConnection
78
+ include Spectre::Delegate if defined? Spectre::Delegate
76
79
 
80
+ def initialize host, username, opts, logger
77
81
  @__logger = logger
78
82
  @__session = nil
79
83
  @__host = host
@@ -100,26 +104,24 @@ module Spectre
100
104
  end
101
105
 
102
106
  def connect!
103
- return unless @__session == nil or @__session.closed?
107
+ return unless @__session.nil? or @__session.closed?
104
108
 
105
- @__logger.info "Connecting to '#{@__host}' with user '#{@__username}'"
109
+ @__logger.info("Connecting to '#{@__host}' with user '#{@__username}'")
106
110
  @__session = Net::SFTP.start(@__host, @__username, @__opts)
107
111
  @__session.connect!
108
112
  end
109
113
 
110
114
  def close
111
- return unless @__session and not @__session.closed?
115
+ return if @__session.nil? or @__session.closed?
112
116
 
113
- # @__session.close!
117
+ @__session.close_channel
114
118
  end
115
119
 
116
120
  def can_connect?
117
- begin
118
- connect!
119
- return true
120
- rescue
121
- return false
122
- end
121
+ connect!
122
+ true
123
+ rescue StandardError
124
+ false
123
125
  end
124
126
 
125
127
  def download remotefile, to: File.basename(remotefile)
@@ -150,14 +152,20 @@ module Spectre
150
152
  raise e
151
153
  end
152
154
 
153
- return true
155
+ true
154
156
  end
155
157
  end
156
158
 
159
+ class Client
160
+ include Spectre::Delegate if defined? Spectre::Delegate
157
161
 
158
- class << self
159
- def ftp name, config={}, &block
160
- cfg = @@cfg[name] || {}
162
+ def initialize config, logger
163
+ @config = config['ftp'] || {}
164
+ @logger = logger
165
+ end
166
+
167
+ def ftp(name, config = {}, &)
168
+ cfg = @config[name] || {}
161
169
 
162
170
  host = config[:host] || cfg['host'] || name
163
171
  username = config[:username] || cfg['username']
@@ -167,17 +175,17 @@ module Spectre
167
175
  opts[:ssl] = config[:ssl]
168
176
  opts[:port] = config[:port] || cfg['port'] || 21
169
177
 
170
- ftp_conn = FTPConnection.new(host, username, password, opts, @@logger)
178
+ ftp_conn = FTPConnection.new(host, username, password, opts, @logger)
171
179
 
172
180
  begin
173
- ftp_conn.instance_eval &block
181
+ ftp_conn.instance_eval(&)
174
182
  ensure
175
183
  ftp_conn.close
176
184
  end
177
185
  end
178
186
 
179
- def sftp name, config={}, &block
180
- cfg = @@cfg[name] || {}
187
+ def sftp(name, config = {}, &)
188
+ cfg = @config[name] || {}
181
189
 
182
190
  host = config[:host] || cfg['host'] || name
183
191
  username = config[:username] || cfg['username']
@@ -193,27 +201,18 @@ module Spectre
193
201
  opts[:auth_methods].push 'publickey' if opts[:keys]
194
202
  opts[:auth_methods].push 'password' if opts[:password]
195
203
 
196
- sftp_con = SFTPConnection.new(host, username, opts, @@logger)
204
+ opts[:non_interactive] = true
205
+
206
+ sftp_con = SFTPConnection.new(host, username, opts, @logger)
197
207
 
198
208
  begin
199
- sftp_con.instance_eval &block
209
+ sftp_con.instance_eval(&)
200
210
  ensure
201
211
  sftp_con.close
202
212
  end
203
213
  end
204
214
  end
205
-
206
- Spectre.register do |config|
207
- @@logger = Spectre::Logging::ModuleLogger.new(config, 'spectre/ftp')
208
-
209
- if config.key? 'ftp'
210
-
211
- config['ftp'].each do |name, cfg|
212
- @@cfg[name] = cfg
213
- end
214
- end
215
- end
216
-
217
- Spectre.delegate :ftp, :sftp, to: self
218
215
  end
216
+
217
+ Engine.register(FTP::Client, :ftp, :sftp) if defined? Engine
219
218
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spectre-ftp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Neubauer
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2025-01-20 00:00:00.000000000 Z
10
+ date: 2025-03-21 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: net-ftp
@@ -38,21 +37,7 @@ dependencies:
38
37
  - - ">="
39
38
  - !ruby/object:Gem::Version
40
39
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: spectre-core
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: 1.14.0
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: 1.14.0
55
- description: Adds FTP functionality to the spectre framework
40
+ description: A simple FTP wrapper for nice readability. Is compatible with spectre-core.
56
41
  email:
57
42
  - christian.neubauer@ionos.com
58
43
  executables: []
@@ -62,12 +47,11 @@ files:
62
47
  - lib/spectre/ftp.rb
63
48
  homepage: https://github.com/ionos-spectre/spectre-ftp
64
49
  licenses:
65
- - MIT
50
+ - GPL-3.0-or-later
66
51
  metadata:
67
52
  homepage_uri: https://github.com/ionos-spectre/spectre-ftp
68
53
  source_code_uri: https://github.com/ionos-spectre/spectre-ftp
69
54
  changelog_uri: https://github.com/ionos-spectre/spectre-ftp/src/master/CHANGELOG.md
70
- post_install_message:
71
55
  rdoc_options: []
72
56
  require_paths:
73
57
  - lib
@@ -75,15 +59,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
75
59
  requirements:
76
60
  - - ">="
77
61
  - !ruby/object:Gem::Version
78
- version: 3.0.0
62
+ version: '3.4'
79
63
  required_rubygems_version: !ruby/object:Gem::Requirement
80
64
  requirements:
81
65
  - - ">="
82
66
  - !ruby/object:Gem::Version
83
67
  version: '0'
84
68
  requirements: []
85
- rubygems_version: 3.4.19
86
- signing_key:
69
+ rubygems_version: 3.6.6
87
70
  specification_version: 4
88
- summary: FTP module for spectre
71
+ summary: Standalone FTP wrapper compatible with spectre
89
72
  test_files: []