cloud_encrypted_sync_s3_adapter 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cloud_encrypted_sync_s3_adapter (0.3.0)
4
+ cloud_encrypted_sync_s3_adapter (0.3.1)
5
5
  aws-sdk (~> 1.7.1)
6
6
  cloud_encrypted_sync (~> 0.3.0)
7
7
 
@@ -3,14 +3,17 @@ require 'aws-sdk'
3
3
  module CloudEncryptedSync
4
4
  module Adapters
5
5
  class S3 < Template
6
- attr_accessor :bucket_name, :credentials
6
+ attr_writer :bucket_name, :access_key, :access_key_id
7
7
 
8
8
  def parse_command_line_options(parser)
9
9
  parser.on('--bucket BUCKETNAME', 'Name of S3 bucket to use.') do |bucket_argument|
10
- self.bucket_name = bucket_argument.to_sym
10
+ self.bucket_name = bucket_argument
11
11
  end
12
- parser.on('--s3-credentials ACCESS_KEY_ID,SECRET_ACCESS_KEY', Array, "Credentials for your S3 account." ) do |credentials_argument|
13
- self.credentials = credentials_argument
12
+ parser.on('--access-key KEY', 'Access Key for S3 login.') do |bucket_argument|
13
+ self.access_key = bucket_argument
14
+ end
15
+ parser.on('--access-key-id KEYID', 'Access Key ID for S3 login.') do |bucket_argument|
16
+ self.access_key_id = bucket_argument
14
17
  end
15
18
  end
16
19
 
@@ -38,8 +41,20 @@ module CloudEncryptedSync
38
41
  private
39
42
  #######
40
43
 
44
+ def bucket_name
45
+ @bucket_name || Configuration.settings['s3-bucket']
46
+ end
47
+
48
+ def access_key
49
+ @access_key || Configuration.settings['s3-access-key']
50
+ end
51
+
52
+ def access_key_id
53
+ @access_key_id || Configuration.settings['s3-access-key-id']
54
+ end
55
+
41
56
  def connection
42
- @connection ||= AWS::S3.new(:access_key_id => credentials[0], :secret_access_key => credentials[1])
57
+ @connection ||= AWS::S3.new(:access_key_id => access_key_id, :secret_access_key => access_key)
43
58
  end
44
59
 
45
60
  def bucket
@@ -1,3 +1,3 @@
1
1
  module CloudEncryptedSyncS3Adapter
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end
@@ -18,20 +18,21 @@ module CloudEncryptedSyncS3Adapter
18
18
  test 'should parse command line options' do
19
19
  unstub_configuration
20
20
  Object.send(:remove_const,:ARGV)
21
- ::ARGV = '--bucket foobar --s3-credentials KEY_ID,ACCESS_KEY'.split(/\s/)
21
+ ::ARGV = '--bucket foobar --access-key-id KEY_ID --access-key ACCESS_KEY'.split(/\s/)
22
22
  @command_line_options = {}
23
23
  @option_parser = OptionParser.new do |parser|
24
24
  adapter.parse_command_line_options(parser)
25
25
  end
26
26
  @option_parser.parse!
27
- assert_equal(:foobar,CloudEncryptedSync::Adapters::S3.instance.bucket_name)
28
- assert_equal(['KEY_ID','ACCESS_KEY'],CloudEncryptedSync::Adapters::S3.instance.credentials)
27
+ assert_equal('foobar',CloudEncryptedSync::Adapters::S3.instance.send(:bucket_name))
28
+ assert_equal('KEY_ID',CloudEncryptedSync::Adapters::S3.instance.send(:access_key_id))
29
+ assert_equal('ACCESS_KEY',CloudEncryptedSync::Adapters::S3.instance.send(:access_key))
29
30
  stub_configuration
30
31
  end
31
32
 
32
33
  test 'should write readable data to s3 and then delete it' do
33
34
 
34
- skip 'S3 credentials for test bucket not provided.' unless credentials.is_a?(Array) and credentials != []
35
+ skip 'S3 credentials for test bucket not provided.' unless access_key and access_key_id
35
36
 
36
37
  test_data = 'testdata'
37
38
  test_key = 'testkey'
@@ -59,8 +60,12 @@ module CloudEncryptedSyncS3Adapter
59
60
  private
60
61
  #######
61
62
 
62
- def credentials
63
- @config['s3_credentials']
63
+ def access_key
64
+ @config['s3-access-key']
65
+ end
66
+
67
+ def access_key_id
68
+ @config['s3-access-key-id']
64
69
  end
65
70
 
66
71
  def create_test_bucket
@@ -68,7 +73,7 @@ module CloudEncryptedSyncS3Adapter
68
73
  end
69
74
 
70
75
  def delete_test_bucket
71
- adapter.instance.send(:bucket).delete! unless credentials == [] or !credentials.is_a?(Array)
76
+ adapter.instance.send(:bucket).delete! if access_key and access_key_id
72
77
  end
73
78
 
74
79
  def test_bucket_name
@@ -80,19 +85,19 @@ module CloudEncryptedSyncS3Adapter
80
85
  {
81
86
  :excryption_key => 'abc',
82
87
  :adapter => 's3',
83
- :bucket => test_bucket_name,
84
- :sync_path => '/non/existent/path',
85
- :s3_credentials => @config['s3_credentials']
88
+ :sync_path => '/any/path',
86
89
  }
87
90
  )
88
91
  CloudEncryptedSync::Adapters::S3.any_instance.stubs(:bucket_name).returns(test_bucket_name)
89
- CloudEncryptedSync::Adapters::S3.any_instance.stubs(:credentials).returns(@config['s3_credentials'])
92
+ CloudEncryptedSync::Adapters::S3.any_instance.stubs(:access_key).returns(access_key)
93
+ CloudEncryptedSync::Adapters::S3.any_instance.stubs(:access_key_id).returns(access_key_id)
90
94
  end
91
95
 
92
96
  def unstub_configuration
93
97
  CloudEncryptedSync::Configuration.unstub(:settings)
94
98
  CloudEncryptedSync::Adapters::S3.any_instance.unstub(:bucket_name)
95
- CloudEncryptedSync::Adapters::S3.any_instance.unstub(:credentials)
99
+ CloudEncryptedSync::Adapters::S3.any_instance.unstub(:access_key)
100
+ CloudEncryptedSync::Adapters::S3.any_instance.unstub(:access_key_id)
96
101
  end
97
102
  end
98
103
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloud_encrypted_sync_s3_adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: