dragonfly-azure_data_store 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +104 -0
- data/Guardfile +16 -0
- data/README.md +58 -17
- data/dragonfly-azure_data_store.gemspec +2 -0
- data/lib/dragonfly/azure_data_store/version.rb +1 -1
- data/lib/dragonfly/azure_data_store.rb +25 -10
- metadata +32 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d2024967b29c0e312ad70474d518ceb9b6ac941
|
4
|
+
data.tar.gz: 69f109e7bee50858b5cd899255b5bc660c1f4f9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23268df03c06d76312ae8bd52a910080cbe53a3d452878d21a4c29bd237c829e4962e7feda5a7d02c65ebcf808ea6b104cb9ad21ee4565117b428d5a417fb696
|
7
|
+
data.tar.gz: 6e2c2eed209c11d5d945296bacb21da78256027295d557b920e9b2b6d773ff0da5a5a3b11314ac36fbbeaea2bdb8c6cb0aeacc2f9e72ec519a572cb630773368
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
dragonfly-azure_data_store (0.0.1)
|
5
|
+
azure-storage-blob (~> 1.0)
|
6
|
+
dragonfly (~> 1.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.5.2)
|
12
|
+
public_suffix (>= 2.0.2, < 4.0)
|
13
|
+
azure-core (0.1.14)
|
14
|
+
faraday (~> 0.9)
|
15
|
+
faraday_middleware (~> 0.10)
|
16
|
+
nokogiri (~> 1.6)
|
17
|
+
azure-storage-blob (1.0.1)
|
18
|
+
azure-core (~> 0.1.13)
|
19
|
+
azure-storage-common (~> 1.0)
|
20
|
+
nokogiri (~> 1.6, >= 1.6.8)
|
21
|
+
azure-storage-common (1.0.1)
|
22
|
+
azure-core (~> 0.1.13)
|
23
|
+
nokogiri (~> 1.6, >= 1.6.8)
|
24
|
+
byebug (10.0.0)
|
25
|
+
coderay (1.1.2)
|
26
|
+
diff-lcs (1.3)
|
27
|
+
dragonfly (1.1.4)
|
28
|
+
addressable (~> 2.3)
|
29
|
+
multi_json (~> 1.0)
|
30
|
+
rack (>= 1.3)
|
31
|
+
faraday (0.14.0)
|
32
|
+
multipart-post (>= 1.2, < 3)
|
33
|
+
faraday_middleware (0.12.2)
|
34
|
+
faraday (>= 0.7.4, < 1.0)
|
35
|
+
ffi (1.9.21)
|
36
|
+
formatador (0.2.5)
|
37
|
+
guard (2.14.2)
|
38
|
+
formatador (>= 0.2.4)
|
39
|
+
listen (>= 2.7, < 4.0)
|
40
|
+
lumberjack (>= 1.0.12, < 2.0)
|
41
|
+
nenv (~> 0.1)
|
42
|
+
notiffany (~> 0.0)
|
43
|
+
pry (>= 0.9.12)
|
44
|
+
shellany (~> 0.0)
|
45
|
+
thor (>= 0.18.1)
|
46
|
+
guard-compat (1.2.1)
|
47
|
+
guard-rspec (4.7.3)
|
48
|
+
guard (~> 2.1)
|
49
|
+
guard-compat (~> 1.1)
|
50
|
+
rspec (>= 2.99.0, < 4.0)
|
51
|
+
listen (3.1.5)
|
52
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
53
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
54
|
+
ruby_dep (~> 1.2)
|
55
|
+
lumberjack (1.0.12)
|
56
|
+
method_source (0.9.0)
|
57
|
+
mini_portile2 (2.3.0)
|
58
|
+
multi_json (1.13.1)
|
59
|
+
multipart-post (2.0.0)
|
60
|
+
nenv (0.3.0)
|
61
|
+
nokogiri (1.8.2)
|
62
|
+
mini_portile2 (~> 2.3.0)
|
63
|
+
notiffany (0.1.1)
|
64
|
+
nenv (~> 0.1)
|
65
|
+
shellany (~> 0.0)
|
66
|
+
pry (0.11.3)
|
67
|
+
coderay (~> 1.1.0)
|
68
|
+
method_source (~> 0.9.0)
|
69
|
+
pry-byebug (3.6.0)
|
70
|
+
byebug (~> 10.0)
|
71
|
+
pry (~> 0.10)
|
72
|
+
public_suffix (3.0.1)
|
73
|
+
rack (2.0.4)
|
74
|
+
rb-fsevent (0.10.2)
|
75
|
+
rb-inotify (0.9.10)
|
76
|
+
ffi (>= 0.5.0, < 2)
|
77
|
+
rspec (3.7.0)
|
78
|
+
rspec-core (~> 3.7.0)
|
79
|
+
rspec-expectations (~> 3.7.0)
|
80
|
+
rspec-mocks (~> 3.7.0)
|
81
|
+
rspec-core (3.7.1)
|
82
|
+
rspec-support (~> 3.7.0)
|
83
|
+
rspec-expectations (3.7.0)
|
84
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
85
|
+
rspec-support (~> 3.7.0)
|
86
|
+
rspec-mocks (3.7.0)
|
87
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
88
|
+
rspec-support (~> 3.7.0)
|
89
|
+
rspec-support (3.7.0)
|
90
|
+
ruby_dep (1.5.0)
|
91
|
+
shellany (0.0.1)
|
92
|
+
thor (0.20.0)
|
93
|
+
|
94
|
+
PLATFORMS
|
95
|
+
ruby
|
96
|
+
|
97
|
+
DEPENDENCIES
|
98
|
+
dragonfly-azure_data_store!
|
99
|
+
guard-rspec
|
100
|
+
pry-byebug
|
101
|
+
rspec (~> 3.0)
|
102
|
+
|
103
|
+
BUNDLED WITH
|
104
|
+
1.16.1
|
data/Guardfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
2
|
+
require "guard/rspec/dsl"
|
3
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
4
|
+
|
5
|
+
# Feel free to open issues for suggestions and improvements
|
6
|
+
|
7
|
+
# RSpec files
|
8
|
+
rspec = dsl.rspec
|
9
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
10
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
11
|
+
watch(rspec.spec_files)
|
12
|
+
|
13
|
+
# Ruby files
|
14
|
+
ruby = dsl.ruby
|
15
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
16
|
+
end
|
data/README.md
CHANGED
@@ -1,43 +1,84 @@
|
|
1
1
|
# Dragonfly::AzureDataStore
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
Microsoft Azure data store for use with the
|
4
|
+
[Dragonfly](http://github.com/markevans/dragonfly) gem.
|
6
5
|
|
7
6
|
## Installation
|
8
7
|
|
9
|
-
Add this line to your application's Gemfile:
|
10
|
-
|
11
8
|
```ruby
|
12
9
|
gem 'dragonfly-azure_data_store'
|
13
10
|
```
|
14
11
|
|
15
|
-
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
Configuration (remember the require)
|
16
15
|
|
17
|
-
|
16
|
+
```ruby
|
17
|
+
require 'dragonfly/azure_data_store'
|
18
18
|
|
19
|
-
|
19
|
+
Dragonfly.app.configure do
|
20
|
+
# ...
|
20
21
|
|
21
|
-
|
22
|
+
datastore :azure, account_name: ENV['AZURE_ACCOUNT_NAME'],
|
23
|
+
container_name: ENV['AZURE_CONTAINER_NAME'],
|
24
|
+
access_key: ENV['AZURE_ACCESS_KEY']
|
22
25
|
|
23
|
-
|
26
|
+
# ...
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
30
|
+
### Available configuration options
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
:account_name
|
34
|
+
:container_name
|
35
|
+
:access_key
|
36
|
+
:url_scheme # defaults to "http"
|
37
|
+
:url_host # defaults to "<account_name>.blob.core.windows.net"
|
38
|
+
:root_path # store all content under a subdirectory - uids will be relative to this - defaults to nil
|
39
|
+
```
|
40
|
+
|
41
|
+
### Serving directly from Azure
|
24
42
|
|
25
|
-
|
43
|
+
You can get the Azure url using
|
26
44
|
|
27
|
-
|
45
|
+
```ruby
|
46
|
+
Dragonfly.app.remote_url_for('some/uid')
|
47
|
+
```
|
48
|
+
|
49
|
+
or
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
my_model.attachment.remote_url
|
53
|
+
```
|
28
54
|
|
29
|
-
|
55
|
+
or with an https url:
|
30
56
|
|
31
|
-
|
57
|
+
```ruby
|
58
|
+
my_model.attachment.remote_url(scheme: 'https') # also configurable for all urls with 'url_scheme'
|
59
|
+
```
|
60
|
+
|
61
|
+
or with a custom host:
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
my_model.attachment.remote_url(host: 'custom.domain') # also configurable for all urls with 'url_host'
|
65
|
+
```
|
32
66
|
|
33
67
|
## Contributing
|
34
68
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at
|
69
|
+
Bug reports and pull requests are welcome on GitHub at
|
70
|
+
https://github.com/meloncargo/dragonfly-azure_data_store. This project is
|
71
|
+
intended to be a safe, welcoming space for collaboration, and contributors are
|
72
|
+
expected to adhere to the [Contributor Covenant](http://contributor-covenant.org)
|
73
|
+
code of conduct.
|
36
74
|
|
37
75
|
## License
|
38
76
|
|
39
|
-
The gem is available as open source under the terms of the
|
77
|
+
The gem is available as open source under the terms of the
|
78
|
+
[MIT License](https://opensource.org/licenses/MIT).
|
40
79
|
|
41
80
|
## Code of Conduct
|
42
81
|
|
43
|
-
Everyone interacting in the Dragonfly::AzureDataStore project’s codebases, issue
|
82
|
+
Everyone interacting in the Dragonfly::AzureDataStore project’s codebases, issue
|
83
|
+
trackers, chat rooms and mailing lists is expected to follow the
|
84
|
+
[code of conduct](https://github.com/meloncargo/dragonfly-azure_data_store/blob/master/CODE_OF_CONDUCT.md).
|
@@ -23,5 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
|
24
24
|
spec.add_runtime_dependency 'azure-storage-blob', '~> 1.0'
|
25
25
|
spec.add_runtime_dependency 'dragonfly', '~> 1.0'
|
26
|
+
spec.add_development_dependency 'guard-rspec', '~> 4.0'
|
27
|
+
spec.add_development_dependency 'pry-byebug', '~> 3.0'
|
26
28
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
27
29
|
end
|
@@ -1,37 +1,56 @@
|
|
1
|
+
require 'dragonfly'
|
1
2
|
require 'azure/storage/blob'
|
2
3
|
|
3
4
|
Dragonfly::App.register_datastore(:azure) { Dragonfly::AzureDataStore }
|
4
5
|
|
5
6
|
module Dragonfly
|
6
7
|
class AzureDataStore
|
7
|
-
attr_accessor :account_name, :access_key, :container_name, :root_path
|
8
|
+
attr_accessor :account_name, :access_key, :container_name, :root_path,
|
9
|
+
:url_scheme, :url_host
|
8
10
|
|
9
11
|
def initialize(opts = {})
|
10
12
|
@account_name = opts[:account_name]
|
11
13
|
@access_key = opts[:access_key]
|
12
14
|
@container_name = opts[:container_name]
|
13
15
|
@root_path = opts[:root_path]
|
16
|
+
@url_scheme = opts[:url_scheme] || 'http'
|
17
|
+
@url_host = opts[:url_host]
|
14
18
|
end
|
15
19
|
|
16
|
-
def write(content,
|
20
|
+
def write(content, _opts = {})
|
17
21
|
blob = nil
|
18
22
|
filename = path_for(content.name || 'file')
|
19
23
|
content.file do |f|
|
20
|
-
blob =
|
24
|
+
blob = storage.create_block_blob(
|
21
25
|
container.name, full_path(filename), f
|
22
26
|
)
|
23
|
-
# storage.put_object(bucket_name, full_path(uid), f, full_storage_headers(headers, content.meta))
|
24
27
|
end
|
25
|
-
# content = File.open("test.png", "rb") { |file| file.read }
|
26
28
|
filename
|
27
29
|
end
|
28
30
|
|
29
31
|
def read(uid)
|
32
|
+
blob = storage.get_blob(container.name, full_path(uid))
|
33
|
+
[blob[1], blob[0].properties]
|
34
|
+
rescue Azure::Core::Http::HTTPError
|
35
|
+
nil
|
30
36
|
end
|
31
37
|
|
32
38
|
def destroy(uid)
|
39
|
+
storage.delete_blob(container.name, full_path(uid))
|
40
|
+
true
|
41
|
+
rescue Azure::Core::Http::HTTPError
|
42
|
+
false
|
33
43
|
end
|
34
44
|
|
45
|
+
def url_for(uid, opts = {})
|
46
|
+
scheme = opts[:scheme] || url_scheme
|
47
|
+
host = opts[:host] || url_host ||
|
48
|
+
"#{account_name}.blob.core.windows.net"
|
49
|
+
"#{scheme}://#{host}/#{container_name}/#{full_path(uid)}"
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
35
54
|
def storage
|
36
55
|
@storage ||=
|
37
56
|
Azure::Storage::Blob::BlobService.create(
|
@@ -49,13 +68,9 @@ module Dragonfly
|
|
49
68
|
end
|
50
69
|
end
|
51
70
|
|
52
|
-
# def generate_uid(name)
|
53
|
-
# "#{Time.now.strftime '%Y/%m/%d/%H/%M/%S'}/#{SecureRandom.uuid}/#{name}"
|
54
|
-
# end
|
55
|
-
|
56
71
|
def path_for(filename)
|
57
72
|
time = Time.now
|
58
|
-
"#{time.strftime '%Y/%m/%d/'}#{rand(1e15).to_s(36)}_#{filename.gsub(/[^\w.]+/,'_')}"
|
73
|
+
"#{time.strftime '%Y/%m/%d/'}#{rand(1e15).to_s(36)}_#{filename.gsub(/[^\w.]+/, '_')}"
|
59
74
|
end
|
60
75
|
|
61
76
|
def full_path(filename)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dragonfly-azure_data_store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alter Lagos
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: azure-storage-blob
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: guard-rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry-byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: rspec
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -64,6 +92,8 @@ files:
|
|
64
92
|
- ".travis.yml"
|
65
93
|
- CODE_OF_CONDUCT.md
|
66
94
|
- Gemfile
|
95
|
+
- Gemfile.lock
|
96
|
+
- Guardfile
|
67
97
|
- LICENSE.txt
|
68
98
|
- README.md
|
69
99
|
- Rakefile
|