cloud_encrypted_sync_s3_adapter 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ coverage
2
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+ gemspec
3
+
4
+ gem 'cloud_encrypted_sync', :path => '~/workspace/cloud_encrypted_sync'
data/Gemfile.lock ADDED
@@ -0,0 +1,51 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cloud_encrypted_sync_s3_adapter (0.0.1)
5
+ aws-sdk (~> 1.4.1)
6
+ cloud_encrypted_sync (~> 0.0.1)
7
+
8
+ PATH
9
+ remote: ~/workspace/cloud_encrypted_sync
10
+ specs:
11
+ cloud_encrypted_sync (0.0.1)
12
+
13
+ GEM
14
+ remote: http://rubygems.org/
15
+ specs:
16
+ activesupport (3.2.3)
17
+ i18n (~> 0.6)
18
+ multi_json (~> 1.0)
19
+ aws-sdk (1.4.1)
20
+ httparty (~> 0.7)
21
+ json (~> 1.4)
22
+ nokogiri (>= 1.4.4)
23
+ uuidtools (~> 2.1)
24
+ httparty (0.8.3)
25
+ multi_json (~> 1.0)
26
+ multi_xml
27
+ i18n (0.6.0)
28
+ json (1.7.3)
29
+ metaclass (0.0.1)
30
+ mocha (0.11.4)
31
+ metaclass (~> 0.0.1)
32
+ multi_json (1.3.4)
33
+ multi_xml (0.5.1)
34
+ nokogiri (1.5.5)
35
+ rake (0.9.2.2)
36
+ simplecov (0.6.4)
37
+ multi_json (~> 1.0)
38
+ simplecov-html (~> 0.5.3)
39
+ simplecov-html (0.5.3)
40
+ uuidtools (2.1.2)
41
+
42
+ PLATFORMS
43
+ ruby
44
+
45
+ DEPENDENCIES
46
+ activesupport
47
+ cloud_encrypted_sync!
48
+ cloud_encrypted_sync_s3_adapter!
49
+ mocha
50
+ rake
51
+ simplecov
data/LICENSE ADDED
@@ -0,0 +1,17 @@
1
+ Copyright (c) 2012 Jonathan S. Garvin
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this
4
+ software and associated documentation files (the "Software"), to deal in the Software
5
+ without restriction, including without limitation the rights to use, copy, modify, merge,
6
+ publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7
+ to whom the Software is furnished to do so, subject to the following conditions:
8
+
9
+ The above copyright notice and this permission notice shall be included in all copies or
10
+ substantial portions of the Software.
11
+
12
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13
+ INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14
+ PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15
+ FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
16
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ CloudEncryptedCync S3 Adapter
2
+ =============================
3
+
4
+ An Amazon S3 adapter for the CloudEncryptedSync Ruby gem.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'rake/testtask'
2
+
3
+ task :default => :test
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << 'lib'
7
+ t.libs << 'test'
8
+ t.pattern = 'test/**/*_test.rb'
9
+ t.verbose = true
10
+ end
@@ -0,0 +1,25 @@
1
+ require File.expand_path('../lib/cloud_encrypted_sync_s3_adapter/version', __FILE__)
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "cloud_encrypted_sync_s3_adapter"
5
+ s.version = CloudEncryptedSyncS3Adapter::VERSION
6
+ s.platform = Gem::Platform::RUBY
7
+ s.authors = ["Jonathan S. Garvin"]
8
+ s.email = ["jon@5valleys.com"]
9
+ s.homepage = "https://github.com/jsgarvin/cloud_encrypted_sync_s3_adapter"
10
+ s.summary = %q{Plugin adapter for CloudEncryptedSync gem that provides interface to AmazonS3.}
11
+ s.description = %q{Plugin adapter for CloudEncryptedSync gem that provides interface to AmazonS3.}
12
+
13
+ s.add_dependency('aws-sdk', '~> 1.4.1')
14
+ s.add_dependency('cloud_encrypted_sync', '~> 0.0.1')
15
+
16
+ s.add_development_dependency('rake')
17
+ s.add_development_dependency('mocha')
18
+ s.add_development_dependency('simplecov')
19
+ s.add_development_dependency('activesupport')
20
+
21
+ s.files = `git ls-files`.split("\n")
22
+ s.test_files = `git ls-files -- test/*`.split("\n")
23
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
24
+ s.require_paths = ["lib"]
25
+ end
@@ -0,0 +1 @@
1
+ require File.expand_path('../cloud_encrypted_sync_s3_adapter/adapter', __FILE__)
@@ -0,0 +1,58 @@
1
+ require 'aws-sdk'
2
+
3
+ module CloudEncryptedSync
4
+ module Adapters
5
+ class S3 < Template
6
+
7
+ class << self
8
+
9
+ def parse_command_line_options(opts,command_line_options)
10
+ opts.on('--bucket=BUCKETNAME', 'Name of S3 bucket to use.') do |bucket_name|
11
+ command_line_options[:bucket] = bucket_name
12
+ end
13
+ opts.on('--s3-credentials=ACCESS_KEY_ID,SECRET_ACCESS_KEY', Array, "Credentials for your S3 account." ) do| credentials|
14
+ command_line_options[:s3_credentials] = credentials
15
+ end
16
+ return command_line_options
17
+ end
18
+
19
+ def write(data, key)
20
+ bucket.objects.create(key,data)
21
+ end
22
+
23
+ def read(key)
24
+ bucket.objects[key].read
25
+ end
26
+
27
+ def delete(key)
28
+ bucket.objects[key].delete
29
+ end
30
+
31
+ def key_exists?(key)
32
+ bucket.objects[key].exists?
33
+ end
34
+
35
+ #######
36
+ private
37
+ #######
38
+
39
+ def credentials
40
+ Configuration.settings[:s3_credentials]
41
+ end
42
+
43
+ def connection
44
+ @connection ||= AWS::S3.new(:access_key_id => credentials[0], :secret_access_key => credentials[1])
45
+ end
46
+
47
+ def bucket_name
48
+ Configuration.settings[:bucket].to_sym
49
+ end
50
+
51
+ def bucket
52
+ connection.buckets[bucket_name]
53
+ end
54
+
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,3 @@
1
+ module CloudEncryptedSyncS3Adapter
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,30 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'simplecov'
4
+ require 'active_support/test_case'
5
+ require 'test/unit'
6
+ require 'etc'
7
+
8
+ SimpleCov.start
9
+
10
+ require 'cloud_encrypted_sync'
11
+ require 'cloud_encrypted_sync_s3_adapter'
12
+
13
+ module CloudEncryptedSyncS3Adapter
14
+ class ActiveSupport::TestCase
15
+
16
+ setup :preset_environment
17
+
18
+ def preset_environment
19
+ CloudEncryptedSync::Master.instance_variable_set(:@config,nil)
20
+ CloudEncryptedSync::Master.instance_variable_set(:@command_line_options, {
21
+ :data_dir => "#{Etc.getpwuid.dir}/.cloud_encrypted_sync"
22
+ })
23
+ end
24
+
25
+ def adapter
26
+ CloudEncryptedSync::Adapters::S3
27
+ end
28
+ end
29
+ end
30
+ require 'mocha'
@@ -0,0 +1,54 @@
1
+ require 'test_helper'
2
+
3
+ module CloudEncryptedSyncS3Adapter
4
+ class AdapterTest < ActiveSupport::TestCase
5
+
6
+ def setup
7
+ if File.exist?(CloudEncryptedSync::Master.send(:config_file_path))
8
+ @config = YAML.load_file(CloudEncryptedSync::Master.send(:config_file_path))
9
+ end
10
+ @test_bucket_name = "cloud_encrypted_sync_unit_test_bucket_#{Digest::SHA1.hexdigest(rand.to_s)}"
11
+ CloudEncryptedSync::Master.instance_variable_set(:@command_line_options, CloudEncryptedSync::Master.instance_variable_get(:@command_line_options).merge({:bucket => @test_bucket_name, :s3_credentials => @config['s3_credentials']}))
12
+ create_test_bucket
13
+ end
14
+
15
+ test 'should write readable data to s3 and then delete it' do
16
+
17
+ skip 'S3 credentials for test bucket not provided.' unless credentials.is_a?(Array) and credentials != []
18
+
19
+ test_data = 'testdata'
20
+ test_key = 'testkey'
21
+
22
+ assert !adapter.key_exists?(test_key)
23
+ assert_difference('adapter.send(:bucket).objects.count') do
24
+ adapter.write(test_data,test_key)
25
+ end
26
+ assert adapter.key_exists?(test_key)
27
+
28
+ assert_equal(test_data,adapter.read(test_key))
29
+
30
+ assert_difference('adapter.send(:bucket).objects.count',-1) do
31
+ adapter.delete(test_key)
32
+ end
33
+ assert !adapter.key_exists?(test_key)
34
+
35
+ end
36
+
37
+
38
+ #######
39
+ private
40
+ #######
41
+
42
+ def credentials
43
+ @config['s3_credentials']
44
+ end
45
+
46
+ def create_test_bucket
47
+ adapter.send(:connection).buckets.create(@test_bucket_name)
48
+ end
49
+
50
+ def delete_test_bucket
51
+ adapter.send(:bucket).delete! unless credentials == [] or !credentials.is_a?(Array)
52
+ end
53
+ end
54
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cloud_encrypted_sync_s3_adapter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jonathan S. Garvin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-14 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: 1.4.1
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: 1.4.1
30
+ - !ruby/object:Gem::Dependency
31
+ name: cloud_encrypted_sync
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.0.1
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.0.1
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: mocha
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: simplecov
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: activesupport
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: Plugin adapter for CloudEncryptedSync gem that provides interface to
111
+ AmazonS3.
112
+ email:
113
+ - jon@5valleys.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - Gemfile
120
+ - Gemfile.lock
121
+ - LICENSE
122
+ - README.md
123
+ - Rakefile
124
+ - cloud_encrypted_sync_s3_adapter.gemspec
125
+ - lib/cloud_encrypted_sync_s3_adapter.rb
126
+ - lib/cloud_encrypted_sync_s3_adapter/adapter.rb
127
+ - lib/cloud_encrypted_sync_s3_adapter/version.rb
128
+ - test/test_helper.rb
129
+ - test/unit/adapter_test.rb
130
+ homepage: https://github.com/jsgarvin/cloud_encrypted_sync_s3_adapter
131
+ licenses: []
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ none: false
144
+ requirements:
145
+ - - ! '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubyforge_project:
150
+ rubygems_version: 1.8.24
151
+ signing_key:
152
+ specification_version: 3
153
+ summary: Plugin adapter for CloudEncryptedSync gem that provides interface to AmazonS3.
154
+ test_files:
155
+ - test/test_helper.rb
156
+ - test/unit/adapter_test.rb