s3rsync 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MDUyOTRiOWFhOWJjNmY4ZjVkZWI0NzFkY2IwNWFlM2EzNjU5Yzk2Zg==
4
+ YjEyMWZhMDA1MDdmNTRkYWI4MjllMjhkMmQxZmFkMGRjMzVmOWQ1ZQ==
5
5
  data.tar.gz: !binary |-
6
- MTg4ZjgzMDA0YzgxMDM5NmQ4YjIzZDdhMmRhZmYzNzRmYjhjMGY5OA==
6
+ OTcyYzAyMjg1YWRhYTFhYzI3NjYwMTdjNmRiMTA4YTAyMjVlN2M5Zg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZTM3OGY2NWQzMTVmM2RjN2U2NGZhYmM3Njc1YjIwODM4ZGI4MmNlZDc4YTQw
10
- YWVlMjBlOTcwYjdhYzI1NzY3ZDY4OGQ1YWRkZTRiMzI0NDYxNDQ2OWY2YmM4
11
- NDEwMGZiNDQ2OGFjN2I5NTE2MTc4Mjg1ZWExYzg4NDVhY2QwMWM=
9
+ MzM5OGE1MGRiYjhkYjZhOWU4OTk2MGE1MDBlMWU5YWM5ZTNkNTg3NmQzM2E3
10
+ OGM5OWZlZGIxN2U3ZGE4ZGNkN2FiNGI5ZmZiMjJhMjRkNzM5NjBmZWUwMzMz
11
+ NTUwZTc1NjU0NWVmY2M0MjYzYTc5ZGZiYzAwYmY3ODkxMzY1NDM=
12
12
  data.tar.gz: !binary |-
13
- YmIzZGEwMzZiZmU1NmE4ZmMzNTBmMWE4ZWIxYjFjZWE3MTg3ZmQ1YTBhNjhk
14
- ZGJlOGZkMjkxM2EzYzU5ZWM5YTNlNmMwNjBjNTNhMzJkNDU3N2RlNjA0NWRl
15
- M2UyZmEzOTEwOTlmZjVlMmVhMTAyNjNlNGU2ZjcyZWY0YzZiZWU=
13
+ YzZjMmFhNTE5OTI2NzdlNjdkMjg4MTZhMTcxZDhmNzFlMTYxZWQ3OGNmODc3
14
+ M2VhZTgwYTUyOGY4ZGU0MzI0NzMwYTdhODcxNGM1NzIxNmMxMWJkNGE1MDk3
15
+ ODk3YmQzM2FmMDA1MGE1YTllY2M5MWY4NTY4MTI1OWM3MTRkYTU=
data/README.md CHANGED
@@ -8,12 +8,12 @@ s3rsync
8
8
  [travis]: http://travis-ci.org/idevops/s3rsync
9
9
  [coveralls]: https://coveralls.io/r/idevops/s3rsync
10
10
 
11
- Wrapper gem to sync files with s3cmd tool.
11
+ Wrapper gem used to sync files with s3cmd tool.
12
12
  Remote update protocol between local set of files and S3 storage.
13
13
 
14
14
  Prerequisites
15
15
  -------------
16
- Omnibus is designed to run with a minimal set of prerequisites. You will need the following:
16
+ You will need the following:
17
17
 
18
18
  - Ruby 1.9+
19
19
  - Bundler
@@ -35,14 +35,17 @@ Or install it yourself as:
35
35
 
36
36
  ## Usage
37
37
 
38
- $ s3rsync help [COMMAND] # Describe available commands or one specific command
39
- $ s3rsync upload -c, --config-path=CONFIG_PATH -d, --dir=DIR # Sync local dir to s3 location
40
- $ s3rsync download -c, --config-path=CONFIG_PATH -d, --dir=DIR # Sync from s3 location to local dir
38
+ $ s3rsync help [COMMAND] # Describe expanded available commands or one specific command
39
+ $ s3rsync upload -c, --config-path=CONFIG_PATH -p, --path=PATH # Sync local path to s3 location
40
+ $ s3rsync download -c, --config-path=CONFIG_PATH -p, --path=PATH # Sync from s3 to local path
41
+
42
+ ## Configuration
41
43
 
