usmu-s3 1.0.0 → 1.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a2bf26b514877f1596619bb43c3f6a702fd26be9
4
- data.tar.gz: d2ad7cd9958cf71e5e68a123555829d08677db50
3
+ metadata.gz: ed718f2274fba13642f76b974506164780db8d06
4
+ data.tar.gz: 88a9c13316372475e68922edeca87e80089c6d73
5
5
  SHA512:
6
- metadata.gz: a040b35e4fc077cd0b82677b2efe3cc0608be03842e0890bea510af89827ee245de5425e2334a427f50673ffb37298fb7b75910116c2b9fc30bf77f272b98cc5
7
- data.tar.gz: b05383994090614f96c6befb4d90122d0ed92d5cbcd5362d55e9c9933307a5c649c940bcd0748719d34ab8d34fc409cd5fe1ec7a975508c02aed41d2f4bca097
6
+ metadata.gz: 02e856d7c49ab50309c0a5c3dc6858d51ef12b4fe5a766884c756847972c11a2b16adc44437746283a1f2ea3f2acfc9d313ebe3fd10cc9e30527bae6d068de7e
7
+ data.tar.gz: 72d2601cdf3c358452dc6034a11f720d3614aa2fde9d6554b1cf3402df213e72e4cc5c895ad2a3858cec9bfa02779f75bd636eea35037eee85a15a27538f6f8b
@@ -1,5 +1,14 @@
1
1
  # Usmu S3 Upload plugin changelog
2
2
 
3
+ ## 1.1.0.pre
4
+
5
+ Matthew Scharley <matt.scharley@gmail.com>
6
+
7
+ * Bump to 1.1.0.pre for further dev (7778eab819fcbd07560615fa2e6333f8d339201e)
8
+ * [ci skip] Update README (8638b8202aef9b9662fdbc738c209c485d206842)
9
+ * [#9] Add reduced redundancy support (63506a00ac84e38f171e9386cd54ea2e0df8fab2)
10
+ * Fix command's tests (788741ef5d95c766140e20bed7ea167f23451d22)
11
+
3
12
  ## 1.0.0
4
13
 
5
14
  Matthew Scharley <matt.scharley@gmail.com>
data/README.md CHANGED
@@ -16,15 +16,34 @@
16
16
 
17
17
  Allows you to deploy your [Usmu][usmu] website to Amazon's S3 service.
18
18
 
19
- TODO: Write synopsis here
20
-
21
19
  ## Installation
22
20
 
23
21
  $ gem install usmu-s3
24
22
 
23
+ OR
24
+
25
+ $ echo 'gem "usmu-s3"' >> Gemfile
26
+ $ bundle install
27
+
28
+ Usmu will automatically detect any plugins available and automatically make them available.
29
+
30
+ ## Configuration
31
+
32
+ You can configure this plugin in your `usmu.yml` file:
33
+
34
+ plugin:
35
+ s3:
36
+ access_key: '%env{AWS_ACCESS_KEY_ID}'
37
+ secret_key: '%env{AWS_SECRET_ACCESS_KEY}'
38
+ region: 'us-east-1'
39
+ bucket: 'usmu.org'
40
+
41
+ All S3 configuration options can be pulled from environment variables as shown above. Your access key and secret key
42
+ will default to the above environment variables (the same ones used by the SDK) if not specified.
43
+
25
44
  ## Usage
26
45
 
27
- TODO: Write usage instructions here
46
+ $ usmu s3 deploy
28
47
 
29
48
  [gh-contrib]: https://github.com/usmu/usmu-s3/graphs/contributors
30
49
  [gh-issues]: https://github.com/usmu/usmu-s3/issues
@@ -30,9 +30,9 @@ module Usmu
30
30
  end
31
31
  end
32
32
 
33
- def command_deploy(args = [], options = {})
34
- raise 'This command does not take arguments.' unless args.empty?
35
- raise 'Invalid options, must be a Hash.' unless options.instance_of? Hash
33
+ def command_deploy(args, options)
34
+ raise 'This command does not take arguments' unless args.empty?
35
+ raise 'Invalid options' unless options.inspect.start_with? '<Commander::Command::Options '
36
36
 
37
37
  configuration = @ui.configuration
38
38
  s3_configuration = S3Configuration.new(configuration['plugin', 's3', default: {}])
@@ -23,6 +23,10 @@ module Usmu
23
23
  substitute_env @config['bucket'] || ''
24
24
  end
25
25
 
26
+ def reduced_redundancy
27
+ @config['reduced redundancy'] || false
28
+ end
29
+
26
30
  def inspect
27
31
  "\#<#{self.class} region=\"#{region}\" access_key=\"#{access_key}\" bucket=\"#{bucket}\">"
28
32
  end
@@ -7,6 +7,7 @@ module Usmu
7
7
  def initialize(configuration, s3_configuration)
8
8
  @log = Logging.logger[self]
9
9
  @configuration = configuration
10
+ @s3_configuration = s3_configuration
10
11
  s3 = Aws::S3::Resource.new(credentials: s3_configuration.credentials, region: s3_configuration.region)
11
12
  @bucket = s3.bucket(s3_configuration.bucket)
12
13
  end
@@ -21,15 +22,18 @@ module Usmu
21
22
 
22
23
  attr_reader :log
23
24
  attr_reader :configuration
25
+ attr_reader :s3_configuration
24
26
  attr_reader :bucket
25
27
 
26
28
  def push_local(files)
29
+ storage_class = @s3_configuration.reduced_redundancy ? 'REDUCED_REDUNDANCY' : 'STANDARD'
27
30
  for file in files
28
31
  @log.success("Uploading #{file}")
29
32
  File.open(File.join(@configuration.destination_path, file), 'r') do |io|
30
33
  @bucket.put_object({
31
34
  key: file,
32
35
  body: io,
36
+ storage_class: storage_class
33
37
  })
34
38
  end
35
39
  end
@@ -2,6 +2,6 @@
2
2
  module Usmu
3
3
  class S3
4
4
  # The current version string for the gem
5
- VERSION = '1.0.0'
5
+ VERSION = '1.0.1'
6
6
  end
7
7
  end
@@ -10,6 +10,7 @@ RSpec.describe Usmu::S3::S3Configuration do
10
10
  'access key' => 'replace %env{TEST_ACCESS_KEY}',
11
11
  'secret key' => 'replace %env{TEST_SECRET_KEY}',
12
12
  'bucket' => 'replace %env{TEST_BUCKET}',
13
+ 'reduced redundancy' => true,
13
14
  }
