floccus 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +58 -0
- data/Rakefile +2 -0
- data/bin/floc +15 -0
- data/floccus.gemspec +23 -0
- data/lib/floccus.rb +12 -0
- data/lib/floccus/cloud.rb +35 -0
- data/lib/floccus/commands.rb +3 -0
- data/lib/floccus/commands/put.rb +9 -0
- data/lib/floccus/filename.rb +14 -0
- data/lib/floccus/put_helper.rb +51 -0
- metadata +108 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Owen Bossola
|
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,58 @@
|
|
1
|
+
# Floccus
|
2
|
+
|
3
|
+
![alt text](http://upload.wikimedia.org/wikipedia/commons/e/e3/Clouds_H2.svg "Floccus")
|
4
|
+
|
5
|
+
A sane and tidy way to manage files in the cloud.
|
6
|
+
|
7
|
+
Floccus prefixes filenames with a unique hash based on the contents of the file, then drops them at your cloud root where they're publicly accessible.
|
8
|
+
|
9
|
+
This removes the need to keep track of filenames, paths, or concerns if a certain file is actually in your cloud but not readily discoverable. Since the hashing mechanism is standard, it's easy to query the cloud for an existing file, even if named differently, if you have a local copy.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
$ gem install floccus
|
14
|
+
|
15
|
+
## Setup
|
16
|
+
|
17
|
+
Create the file ```~/.floccfg``` with your AWS keys and default bucket.
|
18
|
+
|
19
|
+
# Floccfg
|
20
|
+
access_key_id: 'aws-key' # required, your AWS Access ID
|
21
|
+
secret_access_key: 'aws-secret' # required, your AWS Secret Key
|
22
|
+
default_bucket: 'default-bucket' # required, the bucket to place files in
|
23
|
+
domain: 'cdn.my-cloud.com' # optional, returns the file hosted at this domain root, instead of S3
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
### CLI
|
28
|
+
|
29
|
+
floc image.jpg
|
30
|
+
-> public URL: http://cdn.my-cloud.com/24894781b632f6b3e805dae60e2d8c46-image.jpg
|
31
|
+
|
32
|
+
The public URL is also copied to your clipboard.
|
33
|
+
|
34
|
+
## Roadmap
|
35
|
+
|
36
|
+
* Tests, Documentation
|
37
|
+
* Usage as a library for applications
|
38
|
+
* Expose an `ls` feature for checking for an existing file
|
39
|
+
* Installation with setup for .floccfg
|
40
|
+
* Multiple cloud backends (right now only S3 is supported)
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
1. Fork it
|
45
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
46
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
47
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
48
|
+
5. Create new Pull Request
|
49
|
+
|
50
|
+
## About
|
51
|
+
|
52
|
+
'Floccus' is a type of cirrus cloud that resembles the pattern above: http://en.wikipedia.org/wiki/Cirrus_floccus. It's a cloud that rises high in the atmosphere, hence the high level API.
|
53
|
+
|
54
|
+
## License
|
55
|
+
|
56
|
+
MIT License
|
57
|
+
|
58
|
+
Copyright (C) 2013 Owen Bossola, http://owenbossola.com
|
data/Rakefile
ADDED
data/bin/floc
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.push File.expand_path("../../lib", __FILE__)
|
4
|
+
require 'floccus'
|
5
|
+
|
6
|
+
HighLine.track_eof = false
|
7
|
+
|
8
|
+
program :version, Floccus::VERSION
|
9
|
+
program :description, 'A sane and tidy way to manage files in the cloud.'
|
10
|
+
|
11
|
+
program :help, 'Authors', 'Owen Bossola <owen@bosso.la>'
|
12
|
+
program :help, 'Website', 'http://owenbossola.com/floccus'
|
13
|
+
program :help_formatter, :compact
|
14
|
+
|
15
|
+
default_command :put
|
data/floccus.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'floccus'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.authors = ["Owen Bossola"]
|
8
|
+
gem.email = ["owen@bosso.la"]
|
9
|
+
gem.description = %q{A sane and tidy way to manage files in the cloud.}
|
10
|
+
gem.summary = %q{Remove the need to remember filenames, paths, or buckets. All that's left is files and URLs.}
|
11
|
+
gem.homepage = "http://owenbossola.com/floccus"
|
12
|
+
|
13
|
+
gem.add_dependency 'commander', '~> 4.1.3'
|
14
|
+
gem.add_dependency 'aws-sdk', '~> 1.8.1.1'
|
15
|
+
gem.add_dependency 'ruby-progressbar', '~> 1.0.2'
|
16
|
+
|
17
|
+
gem.files = `git ls-files`.split($\)
|
18
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
19
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
20
|
+
gem.name = "floccus"
|
21
|
+
gem.require_paths = ["lib"]
|
22
|
+
gem.version = Floccus::VERSION
|
23
|
+
end
|
data/lib/floccus.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'commander/import'
|
2
|
+
require 'aws-sdk'
|
3
|
+
require 'digest/md5'
|
4
|
+
require 'ruby-progressbar'
|
5
|
+
require 'floccus/filename'
|
6
|
+
require 'floccus/cloud'
|
7
|
+
require 'floccus/put_helper'
|
8
|
+
require 'floccus/commands'
|
9
|
+
|
10
|
+
module Floccus
|
11
|
+
VERSION = "0.0.1"
|
12
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Floccus
|
2
|
+
class Cloud
|
3
|
+
|
4
|
+
CONFIG_PATH = "#{ENV['HOME']}/.floccfg"
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
config = YAML.load(File.read(CONFIG_PATH))
|
8
|
+
|
9
|
+
AWS.config(
|
10
|
+
:access_key_id => config["access_key_id"],
|
11
|
+
:secret_access_key => config["secret_access_key"]
|
12
|
+
)
|
13
|
+
@default_bucket = config["default_bucket"]
|
14
|
+
@domain = config["domain"]
|
15
|
+
|
16
|
+
@s3 = AWS::S3.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def bucket
|
20
|
+
@default_bucket
|
21
|
+
end
|
22
|
+
|
23
|
+
def s3
|
24
|
+
@s3
|
25
|
+
end
|
26
|
+
|
27
|
+
def use_domain?
|
28
|
+
@domain
|
29
|
+
end
|
30
|
+
|
31
|
+
def domain
|
32
|
+
@domain
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Floccus
|
2
|
+
class Filename
|
3
|
+
# Generate a hashed filename based on the contents
|
4
|
+
#
|
5
|
+
# Returns the hash followed by the filename
|
6
|
+
def self.generate(filename)
|
7
|
+
file_path = File.expand_path(filename)
|
8
|
+
contents = File.read(file_path)
|
9
|
+
hash = Digest::MD5.hexdigest(contents)
|
10
|
+
|
11
|
+
"#{hash}-#{filename}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Floccus
|
2
|
+
class PutHelper
|
3
|
+
|
4
|
+
KB = 1024
|
5
|
+
|
6
|
+
# Setup
|
7
|
+
#
|
8
|
+
def initialize(*args)
|
9
|
+
@filename = args[0]
|
10
|
+
@hashed_filename = Floccus::Filename.generate(@filename)
|
11
|
+
@cloud = Floccus::Cloud.new
|
12
|
+
@s3 = @cloud.s3
|
13
|
+
end
|
14
|
+
|
15
|
+
# Run the full command
|
16
|
+
#
|
17
|
+
def run
|
18
|
+
file = open(@filename)
|
19
|
+
|
20
|
+
# Instantiate a Progress Bar
|
21
|
+
total_blocks = (file.size / KB).to_i + 2
|
22
|
+
progressbar = ProgressBar.create total: total_blocks
|
23
|
+
|
24
|
+
# Create the object
|
25
|
+
object = @s3.buckets[@cloud.bucket].objects[@hashed_filename]
|
26
|
+
|
27
|
+
# Write the file
|
28
|
+
object.write(content_length: file.size, acl: :public_read) do |buffer, bytes|
|
29
|
+
buffer.write(file.read(bytes))
|
30
|
+
|
31
|
+
progressbar.increment
|
32
|
+
end
|
33
|
+
|
34
|
+
file.close
|
35
|
+
|
36
|
+
public_url = if @cloud.use_domain?
|
37
|
+
obj = object.public_url
|
38
|
+
obj.scheme = "http"
|
39
|
+
obj.host = @cloud.domain
|
40
|
+
obj.path = obj.path.gsub("/#{@cloud.bucket}", "")
|
41
|
+
obj
|
42
|
+
else
|
43
|
+
object.public_url
|
44
|
+
end
|
45
|
+
|
46
|
+
# Echo the results
|
47
|
+
system "echo #{public_url} | pbcopy"
|
48
|
+
puts "---> #{public_url}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: floccus
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Owen Bossola
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: commander
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 4.1.3
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 4.1.3
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: aws-sdk
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.8.1.1
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.8.1.1
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: ruby-progressbar
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.0.2
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.0.2
|
62
|
+
description: A sane and tidy way to manage files in the cloud.
|
63
|
+
email:
|
64
|
+
- owen@bosso.la
|
65
|
+
executables:
|
66
|
+
- floc
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- .gitignore
|
71
|
+
- Gemfile
|
72
|
+
- LICENSE
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- bin/floc
|
76
|
+
- floccus.gemspec
|
77
|
+
- lib/floccus.rb
|
78
|
+
- lib/floccus/cloud.rb
|
79
|
+
- lib/floccus/commands.rb
|
80
|
+
- lib/floccus/commands/put.rb
|
81
|
+
- lib/floccus/filename.rb
|
82
|
+
- lib/floccus/put_helper.rb
|
83
|
+
homepage: http://owenbossola.com/floccus
|
84
|
+
licenses: []
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ! '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 1.8.25
|
104
|
+
signing_key:
|
105
|
+
specification_version: 3
|
106
|
+
summary: Remove the need to remember filenames, paths, or buckets. All that's left
|
107
|
+
is files and URLs.
|
108
|
+
test_files: []
|