paperclip-azure 1.0.0 → 1.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 +4 -4
- data/Manifest.txt +27 -1
- data/README.txt +25 -7
- data/Rakefile +7 -1
- data/lib/paperclip-azure.rb +0 -1
- data/lib/paperclip/azure.rb +1 -1
- data/lib/paperclip/storage/azure.rb +43 -57
- data/lib/paperclip/storage/azure/environment.rb +2 -2
- data/spec/database.yml +3 -0
- data/spec/paperclip/storage/azure_spec.rb +435 -0
- data/spec/spec_helper.rb +29 -3
- data/spec/support/fake_model.rb +25 -0
- data/spec/support/fake_rails.rb +12 -0
- data/spec/support/fixtures/12k.png +0 -0
- data/spec/support/fixtures/50x50.png +0 -0
- data/spec/support/fixtures/5k.png +0 -0
- data/spec/support/fixtures/animated +0 -0
- data/spec/support/fixtures/animated.gif +0 -0
- data/spec/support/fixtures/animated.unknown +0 -0
- data/spec/support/fixtures/azure.yml +8 -0
- data/spec/support/fixtures/bad.png +1 -0
- data/spec/support/fixtures/empty.html +1 -0
- data/spec/support/fixtures/empty.xlsx +0 -0
- data/spec/support/fixtures/fog.yml +8 -0
- data/spec/support/fixtures/rotated.jpg +0 -0
- data/spec/support/fixtures/spaced file.jpg +0 -0
- data/spec/support/fixtures/spaced file.png +0 -0
- data/spec/support/fixtures/text.txt +1 -0
- data/spec/support/fixtures/twopage.pdf +0 -0
- data/spec/support/fixtures/uppercase.PNG +0 -0
- data/spec/support/mock_attachment.rb +24 -0
- data/spec/support/mock_interpolator.rb +24 -0
- data/spec/support/mock_url_generator_builder.rb +27 -0
- data/spec/support/model_reconstruction.rb +68 -0
- data/spec/support/test_data.rb +13 -0
- data/spec/support/version_helper.rb +9 -0
- metadata +116 -6
- data/lib/azure/core/auth/shared_access_signature.rb +0 -84
@@ -1,84 +0,0 @@
|
|
1
|
-
# Adapted from the SharedAccessSignature class found in the Azure
|
2
|
-
# Extensions project by David Michael located at https://github.com/dmichael/azure-contrib
|
3
|
-
|
4
|
-
require 'hashie/dash'
|
5
|
-
require 'addressable/uri'
|
6
|
-
|
7
|
-
module Azure
|
8
|
-
module Core
|
9
|
-
module Auth
|
10
|
-
class SharedAccessSignature
|
11
|
-
class Version20130815 < Hashie::Dash
|
12
|
-
property :resource, default: 'c', required: true
|
13
|
-
property :permissions, default: 'r', required: true
|
14
|
-
property :start, default: ''
|
15
|
-
property :identifier, default: ''
|
16
|
-
property :expiry, required: true
|
17
|
-
property :canonicalized_resource, required: true
|
18
|
-
property :access_key, required: true
|
19
|
-
# Do not change this
|
20
|
-
property :version, default: '2103-08-15'
|
21
|
-
end
|
22
|
-
|
23
|
-
attr_accessor :uri, :options
|
24
|
-
|
25
|
-
def initialize(uri, options = {}, account = ENV['AZURE_STORAGE_ACCOUNT'])
|
26
|
-
# This is the uri that we are signing
|
27
|
-
@uri = Addressable::URI.parse(uri)
|
28
|
-
|
29
|
-
is_blob = options[:resource] == 'b'
|
30
|
-
|
31
|
-
# Create the options hash that will be turned into a query string
|
32
|
-
@options = Version20130815.new(options.merge(canonicalized_resource: canonicalized_resource(@uri, account, is_blob)))
|
33
|
-
end
|
34
|
-
|
35
|
-
# Create a "canonicalized resource" from the full uri to be signed
|
36
|
-
def canonicalized_resource(uri, account = ENV['AZURE_STORAGE_ACCOUNT'], is_blob = false)
|
37
|
-
path = uri.path # Addressable::URI
|
38
|
-
# There is only really one level deep for containers, the remainder is the BLOB key (that looks like a path)
|
39
|
-
path_array = path.split('/').reject {|p| p == ''}
|
40
|
-
container = path_array.shift
|
41
|
-
|
42
|
-
string = if is_blob
|
43
|
-
File.join('/', account, container, path_array.join('/'))
|
44
|
-
else
|
45
|
-
File.join('/', account, container)
|
46
|
-
end
|
47
|
-
|
48
|
-
string
|
49
|
-
end
|
50
|
-
|
51
|
-
# When creating the query string from the options, we only include the no-empty fields
|
52
|
-
# - this is opposed to the string that gets signed which includes them as blank.
|
53
|
-
def create_query_values(options = Version20130815.new)
|
54
|
-
# Parts
|
55
|
-
parts = {}
|
56
|
-
parts[:st] = URI.unescape(options[:start]) unless options[:start] == ''
|
57
|
-
parts[:se] = URI.unescape(options[:expiry])
|
58
|
-
parts[:sr] = URI.unescape(options[:resource])
|
59
|
-
parts[:sp] = URI.unescape(options[:permissions])
|
60
|
-
parts[:si] = URI.unescape(options[:identifier]) unless options[:identifier] == ''
|
61
|
-
parts[:sig] = URI.unescape( create_signature(options) )
|
62
|
-
|
63
|
-
parts
|
64
|
-
end
|
65
|
-
|
66
|
-
def create_signature(options = Version20130815)
|
67
|
-
string_to_sign = []
|
68
|
-
string_to_sign << options[:permissions]
|
69
|
-
string_to_sign << options[:start]
|
70
|
-
string_to_sign << options[:expiry]
|
71
|
-
string_to_sign << options[:canonicalized_resource]
|
72
|
-
string_to_sign << options[:identifier]
|
73
|
-
|
74
|
-
::Azure::Core::Auth::Signer.new(options[:access_key]).sign(string_to_sign.join("\n").force_encoding("UTF-8"))
|
75
|
-
end
|
76
|
-
|
77
|
-
def sign
|
78
|
-
@uri.query_values = create_query_values(@options)
|
79
|
-
@uri.to_s
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|