Class: LogStash::Inputs::CloudStorage::BlobAdapter

Inherits:
Object
  • Object
show all
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

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

#attributesObject



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.(),
    '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

#generationObject



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

#metadataObject



41
42
43
# File 'lib/logstash/inputs/cloud_storage/blob_adapter.rb', line 41

def 
  @blob.()
end

#nameObject



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 set_metadata!(key, value)
   = { key => value }
  @blob.toBuilder().().build().update()
end

#uriObject



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

Yields:

  • (temp_file)


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