Class: LogStash::Inputs::CloudStorage::BlobAdapter
- Inherits:
-
Object
- Object
- LogStash::Inputs::CloudStorage::BlobAdapter
- Defined in:
- lib/logstash/inputs/cloud_storage/blob_adapter.rb
Overview
BlobAdapter exposes parts of ‘com.google.cloud.storage.Blob` for use in the plugin for easier mocking and future-proofing.
Instance Method Summary collapse
- #attributes ⇒ Object
- #delete! ⇒ Object
- #download_to(path) ⇒ Object
- #generation ⇒ Object
-
#initialize(blob) ⇒ BlobAdapter
constructor
A new instance of BlobAdapter.
- #line_attributes(line_number) ⇒ Object
- #metadata ⇒ Object
- #name ⇒ Object
- #set_metadata!(key, value) ⇒ Object
- #uri ⇒ Object
- #with_downloaded(temp_directory) {|temp_file| ... } ⇒ Object
Constructor Details
#initialize(blob) ⇒ BlobAdapter
Returns a new instance of BlobAdapter.
12 13 14 |
# File 'lib/logstash/inputs/cloud_storage/blob_adapter.rb', line 12 def initialize(blob) @blob = blob end |
Instance Method Details
#attributes ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/logstash/inputs/cloud_storage/blob_adapter.rb', line 20 def attributes { 'bucket' => @blob.getBucket(), 'metadata' => @blob.getMetadata(), 'name' => @blob.getName(), 'md5' => @blob.getMd5(), 'crc32c' => @blob.getCrc32c(), 'generation' => @blob.getGeneration() } end |
#delete! ⇒ Object
32 33 34 |
# File 'lib/logstash/inputs/cloud_storage/blob_adapter.rb', line 32 def delete! @blob.delete(BlobSourceOption.generationMatch()) end |
#download_to(path) ⇒ Object
63 64 65 66 |
# File 'lib/logstash/inputs/cloud_storage/blob_adapter.rb', line 63 def download_to(path) temp_path = Paths.get(path) @blob.downloadTo(temp_path) end |
#generation ⇒ Object
45 46 47 |
# File 'lib/logstash/inputs/cloud_storage/blob_adapter.rb', line 45 def generation @blob.getGeneration() end |
#line_attributes(line_number) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/logstash/inputs/cloud_storage/blob_adapter.rb', line 49 def line_attributes(line_number) attrs = attributes attrs['line'] = line_number attrs['line_id'] = "#{uri}:#{line_number}@#{generation}" attrs end |
#metadata ⇒ Object
41 42 43 |
# File 'lib/logstash/inputs/cloud_storage/blob_adapter.rb', line 41 def @blob.getMetadata() end |
#name ⇒ Object
16 17 18 |
# File 'lib/logstash/inputs/cloud_storage/blob_adapter.rb', line 16 def name @blob.getName() end |
#set_metadata!(key, value) ⇒ Object
36 37 38 39 |
# File 'lib/logstash/inputs/cloud_storage/blob_adapter.rb', line 36 def (key, value) = { key => value } @blob.toBuilder().setMetadata().build().update() end |
#uri ⇒ Object
58 59 60 |
# File 'lib/logstash/inputs/cloud_storage/blob_adapter.rb', line 58 def uri "gs://#{@blob.getBucket()}/#{name}" end |
#with_downloaded(temp_directory) {|temp_file| ... } ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/logstash/inputs/cloud_storage/blob_adapter.rb', line 68 def with_downloaded(temp_directory) temp_file = ::File.join(temp_directory, SecureRandom.uuid) download_to(temp_file) yield temp_file FileUtils.remove_entry_secure(temp_file, true) end |