15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/patriot_gcp/ext/gcs.rb', line 15
def gcs(gcs_keyfile, project_id, bucket, command, source_file, dest_file)
ENV['GOOGLE_CLOUD_KEYFILE'] = gcs_keyfile
storage = Google::Cloud::Storage.new(
project: project_id,
retries: 3,
timeout: 3600
)
bucket = storage.bucket bucket
if command == 'create_file'
bucket.create_file(source_file, dest_file)
elsif command == 'download'
file = bucket.file source_file
if file.nil?
raise GCSException, "File not found."
end
file.download dest_file
elsif command == 'delete'
file = bucket.file source_file
if file.nil?
@logger.info "File not found."
else
file.delete
end
end
end
|