capriza-aws 0.0.2 → 0.0.3
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.
- data/lib/capriza-aws/version.rb +1 -1
- data/lib/capriza-aws.rb +41 -20
- metadata +2 -2
data/lib/capriza-aws/version.rb
CHANGED
data/lib/capriza-aws.rb
CHANGED
@@ -9,38 +9,59 @@ module Capriza
|
|
9
9
|
|
10
10
|
class S3connect
|
11
11
|
|
12
|
-
def initialize (
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
12
|
+
def initialize (config)
|
13
|
+
@config = config
|
14
|
+
self.validate
|
15
|
+
AWS.config(@config)
|
16
|
+
end
|
17
|
+
|
18
|
+
def validate
|
19
|
+
if @config.kind_of?(String) and File.exist?(config_file)
|
20
|
+
if File.exist?(config_file)
|
21
|
+
self.read_config_file(@config)
|
22
|
+
else
|
23
|
+
raise "Config file #{config_file} not found"
|
24
|
+
end
|
25
|
+
elsif @config.kind_of?(Hash)
|
26
|
+
puts @config
|
27
|
+
unless @config.has_key?('access_key_id') and @config.has_key?('secret_access_key') and @config.has_key?('s3_endpoint')
|
28
|
+
raise "Configuration missing. need the following " +
|
29
|
+
"access_key_id: YOUR_ACCESS_KEY_ID " +
|
30
|
+
"secret_access_key: YOUR_SECRET_ACCESS_KEY " +
|
31
|
+
"s3_endpoint: YOUR_S3_ENDPOINT "
|
32
|
+
end
|
20
33
|
else
|
21
|
-
raise
|
34
|
+
raise("Unrecognized Format. Config can be an filename or Hash.")
|
22
35
|
end
|
23
|
-
unless config.kind_of?(Hash)
|
24
|
-
raise "Config file #{config_file} is formatted incorrectly. Please use the following format:" +
|
25
|
-
"access_key_id: YOUR_ACCESS_KEY_ID" +
|
26
|
-
"secret_access_key: YOUR_SECRET_ACCESS_KEY" +
|
27
|
-
"s3_endpoint: YOUR_S3_ENDPOINT"
|
28
|
-
end
|
29
|
-
AWS.config(config)
|
30
36
|
end
|
31
37
|
|
38
|
+
def read_config_file(config_file)
|
39
|
+
case File.extname(config_file)
|
40
|
+
when '.yaml'
|
41
|
+
@config = YAML.load(File.read(config_file))
|
42
|
+
when '.json'
|
43
|
+
@config = JSON.load(File.read(config_file))
|
44
|
+
else
|
45
|
+
raise "Unrecognized file extension. Currently only support json and yaml"
|
46
|
+
end
|
47
|
+
end
|
32
48
|
end
|
33
49
|
|
34
50
|
class S3file
|
35
|
-
def initialize(bucket, file_name,
|
36
|
-
S3connect.new(
|
51
|
+
def initialize(bucket, file_name, config)
|
52
|
+
S3connect.new(config)
|
37
53
|
s3 = AWS::S3.new()
|
38
54
|
@obj = s3.buckets[bucket].objects[file_name]
|
39
55
|
end
|
40
56
|
|
41
|
-
def upload(data)
|
57
|
+
def upload(data, make_public = false)
|
42
58
|
@data = data
|
43
59
|
@obj.write(@data)
|
60
|
+
if make_public
|
61
|
+
@obj.acl = :public_read
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
44
65
|
end
|
45
66
|
|
46
67
|
def download()
|
@@ -56,7 +77,7 @@ module Capriza
|
|
56
77
|
end
|
57
78
|
|
58
79
|
def <=> (local_file)
|
59
|
-
|
80
|
+
unless File.exist?(local_file)
|
60
81
|
raise "File #{local_file} does not exist"
|
61
82
|
end
|
62
83
|
@obj.etag.gsub(/\"/,"") == Digest::MD5.hexdigest(File.read(local_file))
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capriza-aws
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-04-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: aws-sdk
|