capriza-aws-helper 0.0.27
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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +67 -0
- data/Rakefile +1 -0
- data/capriza-aws-helper.gemspec +22 -0
- data/lib/capriza-aws.rb +120 -0
- data/lib/capriza-aws/version.rb +5 -0
- metadata +65 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f1ba98cc6078ba815f735cbf10d76d443823ab52
|
4
|
+
data.tar.gz: 9714c2b2a6aaa2d0a13c35ead83f2758ca0f54ef
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5fea657731db3347adf8d7afd146de419d0fc8ca09adcfa684e4ab3d843672c336f63cef894b4884686b02fa91781c113ffc3ffcb775e6b9d1cecce4bea5c013
|
7
|
+
data.tar.gz: f87d57da400a4a4ee12453cfc6a95893df374fc5274210191c0f59c5f99bb9d3b7aa6bdc154b5a4fcc1f48a86468f7f808004345c0b19758142cd54d97d4601b
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Alon Becker
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# Capriza::Aws
|
2
|
+
|
3
|
+
Capriza::Aws is a helper gem for AWS tasks. Currently there is one class Capriza::Aws::S3File which can upload, download, add metadata and compare local and S3 files.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'capriza-aws'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install capriza-aws
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
To use first create a config.yaml file with the following content
|
22
|
+
|
23
|
+
access_key_id: YOUR_ACCESS_KEY_ID
|
24
|
+
secret_access_key: YOUR_SECRET_ACCESS_KEY
|
25
|
+
s3_endpoint: YOUR_S3_ENDPOINT
|
26
|
+
|
27
|
+
Once configured run the following to instantiate:
|
28
|
+
|
29
|
+
$ require 'capriza-aws'
|
30
|
+
|
31
|
+
$ s3 = Capriza::Aws::S3File('BUCKET_NAME','S3_FILE_NAME','CONFIG_FILE_NAME_FULL_PATH')
|
32
|
+
|
33
|
+
To Upload:
|
34
|
+
|
35
|
+
$ s3.upload('Hello World')
|
36
|
+
|
37
|
+
or
|
38
|
+
|
39
|
+
$ s3.upload(File.read('FILE_NAME'))
|
40
|
+
|
41
|
+
To Download:
|
42
|
+
|
43
|
+
$ data = s3.download
|
44
|
+
or
|
45
|
+
|
46
|
+
$ File.write('FILE_NAME', s3.download)
|
47
|
+
|
48
|
+
To Upload file metadata to S3
|
49
|
+
|
50
|
+
$ s3.set_metadata(key,value)
|
51
|
+
|
52
|
+
To Download file metadata from S3
|
53
|
+
|
54
|
+
$ data = s3.get_metadata(key)
|
55
|
+
|
56
|
+
To Compare a file to the S3 File
|
57
|
+
|
58
|
+
$ s3 <=> 'FILE_NAME'
|
59
|
+
|
60
|
+
|
61
|
+
## Contributing
|
62
|
+
|
63
|
+
1. Fork it
|
64
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
65
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
66
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
67
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'capriza-aws/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = 'capriza-aws-helper'
|
8
|
+
gem.version = Capriza::Aws::VERSION
|
9
|
+
gem.authors = ['Capriza']
|
10
|
+
gem.email = ['backend@capriza.com']
|
11
|
+
gem.description = %q{AWS Helper Files}
|
12
|
+
gem.summary = %q{AWS Helper Files}
|
13
|
+
gem.homepage = 'http://github.com/capriza/capriza-aws'
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ['lib']
|
19
|
+
|
20
|
+
gem.add_dependency 'aws-sdk'
|
21
|
+
|
22
|
+
end
|
data/lib/capriza-aws.rb
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'capriza-aws/version'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'yaml'
|
4
|
+
require 'json'
|
5
|
+
require 'aws-sdk'
|
6
|
+
require 'find'
|
7
|
+
|
8
|
+
module Capriza
|
9
|
+
module Aws
|
10
|
+
|
11
|
+
class S3connect
|
12
|
+
|
13
|
+
def initialize (config)
|
14
|
+
@config = config
|
15
|
+
self.validate
|
16
|
+
AWS.config(@config)
|
17
|
+
end
|
18
|
+
|
19
|
+
def validate
|
20
|
+
if @config.kind_of?(String) and File.exist?(config_file)
|
21
|
+
if File.exist?(config_file)
|
22
|
+
self.read_config_file(@config)
|
23
|
+
else
|
24
|
+
raise "Config file #{config_file} not found"
|
25
|
+
end
|
26
|
+
elsif @config.kind_of?(Hash)
|
27
|
+
puts @config
|
28
|
+
unless @config.has_key?('access_key_id') and @config.has_key?('secret_access_key') and @config.has_key?('s3_endpoint')
|
29
|
+
raise "Configuration missing. need the following " +
|
30
|
+
"access_key_id: YOUR_ACCESS_KEY_ID " +
|
31
|
+
"secret_access_key: YOUR_SECRET_ACCESS_KEY " +
|
32
|
+
"s3_endpoint: YOUR_S3_ENDPOINT "
|
33
|
+
end
|
34
|
+
else
|
35
|
+
raise("Unrecognized Format. Config can be an filename or Hash.")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def read_config_file(config_file)
|
40
|
+
case File.extname(config_file)
|
41
|
+
when '.yaml'
|
42
|
+
@config = YAML.load(File.read(config_file))
|
43
|
+
when '.json'
|
44
|
+
@config = JSON.load(File.read(config_file))
|
45
|
+
else
|
46
|
+
raise "Unrecognized file extension. Currently only support json and yaml"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class S3file
|
52
|
+
def initialize(bucket, file_name, config)
|
53
|
+
S3connect.new(config)
|
54
|
+
s3 = AWS::S3.new()
|
55
|
+
@obj = s3.buckets[bucket].objects[file_name]
|
56
|
+
end
|
57
|
+
|
58
|
+
def upload(data, make_public = false, content_type = "application/zip")
|
59
|
+
@data = data
|
60
|
+
@obj.write(@data)
|
61
|
+
metadata = @obj.head[:metadata]
|
62
|
+
@obj.copy_to(@obj.key, :metadata => metadata, :content_type => content_type)
|
63
|
+
@obj.acl = :public_read if make_public
|
64
|
+
end
|
65
|
+
|
66
|
+
def download
|
67
|
+
@data = @obj.read
|
68
|
+
end
|
69
|
+
|
70
|
+
def exists?
|
71
|
+
@obj.exists?
|
72
|
+
end
|
73
|
+
|
74
|
+
def set_metadata(key, value)
|
75
|
+
@obj.metadata[key] = value
|
76
|
+
end
|
77
|
+
|
78
|
+
def get_metadata(key)
|
79
|
+
@obj.metadata[key]
|
80
|
+
end
|
81
|
+
|
82
|
+
def <=> (local_file)
|
83
|
+
unless File.exist?(local_file)
|
84
|
+
raise "File #{local_file} does not exist"
|
85
|
+
end
|
86
|
+
@obj.etag.gsub(/\"/, "") == Digest::MD5.hexdigest(File.read(local_file))
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
require 'aws-sdk'
|
93
|
+
require 'find'
|
94
|
+
|
95
|
+
class S3Upload
|
96
|
+
|
97
|
+
def initialize(options = {})
|
98
|
+
@options = options
|
99
|
+
AWS.config(@options[:config])
|
100
|
+
@s3 = AWS::S3.new(:s3_endpoint => @options[:config]['s3_endpoint'])
|
101
|
+
end
|
102
|
+
|
103
|
+
def upload
|
104
|
+
Dir.glob("#{@options[:dir]}/**/*").each do |file|
|
105
|
+
puts "starting upload of #{file} to #{@options[:bucket]}"
|
106
|
+
@s3.buckets[@options[:bucket]].objects[file].write(File.read(file), @options[:file_options] || {} ) unless File.directory?(file)
|
107
|
+
puts "completed upload of #{file} to #{@options[:bucket]}"
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def delete
|
112
|
+
puts "deleting #{@options['dir']}"
|
113
|
+
@s3.buckets[@options[:bucket]].objects.with_prefix(@options[:dir] + '/').delete_all
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capriza-aws-helper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.27
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Capriza
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aws-sdk
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: AWS Helper Files
|
28
|
+
email:
|
29
|
+
- backend@capriza.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- Gemfile
|
36
|
+
- LICENSE.txt
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- capriza-aws-helper.gemspec
|
40
|
+
- lib/capriza-aws.rb
|
41
|
+
- lib/capriza-aws/version.rb
|
42
|
+
homepage: http://github.com/capriza/capriza-aws
|
43
|
+
licenses: []
|
44
|
+
metadata: {}
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 2.4.3
|
62
|
+
signing_key:
|
63
|
+
specification_version: 4
|
64
|
+
summary: AWS Helper Files
|
65
|
+
test_files: []
|