dead_drop 0.4.0.0 → 0.4.1.0
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 +4 -4
- data/README.md +110 -0
- data/lib/dead_drop.rb +3 -1
- data/lib/dead_drop/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f61d0d3417d6a25aa211c401001a57644add9278
|
4
|
+
data.tar.gz: 53c387d6e9d87a8fe63c9c6d20fae643b6c89147
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efae49dd9f1f12f21563f3b60432bf884a6ee1fe5e6d841b315fe269f472f6aab4ca8570a1a9759216502b123ccaa5d6a403fca5b1bf78a8063fcab9f968ee01
|
7
|
+
data.tar.gz: dae89bf7cb59479969b43c030540d632a232195e4ee9e7c23d0daf1c5be01328a6b814db86f60b3fb19929b8d688ea208ea463b752a44ec2be2a5c88a5403e1f
|
data/README.md
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
DeadDrop [](http://badge.fury.io/rb/dead_drop)
|
2
|
+
========
|
3
|
+
|
4
|
+
DeadDrop is a Rails::Engine that allows you to drop content in an anonymous locker only accessible with a randomly generated token.
|
5
|
+
|
6
|
+
You can configure when the content should expire and limit the number of total accesses to the content.
|
7
|
+
|
8
|
+
DeadDrop can use any Cache::Store that supports the decrement method. This gem has been tested with :file_store, :memory_store, :mem_cache_store and :dalli_store.
|
9
|
+
|
10
|
+
|
11
|
+
Supported Ruby implementations
|
12
|
+
------------------------------
|
13
|
+
|
14
|
+
DeadDrop should work on:
|
15
|
+
|
16
|
+
* JRuby
|
17
|
+
* Ruby
|
18
|
+
* Rubinius
|
19
|
+
|
20
|
+
If you have problems, please enter an issue.
|
21
|
+
|
22
|
+
Installation and Configuration
|
23
|
+
------------------------------
|
24
|
+
|
25
|
+
Add `gem 'dead_drop'` to your Gemfile.
|
26
|
+
|
27
|
+
If you want to use the Controller option described below add this to your `routes.rb`:
|
28
|
+
```ruby
|
29
|
+
mount DeadDrop::Engine, at: "/dead_drop" # Or any mount point you like
|
30
|
+
```
|
31
|
+
|
32
|
+
You can configure this gem in `initializers/dead_drop.rb`. Here is an example with the default values:
|
33
|
+
```ruby
|
34
|
+
DeadDrop.setup do |config|
|
35
|
+
config.cache_store = :file_store, 'tmp/cache', { # Just configure any Cache::Store as you'd normally do.
|
36
|
+
namespace: 'ddrop',
|
37
|
+
compress: true,
|
38
|
+
compress_threshold: 2*1024 # 2K
|
39
|
+
}
|
40
|
+
config.default_access_limit = nil # How many accesses do you want to allow by default? (nil: no limit)
|
41
|
+
config.default_expiration = 24.hours # When should content expire by default? (nil: no limit)
|
42
|
+
config.token_length = 32
|
43
|
+
config.default_salt = '' # Optionally salt tokens before computing the SHA256 when creating the cache key.
|
44
|
+
config.cache_key_creation = :base64digest # When generating the key from the salt+token (SHA256), use this representation.
|
45
|
+
# When using :file_store on Windows it is recommended to use :hexdigest
|
46
|
+
# representation in order to avoid collisions due to the case insensitive FS.
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
50
|
+
If you want to use the same Cache::Store instance than the rest of your Rails app, just:
|
51
|
+
```ruby
|
52
|
+
DeadDrop.setup do |config|
|
53
|
+
config.cache_store = Rails.cache
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
|
58
|
+
Usage
|
59
|
+
-----
|
60
|
+
|
61
|
+
**Dropping**
|
62
|
+
```ruby
|
63
|
+
csv_content = "col1, col2\n 1.012, John\n 4.332, Mary"
|
64
|
+
token = DeadDrop.drop(csv_content, filename: "data.csv", expiration: 5.minutes, limit: 1)
|
65
|
+
```
|
66
|
+
*csv_content* has been saved in Cache::Store and a url friendly token has been returned.
|
67
|
+
This token can be used later to access programatically the resource or a url can be generated:
|
68
|
+
```ruby
|
69
|
+
url = dead_drop.pick_url(token) # The resource will be rendered when accessed unless it was dropped with
|
70
|
+
# the 'filename' option (useful for storing static html pages, for instance)
|
71
|
+
url = dead_drop.download_url(token, 'file.dat') # The resource will always be downloaded
|
72
|
+
```
|
73
|
+
This url is only useful if you have activated the custom controller in your `routes.rb` (described in installation section)
|
74
|
+
|
75
|
+
|
76
|
+
**Accessing Using Controller**
|
77
|
+
|
78
|
+
Just access to the url generated by above helpers which will show the content in the browser or download a file depending on the options you chose.
|
79
|
+
|
80
|
+
The url should look similar to `http://domain.com/dead_drop/3vTCwxjRC1oASZgY4MHwbWmQdL9l8Bwb`
|
81
|
+
|
82
|
+
|
83
|
+
**Accessing Programmatically**
|
84
|
+
```ruby
|
85
|
+
content = DeadDrop.pick(token)
|
86
|
+
```
|
87
|
+
If the token is still valid this hash will be returned: `{:resource=>content, :filename=>name, :mime_type=>mime}`. Else `nil` is returned.
|
88
|
+
|
89
|
+
If you just want to check the validity of the token without actually loading the resource:
|
90
|
+
```ruby
|
91
|
+
DeadDrop.exists?(token)
|
92
|
+
```
|
93
|
+
|
94
|
+
|
95
|
+
Helping Out
|
96
|
+
-----------
|
97
|
+
|
98
|
+
If you have a fix you wish to provide, please send a pull request on github.
|
99
|
+
|
100
|
+
|
101
|
+
Author
|
102
|
+
------
|
103
|
+
|
104
|
+
Miguel Canton Cortes, [GitHub](http://github.com/miwelc)
|
105
|
+
|
106
|
+
|
107
|
+
Copyright
|
108
|
+
---------
|
109
|
+
|
110
|
+
MIT Licensed
|
data/lib/dead_drop.rb
CHANGED
@@ -7,6 +7,7 @@ module DeadDrop
|
|
7
7
|
mattr_accessor :default_access_limit
|
8
8
|
mattr_accessor :default_expiration
|
9
9
|
mattr_accessor :default_salt
|
10
|
+
mattr_accessor :token_length
|
10
11
|
mattr_accessor :cache_key_creation
|
11
12
|
mattr_accessor :cache
|
12
13
|
|
@@ -18,6 +19,7 @@ module DeadDrop
|
|
18
19
|
self.default_salt = ''
|
19
20
|
self.default_access_limit = nil
|
20
21
|
self.default_expiration = 24.hours
|
22
|
+
self.token_length = 32
|
21
23
|
self.cache_key_creation = :base64digest
|
22
24
|
end
|
23
25
|
|
@@ -40,7 +42,7 @@ module DeadDrop
|
|
40
42
|
|
41
43
|
token = ""
|
42
44
|
loop do
|
43
|
-
token = SecureRandom.urlsafe_base64(
|
45
|
+
token = SecureRandom.urlsafe_base64((DeadDrop.token_length*3)/4)
|
44
46
|
break unless DeadDrop.exists?(token, salt: options[:salt])
|
45
47
|
end
|
46
48
|
|
data/lib/dead_drop/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dead_drop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miguel Canton Cortes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03
|
11
|
+
date: 2015-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -60,6 +60,7 @@ files:
|
|
60
60
|
- lib/tasks/dead_drop_tasks.rake
|
61
61
|
- MIT-LICENSE
|
62
62
|
- Rakefile
|
63
|
+
- README.md
|
63
64
|
- test/dead_drop_test.rb
|
64
65
|
- test/test_helper.rb
|
65
66
|
- test/dummy/config.ru
|