44
+ json config [s3rsync.json.example](https://github.com/idevops/s3rsync/blob/master/s3rsync.json.example)
42
45
 
43
46
  ## Contributing
44
47
 
45
- 1. Fork it ( http://github.com/<my-github-username>/s3rsync/fork )
48
+ 1. [Fork it]( https://github.com/idevops/s3rsync/fork )
46
49
  2. Create your feature branch (`git checkout -b my-new-feature`)
47
50
  3. Commit your changes (`git commit -am 'Add some feature'`)
48
51
  4. Push to the branch (`git push origin my-new-feature`)
data/lib/s3rsync/base.rb CHANGED
@@ -23,14 +23,9 @@ module S3Rsync
23
23
  statsd
24
24
  end
25
25
 
26
- def error_exit(msg)
26
+ def error_exit(msg, exit_code = 1)
27
27
  @log.error msg
28
- return 1
29
- end
30
-
31
- def error_exit(msg)
32
- @log.error msg
33
- return 1
28
+ exit exit_code
34
29
  end
35
30
 
36
31
  def pass_cli(cmd, valid_out_pattern = nil)
data/lib/s3rsync/cli.rb CHANGED
@@ -2,13 +2,14 @@ require 'thor'
2
2
 
3
3
  module S3Rsync
4
4
  class CLI < Thor
5
-
5
+
6
6
  def self.common_opts
7
7
  method_option :path, :aliases => "-p", :required => true
8
8
  method_option :'config-path', :aliases => "-c", :required => true
9
9
  method_option :'s3-prefix', :aliases => "-s", :default => 's3rsync'
10
10
  method_option :'log-path', :aliases => "-l"
11
11
  method_option :'dry-run', :aliases => "-d", :type => :boolean, :default => false
12
+ method_option :'make-public', :aliases => "-m", :type => :boolean, :default => false
12
13
  end
13
14
 
14
15
  desc "upload", "sync from local to s3"
data/lib/s3rsync/sync.rb CHANGED
@@ -14,14 +14,13 @@ module S3Rsync
14
14
  @params[:s3_prefix] = opt['s3-prefix']
15
15
  @params[:config_path] = opt['config-path']
16
16
  @params[:s3cmd_conf] = @params[:config_path].sub('.json', '_s3rsync.conf')
17
+ @params[:dry_run] = opt['dry-run']
18
+ @params[:make_public] = opt['make-public']
17
19
  @log.debug "@params[:config_path]: #{@params[:config_path]}"
18
20
  begin
19
21
  conf = JSON.parse File.read(@params[:config_path])
20
22
  rescue Exception => e
21
- mgs = "ERROR: opening or parsing config file failed: #{e.inspect}"
22
- @log.error mgs
23
- raise mgs
24
- exit 1
23
+ error_exit "ERROR: opening or parsing config file failed: #{e.inspect}"
25
24
  end
26
25
 
27
26
  @log.debug "conf: #{conf}"
@@ -35,7 +34,7 @@ module S3Rsync
35
34
  @log.debug "@statsd: #{@statsd.inspect}"
36
35
 
37
36
  init_s3cmd_conf
38
- @s3cmd = "s3cmd -c #{@params[:s3cmd_conf]}"
37
+ @s3cmd = "s3cmd"
39
38
  end
40
39
 
41
40
  def get_lock(name = 'common')
@@ -60,8 +59,7 @@ module S3Rsync
60
59
  @log.debug "rendered_template: #{rendered_template}"
61
60
  File.write @params[:s3cmd_conf], rendered_template
62
61
  rescue Exception => e
63
- @log.error "generating s3cmd config failed: #{e.inspect}"
64
- exit 1
62
+ error_exit "generating s3cmd config failed: #{e.inspect}"
65
63
  end
66
64
  @log.info "Dynamic s3cfg generated: #{@params[:s3cmd_conf]}"
67
65
  end
@@ -94,10 +92,17 @@ module S3Rsync
94
92
  sync_output = 1
95
93
  begin
96
94
  lockfile.lock
97
- cmd = "#{@s3cmd} sync #{sync_locations}"
95
+ s3cmd_args = {}
96
+ s3cmd_args['-c'] = @params[:s3cmd_conf]
97
+ s3cmd_args['--dry-run'] = '' if @params[:dry_run]
98
+ s3cmd_args['--acl-public'] = '' if @params[:make_public]
99
+ @log.debug "s3cmd_args: #{s3cmd_args.inspect}"
100
+ compiled_args = s3cmd_args.to_a.flatten.reject { |v| v.empty? }.join(' ')
101
+ @log.debug "compiled_args: #{compiled_args.inspect}"
102
+ cmd = "#{@s3cmd} #{compiled_args} sync #{sync_locations}"
98
103
  @log.debug "cmd: #{cmd}"
99
104
  sync_output = pass_cli cmd
100
- @log.debug "sync_output: #{sync_output}"
105
+ @log.debug "sync_output: #{sync_output.inspect}"
101
106
  rescue Exception => e
102
107
  sync_output = 1
103
108
  @log.error "something wrong while trying to run the sync: #{e.inspect}"
@@ -1,3 +1,3 @@
1
1
  module S3rsync
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
@@ -0,0 +1,7 @@
1
+ {
2
+ "env.static.s3.key.user": "ACCESS_KEY",
3
+ "env.static.s3.key.secret": "SECRET_KEY",
4
+ "env.static.s3.bucket": "S3_BUCKET_NAME",
5
+ "env.metrics.host": "STATSD_HOST",
6
+ "env.metrics.port": 8125
7
+ }
data/spec/sync_spec.rb CHANGED
@@ -10,6 +10,8 @@ describe S3Rsync::Sync do
10
10
  'path' => '/parent_test_dir/test_dir',
11
11
  's3-prefix' => 's3rsync',
12
12
  'config-path' => 'test_json_conf_path.json',
13
+ 'dry-run' => false,
14
+ 'make-public' => false,
13
15
  }
14
16
  }
15
17
 
@@ -23,6 +25,7 @@ describe S3Rsync::Sync do
23
25
 
24
26
  let(:s3_conf_path) { opt['config-path'].sub('.json', '_s3rsync.conf') }
25
27
  let(:base_sync_path) { opt['path'].split('/').last }
28
+ let(:common_args) { ['-c', s3_conf_path].join(' ') }
26
29
 
27
30
  before do
28
31
  allow(File).to receive(:read).and_return(nil)
@@ -45,7 +48,7 @@ describe S3Rsync::Sync do
45
48
  end
46
49
 
47
50
  it "uploads dir" do
48
- cmd = "s3cmd -c #{s3_conf_path} sync #{opt['path']}/ s3://#{json_conf['env.static.s3.bucket']}/#{opt['s3-prefix']}/#{base_sync_path}/"
51
+ cmd = "s3cmd #{common_args} sync #{opt['path']}/ s3://#{json_conf['env.static.s3.bucket']}/#{opt['s3-prefix']}/#{base_sync_path}/"
49
52
  allow_any_instance_of(S3Rsync::Sync).to receive(:pass_cli).with(cmd).and_return('Success')
50
53
 
51
54
  sync = S3Rsync::Sync.new(opt)
@@ -53,7 +56,7 @@ describe S3Rsync::Sync do
53
56
  end
54
57
 
55
58
  it "downloads dir" do
56
- cmd = "s3cmd -c #{s3_conf_path} sync s3://#{json_conf['env.static.s3.bucket']}/#{opt['s3-prefix']}/#{base_sync_path}/ #{opt['path']}/"
59
+ cmd = "s3cmd #{common_args} sync s3://#{json_conf['env.static.s3.bucket']}/#{opt['s3-prefix']}/#{base_sync_path}/ #{opt['path']}/"
57
60
  allow_any_instance_of(S3Rsync::Sync).to receive(:pass_cli).with(cmd).and_return('Success')
58
61
 
59
62
  sync = S3Rsync::Sync.new(opt)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: s3rsync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - idevops
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-04 00:00:00.000000000 Z
11
+ date: 2014-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -203,6 +203,7 @@ files:
203
203
  - lib/s3rsync/templates/s3cmd_conf.erb
204
204
  - lib/s3rsync/version.rb
205
205
  - s3rsync.gemspec
206
+ - s3rsync.json.example
206
207
  - spec/spec_helper.rb
207
208
  - spec/sync_spec.rb
208
209
  homepage: ''