hydro 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +36 -0
- data/Rakefile +2 -0
- data/bin/evaporate +8 -0
- data/bin/precipitate +6 -0
- data/bin/precipitated +4 -0
- data/hydro.gemspec +26 -0
- data/lib/hydro/precipitator.rb +58 -0
- data/lib/hydro/rule.rb +22 -0
- data/lib/hydro/version.rb +3 -0
- data/lib/hydro.rb +11 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d7df05d40327ea1fa200dd9deecaf9f741f4b320
|
4
|
+
data.tar.gz: 9dd5896a15f7c8d78ea7e72b693439957c6cc37d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3469bee36b9ebb2fc23714955f6acaca5b1e6913c9a98098237683e34e688a8e6edc540d8754dc758274efbb731332e3d600dc83cd029a8f8aa171724cb42de5
|
7
|
+
data.tar.gz: 2e692f636a1eaa6fb3570df868a82a4bd16c0b654c03c931ec4f563568e66780c2d9698ed87e999c43bd68e486f4f22965f0f79dda0ff1a7afaa17276758e8f5
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 James Dabbs
|
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,36 @@
|
|
1
|
+
# Hydro
|
2
|
+
|
3
|
+
Packages a few simple utilities for cycling data up and down from the cloud
|
4
|
+
|
5
|
+
## Installation and Configuration
|
6
|
+
|
7
|
+
Install with `gem install hydro`
|
8
|
+
|
9
|
+
Expects a configuration file in `/etc/hydro/config.yml`
|
10
|
+
|
11
|
+
```yml
|
12
|
+
---
|
13
|
+
s3: {
|
14
|
+
id: ...,
|
15
|
+
key: ...,
|
16
|
+
bucket: ...
|
17
|
+
},
|
18
|
+
log: ...,
|
19
|
+
rules: [
|
20
|
+
{ to: ..., ext: ... }
|
21
|
+
]
|
22
|
+
```
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
`evaporate [file]` - uploads file to bucket
|
27
|
+
`precipitate` - downloads and sorts files from bucket
|
28
|
+
`precipitated [start|stop|...]` - daemon version of `precipitate`
|
29
|
+
|
30
|
+
## Contributing
|
31
|
+
|
32
|
+
1. Fork it ( https://github.com/[my-github-username]/hydro/fork )
|
33
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
34
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
35
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
36
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/evaporate
ADDED
data/bin/precipitate
ADDED
data/bin/precipitated
ADDED
data/hydro.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'hydro/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "hydro"
|
8
|
+
spec.version = Hydro::VERSION
|
9
|
+
spec.authors = ["James Dabbs"]
|
10
|
+
spec.email = ["jamesdabbs@gmail.com"]
|
11
|
+
spec.summary = %q{Simple utilities for cycling files through the cloud.}
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = "https://github.com/jamesdabbs/hydro"
|
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_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
|
24
|
+
spec.add_dependency "aws-sdk", "~> 2"
|
25
|
+
spec.add_dependency "daemons"
|
26
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Hydro
|
2
|
+
class Precipitator
|
3
|
+
def initialize
|
4
|
+
path = "/etc/hydro/config.yml"
|
5
|
+
raise "Could not find config file at #{path}" unless File.exists? path
|
6
|
+
conf = YAML.load_file path
|
7
|
+
|
8
|
+
@logger = Logger.new conf.fetch "log"
|
9
|
+
|
10
|
+
s3 = conf.fetch "s3"
|
11
|
+
@client = Aws::S3::Client.new(
|
12
|
+
region: 'us-east-1',
|
13
|
+
credentials: Aws::Credentials.new(s3.fetch("id"), s3.fetch("key"))
|
14
|
+
)
|
15
|
+
@bucket = Aws::S3::Bucket.new client: @client, name: s3.fetch("bucket")
|
16
|
+
|
17
|
+
@rules = conf.fetch("rules").map do |rule|
|
18
|
+
Rule.new to: rule.fetch("to"), ext: rule.fetch("ext")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def upload_file path
|
23
|
+
raise "Can't upload `#{path}`: file not found" unless File.exists? path
|
24
|
+
@logger.info "Uploading #{path} => #{@bucket.name}"
|
25
|
+
object = @bucket.object(File.basename path)
|
26
|
+
object.put body: File.open(path)
|
27
|
+
end
|
28
|
+
|
29
|
+
def download_file object, path
|
30
|
+
@logger.info "Downloading #{object.key} => #{path}"
|
31
|
+
File.open path, "w" do |f|
|
32
|
+
object.get { |chunk| f.write chunk }
|
33
|
+
end
|
34
|
+
object.delete
|
35
|
+
end
|
36
|
+
|
37
|
+
def download_by_rules
|
38
|
+
@bucket.objects.each do |object|
|
39
|
+
if rule = @rules.find { |r| r.matches? object }
|
40
|
+
download_file object, rule.location_for(object)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def poll frequency
|
46
|
+
@logger.info "Checking for new uploads every #{frequency} seconds"
|
47
|
+
|
48
|
+
at_exit do
|
49
|
+
@logger.info "Halting checks"
|
50
|
+
end
|
51
|
+
|
52
|
+
loop do
|
53
|
+
download_by_rules
|
54
|
+
sleep frequency
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/hydro/rule.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Hydro
|
2
|
+
class Rule
|
3
|
+
attr_reader :ext, :to
|
4
|
+
|
5
|
+
def initialize ext:, to:
|
6
|
+
@ext, @to = ext, to
|
7
|
+
FileUtils.mkdir_p @to
|
8
|
+
end
|
9
|
+
|
10
|
+
def matches? object
|
11
|
+
if ext
|
12
|
+
object.key.end_with? ext
|
13
|
+
else
|
14
|
+
true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def location_for object
|
19
|
+
"#{to}/#{object.key}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/hydro.rb
ADDED
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hydro
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Dabbs
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: aws-sdk
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: daemons
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Simple utilities for cycling files through the cloud.
|
70
|
+
email:
|
71
|
+
- jamesdabbs@gmail.com
|
72
|
+
executables:
|
73
|
+
- evaporate
|
74
|
+
- precipitate
|
75
|
+
- precipitated
|
76
|
+
extensions: []
|
77
|
+
extra_rdoc_files: []
|
78
|
+
files:
|
79
|
+
- ".gitignore"
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/evaporate
|
85
|
+
- bin/precipitate
|
86
|
+
- bin/precipitated
|
87
|
+
- hydro.gemspec
|
88
|
+
- lib/hydro.rb
|
89
|
+
- lib/hydro/precipitator.rb
|
90
|
+
- lib/hydro/rule.rb
|
91
|
+
- lib/hydro/version.rb
|
92
|
+
homepage: https://github.com/jamesdabbs/hydro
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.4.5
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: Simple utilities for cycling files through the cloud.
|
116
|
+
test_files: []
|