14
15
  )
15
16
  }
@@ -86,6 +87,16 @@ RSpec.describe Usmu::S3::S3Configuration do
86
87
  end
87
88
  end
88
89
 
90
+ context '#reduced_redundancy' do
91
+ it 'has a default value of false' do
92
+ expect(empty_configuration.reduced_redundancy).to eq(false)
93
+ end
94
+
95
+ it 'returns the "reduced redundancy" key' do
96
+ expect(configuration.reduced_redundancy).to eq(true)
97
+ end
98
+ end
99
+
89
100
  context '#substitute_env' do
90
101
  it 'replaces environment variables' do
91
102
  expect(empty_configuration.send :substitute_env, '%env{AWS_REGION}').to eq('us-east-1')
@@ -21,13 +21,14 @@ RSpec.describe Usmu::S3::Uploader do
21
21
  let (:uploader) { Usmu::S3::Uploader.new(configuration, s3_configuration) }
22
22
 
23
23
  before do
24
- expect(s3_configuration).to receive(:credentials).and_return(creds)
24
+ allow(s3_configuration).to receive(:credentials).and_return(creds)
25
25
  expect(Aws::S3::Resource).to receive(:new).with({credentials: creds, region: 'us-east-1'}).and_return(s3)
26
26
  end
27
27
 
28
28
  context '#initialize' do
29
29
  it 'sets up instance variables' do
30
30
  expect(uploader.send :configuration).to eq(configuration)
31
+ expect(uploader.send :s3_configuration).to eq(s3_configuration)
31
32
  expect(uploader.send :bucket).to eq(s3)
32
33
  expect(s3.get_bucket).to eq('bucket')
33
34
  expect(uploader.send(:log).is_a? Logging::Logger).to eq(true)
@@ -51,16 +52,34 @@ RSpec.describe Usmu::S3::Uploader do
51
52
 
52
53
  context '#push_local' do
53
54
  let (:io) { OpenStruct.new {} }
55
+ let (:rr_configuration) {
56
+ Usmu::S3::S3Configuration.new(
57
+ {
58
+ 'access key' => 'access',
59
+ 'secret key' => 'secret',
60
+ 'region' => 'us-east-1',
61
+ 'bucket' => 'bucket',
62
+ 'reduced redundancy' => true,
63
+ }
64
+ )
65
+ }
66
+ let (:rr_uploader) { Usmu::S3::Uploader.new(configuration, rr_configuration) }
54
67
 
55
68
  before do
56
69
  allow(File).to receive(:open).with('site/local.html', 'r').and_yield(io)
70
+ allow(rr_configuration).to receive(:credentials).and_return(creds)
57
71
  end
58
72
 
59
73
  it 'sends a request to S3 to push named files' do
