gooddata_s3 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/lib/gooddata_s3/client.rb +121 -13
- data/lib/gooddata_s3/models/buckets.rb +17 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 086dbc09b0f9d03a30918f41b7ad26747d05c9f3
|
4
|
+
data.tar.gz: 561f7abcacc1d31e3b0816b06946ac9913743a93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2505025053c35f23d24c7faa2ec3fd6b2a71d4509dd71007364aa54d1b69266f80955db6ac46210548dfb4645dd201cbd114f334d2a83e955fe905cfcc26879a
|
7
|
+
data.tar.gz: 743811f9ab12f52fb2721cf1113c43994189da88ce590459c0f513390746fe13db391ddf8683efd1d21cb967bb0fdbefffe047678777378f6d62f8840da3dac3
|
data/lib/gooddata_s3/client.rb
CHANGED
@@ -1,17 +1,26 @@
|
|
1
1
|
require 'json'
|
2
|
-
require 'pry'
|
3
2
|
require 'aws-sdk'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'securerandom'
|
5
|
+
|
6
|
+
require_relative 'models/buckets'
|
4
7
|
|
5
8
|
class GoodDataS3::Client
|
6
9
|
|
7
10
|
attr_accessor :bucket_name
|
8
11
|
attr_accessor :bucket
|
12
|
+
attr_accessor :directories
|
13
|
+
|
14
|
+
alias :directory :directories
|
9
15
|
|
10
16
|
def initialize config = {}
|
11
17
|
|
12
18
|
public_key = config[:public_key]
|
13
19
|
private_key = config[:private_key] || config[:secret_key]
|
14
|
-
|
20
|
+
proposed_bucket = S3Bucket.new(config[:bucket] || 'gooddata_connector')
|
21
|
+
|
22
|
+
@bucket_name = proposed_bucket.name
|
23
|
+
@directories = proposed_bucket.directories
|
15
24
|
|
16
25
|
AWS.config(:access_key_id => public_key, :secret_access_key => private_key)
|
17
26
|
|
@@ -25,6 +34,11 @@ class GoodDataS3::Client
|
|
25
34
|
bucket = bucket_exists
|
26
35
|
end
|
27
36
|
|
37
|
+
puts "#{Time.now} => Connected to S3 Bucket: \"#{@bucket_name}\""
|
38
|
+
unless @directories.empty?
|
39
|
+
puts "#{Time.now} => Assigned default directory location: \"#{@directories.join('/')}\""
|
40
|
+
end
|
41
|
+
|
28
42
|
raise 'ERROR! :public_key, :private_key must be passed for configuration.' unless public_key && private_key
|
29
43
|
|
30
44
|
end
|
@@ -39,22 +53,85 @@ class GoodDataS3::Client
|
|
39
53
|
end
|
40
54
|
end
|
41
55
|
|
42
|
-
def upload
|
43
|
-
|
56
|
+
def upload file_path, config = {}
|
57
|
+
|
58
|
+
if File.exists? file_path
|
59
|
+
|
60
|
+
if @directories.empty?
|
61
|
+
directory = config[:directory] || ''
|
62
|
+
else
|
63
|
+
puts "#{Time.now} => Using default directory \"#{@directories.join('/')}\""
|
64
|
+
directory = @directories.join('/')
|
65
|
+
end
|
66
|
+
|
67
|
+
puts local_file = file_path.split('/')[-1]
|
68
|
+
|
69
|
+
else
|
70
|
+
|
71
|
+
statement = file_path.split('/')
|
72
|
+
local_file = statement.pop
|
73
|
+
|
74
|
+
if @directories.empty?
|
75
|
+
directory = statement.join('/')
|
76
|
+
else
|
77
|
+
puts "#{Time.now} => Using default directory \"#{@directories.join('/')}\""
|
78
|
+
default_directory = @directories.join('/')
|
79
|
+
directory = default_directory+"/"+statement.join('/')
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
raise 'Could not find local file...' unless File.exists? local_file
|
85
|
+
|
86
|
+
key = directory+"/"+local_file
|
87
|
+
|
88
|
+
puts "#{Time.now} => Uploading local file \"#{local_file}\" to S3 Bucket \"#{@bucket_name}\" (\"#{key}\")"
|
89
|
+
resp = @s3.put_object(
|
90
|
+
data: IO.read(local_file),
|
91
|
+
bucket_name: @bucket_name,
|
92
|
+
key: key
|
93
|
+
)
|
94
|
+
end
|
95
|
+
|
96
|
+
def create_directory name
|
44
97
|
resp = @s3.put_object(
|
45
|
-
data:
|
98
|
+
data:'',
|
46
99
|
bucket_name: @bucket_name,
|
47
|
-
key:
|
100
|
+
key: name
|
48
101
|
)
|
49
102
|
end
|
50
103
|
|
51
|
-
def download
|
104
|
+
def download file_path, config ={}
|
105
|
+
|
52
106
|
begin
|
53
|
-
|
54
|
-
|
107
|
+
|
108
|
+
if @directories.any?
|
109
|
+
puts "#{Time.now} => Using default directory \"#{@directories.join('/')}\""
|
110
|
+
|
111
|
+
statement = file_path.split('/')
|
112
|
+
local_file = statement.pop
|
113
|
+
directory = @directories.join('/')
|
114
|
+
key = directory+"/"+statement.join('/')+"/"+local_file
|
115
|
+
|
116
|
+
elsif @directories.empty?
|
117
|
+
|
118
|
+
directory = config[:directory] || ''
|
119
|
+
key = directory+file_path
|
120
|
+
|
121
|
+
else
|
122
|
+
|
123
|
+
key = file_path
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
puts "#{Time.now} => Downloading from S3 Bucket (#{@bucket_name}): \"#{key}\""
|
128
|
+
|
129
|
+
resp = @s3.get_object(bucket_name: @bucket_name, key:key)
|
55
130
|
resp[:data]
|
56
|
-
|
57
|
-
|
131
|
+
|
132
|
+
rescue Exception => exp
|
133
|
+
puts exp
|
134
|
+
|
58
135
|
end
|
59
136
|
end
|
60
137
|
|
@@ -134,9 +211,40 @@ class GoodDataS3::Client
|
|
134
211
|
|
135
212
|
alias :include? :exists?
|
136
213
|
|
137
|
-
def delete
|
138
|
-
|
214
|
+
def delete file_path
|
215
|
+
|
216
|
+
begin
|
217
|
+
|
218
|
+
if @directories.any?
|
219
|
+
puts "#{Time.now} => Using default directory \"#{@directories.join('/')}\""
|
220
|
+
|
221
|
+
statement = file_path.split('/')
|
222
|
+
local_file = statement.pop
|
223
|
+
directory = @directories.join('/')
|
224
|
+
key = directory+"/"+statement.join('/')+"/"+local_file
|
225
|
+
|
226
|
+
elsif @directories.empty?
|
227
|
+
|
228
|
+
directory = config[:directory] || ''
|
229
|
+
key = directory+file_path
|
230
|
+
|
231
|
+
else
|
232
|
+
|
233
|
+
key = file_path
|
234
|
+
|
235
|
+
end
|
236
|
+
|
237
|
+
puts "#{Time.now} => Deleting from S3 Bucket (#{@bucket_name}): \"#{key}\""
|
238
|
+
@s3.delete_object(bucket_name: @bucket_name, key: key)
|
239
|
+
|
240
|
+
rescue Exception => exp
|
241
|
+
puts exp
|
242
|
+
|
243
|
+
end
|
244
|
+
|
245
|
+
|
139
246
|
end
|
140
247
|
|
141
248
|
|
142
249
|
end
|
250
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class S3Bucket
|
2
|
+
attr_accessor :name
|
3
|
+
attr_accessor :directories
|
4
|
+
|
5
|
+
def initialize object_string
|
6
|
+
|
7
|
+
if object_string.include? '/'
|
8
|
+
statement = object_string.split('/')
|
9
|
+
@name = statement.shift
|
10
|
+
@directories = statement
|
11
|
+
else
|
12
|
+
@name = object_string
|
13
|
+
@directories = []
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gooddata_s3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick McConlogue
|
@@ -88,6 +88,7 @@ extra_rdoc_files: []
|
|
88
88
|
files:
|
89
89
|
- lib/gooddata_s3.rb
|
90
90
|
- lib/gooddata_s3/client.rb
|
91
|
+
- lib/gooddata_s3/models/buckets.rb
|
91
92
|
homepage: https://github.com/thnkr/connectors/tree/master/s3
|
92
93
|
licenses:
|
93
94
|
- MIT
|