gooddata_s3 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/gooddata_s3/client.rb +142 -0
- data/lib/gooddata_s3.rb +13 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 47dc8e87e10d925ec00de09f149f1d0199394220
|
4
|
+
data.tar.gz: 5ad2f2bd5018e53e61f1c7fcefe05b5a9e147fc2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bcdec9ce0d4afe77d01e06d13bbf27691ae0f371882b8ba0475278a6b3f46d63897f89c38652546509b2a09fe72febd7d733e973f565e260697b84c7f51cab14
|
7
|
+
data.tar.gz: 0078fc39f87e1454b077118927dfba674c55c6b926a33b1a88671d4ade4fc73c99e993785cc7d3cabd583013369214e2b11a39bc23d050ed573968cf7041deaf
|
@@ -0,0 +1,142 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'pry'
|
3
|
+
require 'aws-sdk'
|
4
|
+
|
5
|
+
class GoodDataS3::Client
|
6
|
+
|
7
|
+
attr_accessor :bucket_name
|
8
|
+
attr_accessor :bucket
|
9
|
+
|
10
|
+
def initialize config = {}
|
11
|
+
|
12
|
+
public_key = config[:public_key]
|
13
|
+
private_key = config[:private_key] || config[:secret_key]
|
14
|
+
self.bucket_name = config[:bucket] || 'gooddata_connector'
|
15
|
+
|
16
|
+
AWS.config(:access_key_id => public_key, :secret_access_key => private_key)
|
17
|
+
|
18
|
+
@s3 = AWS::S3::Client.new(region: 'us-east-1')
|
19
|
+
|
20
|
+
bucket_exists = @s3.list_buckets.include? @bucket_name
|
21
|
+
|
22
|
+
if bucket_exists == false
|
23
|
+
bucket = @s3.create_bucket(:bucket_name => @bucket_name)
|
24
|
+
else
|
25
|
+
bucket = bucket_exists
|
26
|
+
end
|
27
|
+
|
28
|
+
raise 'ERROR! :public_key, :private_key must be passed for configuration.' unless public_key && private_key
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
def test
|
33
|
+
begin
|
34
|
+
self.exists? 'tmp_dumb_file'
|
35
|
+
puts "#{Time.now} => SETUP: Connect to AWS S3 Bucket:#{self.bucket_name}...success!"
|
36
|
+
true
|
37
|
+
rescue
|
38
|
+
false
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def upload file
|
43
|
+
puts "#{Time.now} => Uploading:S3_Bucket#{@bucket_name}: \"#{file}\""
|
44
|
+
resp = @s3.put_object(
|
45
|
+
data: IO.read(file),
|
46
|
+
bucket_name: @bucket_name,
|
47
|
+
key: file
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
def download file
|
52
|
+
begin
|
53
|
+
puts "#{Time.now} => Downloading:S3_Bucket#{@bucket_name}: \"#{file}\""
|
54
|
+
resp = @s3.get_object(bucket_name: @bucket_name, key:file)
|
55
|
+
resp[:data]
|
56
|
+
rescue
|
57
|
+
nil
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def get_config config = {}
|
62
|
+
|
63
|
+
file = config[:file] || 'gooddata_connector_config.json'
|
64
|
+
|
65
|
+
if self.exists? file
|
66
|
+
json = JSON.parse(self.download(file), :symbolize_names => true)
|
67
|
+
|
68
|
+
File.open(file,'w'){ |f| JSON.dump(json, f) }
|
69
|
+
|
70
|
+
self.download(file)
|
71
|
+
|
72
|
+
json
|
73
|
+
|
74
|
+
else
|
75
|
+
|
76
|
+
json = {
|
77
|
+
:id => SecureRandom.uuid,
|
78
|
+
:updated => Time.now.to_s,
|
79
|
+
:initial_load_get_multiple => false,
|
80
|
+
:initial_load_get_changes => false
|
81
|
+
}
|
82
|
+
|
83
|
+
File.open(file,'w'){ |f| JSON.dump(json, f) }
|
84
|
+
|
85
|
+
self.upload(file)
|
86
|
+
|
87
|
+
json
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
def set_config config = {}
|
94
|
+
|
95
|
+
if config[:file]
|
96
|
+
file = config.delete(:file)
|
97
|
+
else
|
98
|
+
file = 'gooddata_connector_config.json'
|
99
|
+
end
|
100
|
+
|
101
|
+
if self.exists? file
|
102
|
+
json = JSON.parse(self.download(file), :symbolize_names => true)
|
103
|
+
else
|
104
|
+
json = Hash.new
|
105
|
+
end
|
106
|
+
|
107
|
+
new_json = json.merge(config)
|
108
|
+
|
109
|
+
new_json[:updated] = Time.now.to_s
|
110
|
+
|
111
|
+
File.open(file,'w'){ |f| JSON.dump(new_json, f) }
|
112
|
+
|
113
|
+
self.upload(file)
|
114
|
+
|
115
|
+
new_json
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
def latest_config
|
120
|
+
if File.exists?('gooddata_connector_config.json')
|
121
|
+
File.delete('gooddata_connector_config.json')
|
122
|
+
end
|
123
|
+
self.download('gooddata_connector_config.json')
|
124
|
+
end
|
125
|
+
|
126
|
+
def exists? file
|
127
|
+
begin
|
128
|
+
@s3.get_object(bucket_name: @bucket_name, key:file)
|
129
|
+
true
|
130
|
+
rescue AWS::S3::Errors::NoSuchKey
|
131
|
+
false
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
alias :include? :exists?
|
136
|
+
|
137
|
+
def delete file
|
138
|
+
@s3.delete_object(bucket_name: @bucket_name, key: file)
|
139
|
+
end
|
140
|
+
|
141
|
+
|
142
|
+
end
|
data/lib/gooddata_s3.rb
ADDED
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gooddata_s3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Patrick McConlogue
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.7.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.7.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: aws-sdk
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.61.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.61.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pmap
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.0.2
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.0.2
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.9.12.6
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.9.12.6
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: gooddata
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.6.12
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.6.12
|
83
|
+
description: Uploading wrapper for AWS S3/GoodData Integrations
|
84
|
+
email: patrick.mcconlogue@gooddata.com
|
85
|
+
executables: []
|
86
|
+
extensions: []
|
87
|
+
extra_rdoc_files: []
|
88
|
+
files:
|
89
|
+
- lib/gooddata_s3.rb
|
90
|
+
- lib/gooddata_s3/client.rb
|
91
|
+
homepage: https://github.com/thnkr/connectors/tree/master/s3
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.9.3
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.2.2
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Uploading wrapper for AWS S3/GoodData Integrations
|
115
|
+
test_files: []
|
116
|
+
has_rdoc:
|