capriza-aws2 0.0.24

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.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capriza-aws.gemspec
4
+ gemspec
@@ -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.
@@ -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
@@ -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-aws2"
8
+ gem.version = Capriza::Aws::VERSION
9
+ gem.authors = ["Capriza"]
10
+ gem.email = ["devops@capriza.com"]
11
+ gem.description = %q{AWS Helper Files}
12
+ gem.summary = %q{AWS Helper Files}
13
+ gem.homepage = "http://rubygems.org/gems/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
@@ -0,0 +1,117 @@
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)
59
+ @data = data
60
+ @obj.write(@data)
61
+ metadata = @obj.head[:metadata]
62
+ content_type = "application/zip"
63
+ @obj.copy_to(@obj.key, :metadata => metadata, :content_type => content_type)
64
+ @obj.acl = :public_read if make_public
65
+ end
66
+
67
+ def download()
68
+ @data = @obj.read
69
+ end
70
+
71
+ def set_metadata(key, value)
72
+ @obj.metadata[key] = value
73
+ end
74
+
75
+ def get_metadata(key)
76
+ @obj.metadata[key]
77
+ end
78
+
79
+ def <=> (local_file)
80
+ unless File.exist?(local_file)
81
+ raise "File #{local_file} does not exist"
82
+ end
83
+ @obj.etag.gsub(/\"/, "") == Digest::MD5.hexdigest(File.read(local_file))
84
+ end
85
+
86
+ end
87
+
88
+
89
+ require 'aws-sdk'
90
+ require 'find'
91
+
92
+ class S3Upload
93
+
94
+ def initialize(options = {})
95
+ @options = options
96
+ AWS.config(@options[:config])
97
+ @s3 = AWS::S3.new(:s3_endpoint => @options[:config]['s3_endpoint'])
98
+ end
99
+
100
+ def upload
101
+ Dir.glob("#{@options[:dir]}/**/*").each do |file|
102
+ puts "starting upload of #{file} to #{@options[:bucket]}"
103
+ @s3.buckets[@options[:bucket]].objects[file].write(File.read(file), @options[:file_options] || {} ) unless File.directory?(file)
104
+ puts "completed upload of #{file} to #{@options[:bucket]}"
105
+ end
106
+ end
107
+
108
+ def delete
109
+ puts "deleting #{@options['dir']}"
110
+ @s3.buckets[@options[:bucket]].objects.with_prefix(@options[:dir] + '/').delete_all
111
+ end
112
+
113
+ end
114
+
115
+ end
116
+
117
+ end
@@ -0,0 +1,5 @@
1
+ module Capriza
2
+ module Aws
3
+ VERSION = "0.0.24"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capriza-aws2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.24
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Capriza
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: aws-sdk
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: AWS Helper Files
31
+ email:
32
+ - devops@capriza.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - capriza-aws.gemspec
43
+ - lib/capriza-aws.rb
44
+ - lib/capriza-aws/version.rb
45
+ homepage: http://rubygems.org/gems/capriza-aws
46
+ licenses: []
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubyforge_project:
65
+ rubygems_version: 1.8.24
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: AWS Helper Files
69
+ test_files: []