Class: ArtifactTools::Client
- Inherits:
-
Object
- Object
- ArtifactTools::Client
- Includes:
- Hasher
- Defined in:
- lib/artifact_tools/client.rb
Overview
Use an object of this class to put/fetch files from storage specified with ConfigFile
Instance Method Summary collapse
-
#fetch(file: nil, dest: nil, match: nil, verify: false, force: false) ⇒ Object
Fetch a file from store.
-
#initialize(config:, user: nil) ⇒ Client
constructor
A new instance of Client.
-
#put(file:) ⇒ Object
Put a file to storage.
Methods included from Hasher
Constructor Details
#initialize(config:, user: nil) ⇒ Client
Returns a new instance of Client.
23 24 25 26 27 |
# File 'lib/artifact_tools/client.rb', line 23 def initialize(config:, user: nil) @config = config user ||= ENV['ARTIFACT_STORAGE_USER'] || @config['user'] @ssh = Net::SSH.start(@config['server'], user, non_interactive: true) end |
Instance Method Details
#fetch(file: nil, dest: nil, match: nil, verify: false, force: false) ⇒ Object
Fetch a file from store
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/artifact_tools/client.rb', line 37 def fetch(file: nil, dest: nil, match: nil, verify: false, force: false) files = @config['files'].keys files = [file] if file files.each do |entry| next if match && !entry.match?(match) entry_hash = @config['files'][entry]['hash'] remote = compose_remote(entry, entry_hash) local = compose_local(dest, entry) next if !force && local_file_matches(local, entry_hash) @ssh.scp.download!(remote, local) verify(entry_hash, local) if verify end end |
#put(file:) ⇒ Object
Put a file to storage
56 57 58 59 60 61 |
# File 'lib/artifact_tools/client.rb', line 56 def put(file:) hash = file_hash(file) remote = compose_remote(file, hash) ensure_remote_path_exists(remote) @ssh.scp.upload!(file, remote) end |