sink3 0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1ef001742f3059209bd54b3778591bd9a292d443
4
+ data.tar.gz: e6c713ef21bba1549c35aae6d28c94e819b960ae
5
+ SHA512:
6
+ metadata.gz: 47c61011df93d6ab1d7a89ef341d7683d25f07ce446fd1a3fe624b6865f1d448464fc04bf03c3b5f82a3f178d73b58e77a838d46a435d78b736d6594477c8245
7
+ data.tar.gz: a813ea97a399779eb60cbf0beeba3340c337beb6f3cc939a88d0a3738a00b8d0f4525290badcb35513c6da855cfc8cb4b5292f6a6e9d6b7005af0849fd61878a
data/.gitignore ADDED
@@ -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/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sink3.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Fabrizio Regini
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.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Sink3
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'sink3'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install sink3
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/sink3/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/sink3 ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.expand_path('../../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require 'sink3'
7
+
8
+ # Exit cleanly from an early interrupt
9
+ Signal.trap("INT") { exit 1 }
10
+
11
+ # Split arguments by "--" if its there, we'll recombine them later
12
+ argv = ARGV.dup
13
+ argv_extra = []
14
+ if idx = argv.index("--")
15
+ argv_extra = argv.slice(idx+1, argv.length-2)
16
+ argv = argv.slice(0, idx)
17
+ end
18
+
19
+ # Fast path the version of Vagrant
20
+ if argv.include?("-v") || argv.include?("--version")
21
+ puts "Sink3 #{Sink3::VERSION}"
22
+ exit 0
23
+ end
24
+
25
+ Sink3::Main.start(ARGV)
data/lib/sink3/main.rb ADDED
@@ -0,0 +1,46 @@
1
+ require 'thor'
2
+ require 'dotenv'
3
+ require 'aws-sdk'
4
+
5
+ lib = File.expand_path('../..', __FILE__)
6
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
7
+
8
+ require 'sink3/path_crawler'
9
+
10
+ module Sink3
11
+ class Main < Thor
12
+ option :delete, type: :boolean
13
+
14
+ # option :path, :required => true
15
+ desc "Send file to S3", "Send files to S3 in write only mode"
16
+
17
+ def send(path)
18
+ configure
19
+ path = Pathname.new(path)
20
+ raise "specified path does not exist" unless path.exist?
21
+
22
+ # overwrite hostname if configured
23
+ Dotenv.overload('~/.sink3cfg')
24
+ validate_env
25
+
26
+ prefix = path.realdirpath.basename
27
+ Sink3::PathCrawler.new(path, prefix).start
28
+ end
29
+
30
+ private
31
+
32
+ def configure
33
+ ENV['HOSTNAME'] = `hostname`.strip
34
+
35
+ Sink3.configure do |config|
36
+ config.delete_after_upload = options[:delete]
37
+ end
38
+ end
39
+
40
+ def validate_env
41
+ %w(REGION ACCESS_KEY SECRET_KEY).each do |key|
42
+ raise "missing #{key}" if ENV[key].to_s == ''
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,70 @@
1
+ require 'pathname'
2
+
3
+ module Sink3
4
+ class PathCrawler
5
+ def initialize(path, prefix, parent=nil)
6
+ @parent = parent
7
+ @prefix = prefix
8
+
9
+ if @parent.nil?
10
+ @path = Pathname.new(path)
11
+ else
12
+ @path = parent.join(path)
13
+ end
14
+
15
+ # If path is '.' then just skip the prefix
16
+ if path == prefix
17
+ @prefix = nil
18
+ end
19
+ end
20
+
21
+ def start
22
+ raise "Path does not exist" unless @path.exist?
23
+ if @path.directory?
24
+ @path.opendir.each do |file|
25
+ next if file.start_with? '.'
26
+ PathCrawler.new(file, @prefix, @path).start
27
+ end
28
+ else
29
+ send_to_remote
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def s3
36
+ @s3 ||= AWS::S3.new(
37
+ :access_key_id => ENV['ACCESS_KEY'],
38
+ :secret_access_key => ENV['SECRET_KEY'],
39
+ :region => ENV['REGION']
40
+ )
41
+ end
42
+
43
+ def bucket
44
+ s3.buckets[ENV['BUCKET']]
45
+ end
46
+
47
+ def send_to_remote
48
+ remote_path = "#{ENV['HOSTNAME'].strip}/#{formatted_date}/#{prefix_and_path}"
49
+ remote_file = bucket.objects[remote_path]
50
+ remote_file.write(@path)
51
+
52
+ if Sink3.config.delete_after_upload?
53
+ FileUtils.rm @path
54
+ end
55
+ end
56
+
57
+ def formatted_date
58
+ Time.now.strftime "%Y-%m-%d"
59
+ end
60
+
61
+ def prefix_and_path
62
+ if @prefix.nil?
63
+ "#{@path}"
64
+ else
65
+ "#{@prefix}/#{@path}"
66
+ end
67
+ end
68
+
69
+ end
70
+ end
@@ -0,0 +1,3 @@
1
+ module Sink3
2
+ VERSION = "0.0.1"
3
+ end
data/lib/sink3.rb ADDED
@@ -0,0 +1,25 @@
1
+ require "sink3/version"
2
+ require 'sink3/main'
3
+ require 'sink3/path_crawler'
4
+
5
+ module Sink3
6
+ # Your code goes here...
7
+ class << self
8
+ attr_accessor :config
9
+ end
10
+
11
+ def self.configure
12
+ self.config ||= Configuration.new
13
+ yield config
14
+ end
15
+
16
+ class Configuration
17
+ attr_accessor :delete_after_upload
18
+
19
+ def delete_after_upload
20
+ !!@delete_after_upload
21
+ end
22
+ alias_method :delete_after_upload?, :delete_after_upload
23
+
24
+ end
25
+ end
data/sink3.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sink3/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sink3"
8
+ spec.version = Sink3::VERSION
9
+ spec.authors = ["Fabrizio Regini"]
10
+ spec.email = ["freegenie@gmail.com"]
11
+ spec.summary = %q{S3 backup designed for servers}
12
+ spec.description = %q{Sink3 is an S3 backup designed to work with write-only keys.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "aws-sdk", "< 2.0"
22
+ spec.add_dependency "dotenv"
23
+ spec.add_dependency "thor"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.5"
26
+ spec.add_development_dependency "rake"
27
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sink3::PathCrawler do
4
+
5
+ let(:test_path) {
6
+ File.expand_path('../../support/test_path')
7
+ }
8
+
9
+ it 'should crawl directories'
10
+ it 'should set the correct remote_path'
11
+ end
@@ -0,0 +1,94 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, consider making
10
+ # a separate helper file that requires the additional dependencies and performs
11
+ # the additional setup, and require it from the spec files that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+ lib = File.expand_path('../lib', __FILE__)
18
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
19
+
20
+ require 'sink3'
21
+
22
+ RSpec.configure do |config|
23
+ # rspec-expectations config goes here. You can use an alternate
24
+ # assertion/expectation library such as wrong or the stdlib/minitest
25
+ # assertions if you prefer.
26
+ config.expect_with :rspec do |expectations|
27
+ # This option will default to `true` in RSpec 4. It makes the `description`
28
+ # and `failure_message` of custom matchers include text for helper methods
29
+ # defined using `chain`, e.g.:
30
+ # be_bigger_than(2).and_smaller_than(4).description
31
+ # # => "be bigger than 2 and smaller than 4"
32
+ # ...rather than:
33
+ # # => "be bigger than 2"
34
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
35
+ end
36
+
37
+ # rspec-mocks config goes here. You can use an alternate test double
38
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
39
+ config.mock_with :rspec do |mocks|
40
+ # Prevents you from mocking or stubbing a method that does not exist on
41
+ # a real object. This is generally recommended, and will default to
42
+ # `true` in RSpec 4.
43
+ mocks.verify_partial_doubles = true
44
+ end
45
+
46
+ # The settings below are suggested to provide a good initial experience
47
+ # with RSpec, but feel free to customize to your heart's content.
48
+ =begin
49
+ # These two settings work together to allow you to limit a spec run
50
+ # to individual examples or groups you care about by tagging them with
51
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
52
+ # get run.
53
+ config.filter_run :focus
54
+ config.run_all_when_everything_filtered = true
55
+
56
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
57
+ # For more details, see:
58
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
59
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
60
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
61
+ config.disable_monkey_patching!
62
+
63
+ # This setting enables warnings. It's recommended, but in some cases may
64
+ # be too noisy due to issues in dependencies.
65
+ config.warnings = true
66
+
67
+ # Many RSpec users commonly either run the entire suite or an individual
68
+ # file, and it's useful to allow more verbose output when running an
69
+ # individual spec file.
70
+ if config.files_to_run.one?
71
+ # Use the documentation formatter for detailed output,
72
+ # unless a formatter has already been configured
73
+ # (e.g. via a command-line flag).
74
+ config.default_formatter = 'doc'
75
+ end
76
+
77
+ # Print the 10 slowest examples and example groups at the
78
+ # end of the spec run, to help surface which specs are running
79
+ # particularly slow.
80
+ config.profile_examples = 10
81
+
82
+ # Run specs in random order to surface order dependencies. If you find an
83
+ # order dependency and want to debug it, you can fix the order by providing
84
+ # the seed, which is printed after each run.
85
+ # --seed 1234
86
+ config.order = :random
87
+
88
+ # Seed global randomization in this process using the `--seed` CLI option.
89
+ # Setting this allows you to use `--seed` to deterministically reproduce
90
+ # test failures related to randomization by passing the same `--seed` value
91
+ # as the one that triggered the failure.
92
+ Kernel.srand config.seed
93
+ =end
94
+ end
@@ -0,0 +1,2 @@
1
+
2
+ Keep this file
@@ -0,0 +1 @@
1
+ Keep this file
@@ -0,0 +1 @@
1
+ This is a sample file
@@ -0,0 +1 @@
1
+ keep this file
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sink3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Fabrizio Regini
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sdk
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - <
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - <
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dotenv
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Sink3 is an S3 backup designed to work with write-only keys.
84
+ email:
85
+ - freegenie@gmail.com
86
+ executables:
87
+ - sink3
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .gitignore
92
+ - .rspec
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/sink3
98
+ - lib/sink3.rb
99
+ - lib/sink3/main.rb
100
+ - lib/sink3/path_crawler.rb
101
+ - lib/sink3/version.rb
102
+ - sink3.gemspec
103
+ - spec/lib/sink3/path_crawler_spec.rb
104
+ - spec/spec_helper.rb
105
+ - spec/support/testpath/.hiddendir/.gitkeep
106
+ - spec/support/testpath/.hiddenfile
107
+ - spec/support/testpath/dir1/file.txt
108
+ - spec/support/testpath/dir2/.gitkeep
109
+ homepage: ''
110
+ licenses:
111
+ - MIT
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.2.1
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: S3 backup designed for servers
133
+ test_files:
134
+ - spec/lib/sink3/path_crawler_spec.rb
135
+ - spec/spec_helper.rb
136
+ - spec/support/testpath/.hiddendir/.gitkeep
137
+ - spec/support/testpath/.hiddenfile
138
+ - spec/support/testpath/dir1/file.txt
139
+ - spec/support/testpath/dir2/.gitkeep