60
- expect(s3).to receive(:put_object).with({key: 'local.html', body: io})
74
+ expect(s3).to receive(:put_object).with({key: 'local.html', body: io, storage_class: 'STANDARD'})
61
75
  uploader.send :push_local, ['local.html']
62
76
  end
63
77
 
78
+ it 'uses reduced redundancy if requested' do
79
+ expect(s3).to receive(:put_object).with({key: 'local.html', body: io, storage_class: 'REDUCED_REDUNDANCY'})
80
+ rr_uploader.send :push_local, ['local.html']
81
+ end
82
+
64
83
  it 'logs files as they are pushed' do
65
84
  uploader.send :push_local, ['local.html']
66
85
  expect(@log_output.readline).to eq("SUCCESS Usmu::S3::Uploader : Uploading local.html\n")
@@ -3,6 +3,7 @@ require 'usmu/configuration'
3
3
  require 'usmu/uploader_mock'
4
4
  require 'usmu/commander_mock'
5
5
  require 'ostruct'
6
+ require 'commander'
6
7
 
7
8
  RSpec.describe Usmu::S3 do
8
9
  let(:plugin) { Usmu::S3.new }
@@ -39,7 +40,7 @@ RSpec.describe Usmu::S3 do
39
40
  plugin.commands(ui, commander)
40
41
  expect(commander.get_command(:'s3 deploy')[:syntax]).to eq('usmu s3 deploy')
41
42
  expect(commander.get_command(:'s3 deploy')[:description]).to eq('Deploys your website to S3')
42
- expect(commander.get_command(:'s3 deploy')[:action].arity).to eq(-1)
43
+ expect(commander.get_command(:'s3 deploy')[:action]).to be_a(Proc)
43
44
  end
44
45
  end
45
46
 
@@ -63,13 +64,14 @@ RSpec.describe Usmu::S3 do
63
64
  let(:diffs) { OpenStruct.new }
64
65
  let(:uploader) { Usmu::UploaderMock.new }
65
66
  let(:remote_files) { OpenStruct.new }
67
+ let (:options) { Commander::Command::Options.new }
66
68
 
67
69
  it 'raises an error when arguments are specified' do
68
- expect { plugin.command_deploy(['foo']) }.to raise_error('This command does not take arguments.')
70
+ expect { plugin.command_deploy(['foo'], options) }.to raise_error('This command does not take arguments')
69
71
  end
70
72
 
71
73
  it 'raises an error when invalid options are specified' do
72
- expect { plugin.command_deploy([], []) }.to raise_error('Invalid options, must be a Hash.')
74
+ expect { plugin.command_deploy([], []) }.to raise_error('Invalid options')
73
75
  end
74
76
 
75
77
  it 'gets a DirectoryDiff and passes that to an Uploader' do
@@ -78,7 +80,7 @@ RSpec.describe Usmu::S3 do
78
80
  expect(Usmu::Deployment::DirectoryDiff).to receive(:new).with(configuration, remote_files).and_return(differ)
79
81
  expect(Usmu::S3::Uploader).to receive(:new).with(configuration, s3_configuration).and_return(uploader)
80
82
  expect(Usmu::S3::S3Configuration).to receive(:new).with({'bucket' => 'test'}).and_return(s3_configuration)
81
- plugin.command_deploy
83
+ plugin.command_deploy [], options
82
84
  expect(uploader.diffs).to eq(diffs)
83
85
  end
84
86
 
@@ -88,7 +90,7 @@ RSpec.describe Usmu::S3 do
88
90
  expect(Usmu::Deployment::DirectoryDiff).to receive(:new).with(empty_configuration, remote_files).and_return(differ)
89
91
  expect(Usmu::S3::Uploader).to receive(:new).with(empty_configuration, s3_configuration).and_return(uploader)
90
92
  expect(Usmu::S3::S3Configuration).to receive(:new).with({}).and_return(s3_configuration)
91
- plugin.command_deploy
93
+ plugin.command_deploy [], options
92
94
  end
93
95
 
94
96
  it 'logs progress' do
@@ -97,7 +99,7 @@ RSpec.describe Usmu::S3 do
97
99
  expect(Usmu::Deployment::DirectoryDiff).to receive(:new).with(configuration, remote_files).and_return(differ)
98
100
  expect(Usmu::S3::Uploader).to receive(:new).with(configuration, s3_configuration).and_return(uploader)
99
101
  expect(Usmu::S3::S3Configuration).to receive(:new).with({'bucket' => 'test'}).and_return(s3_configuration)
100
- plugin.command_deploy
102
+ plugin.command_deploy [], options
101
103
 
102
104
  # Discard the line from initialization
103
105
  @log_output.readline
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usmu-s3
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Scharley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-18 00:00:00.000000000 Z
11
+ date: 2015-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: usmu