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.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/Manifest.txt +27 -1
  3. data/README.txt +25 -7
  4. data/Rakefile +7 -1
  5. data/lib/paperclip-azure.rb +0 -1
  6. data/lib/paperclip/azure.rb +1 -1
  7. data/lib/paperclip/storage/azure.rb +43 -57
  8. data/lib/paperclip/storage/azure/environment.rb +2 -2
  9. data/spec/database.yml +3 -0
  10. data/spec/paperclip/storage/azure_spec.rb +435 -0
  11. data/spec/spec_helper.rb +29 -3
  12. data/spec/support/fake_model.rb +25 -0
  13. data/spec/support/fake_rails.rb +12 -0
  14. data/spec/support/fixtures/12k.png +0 -0
  15. data/spec/support/fixtures/50x50.png +0 -0
  16. data/spec/support/fixtures/5k.png +0 -0
  17. data/spec/support/fixtures/animated +0 -0
  18. data/spec/support/fixtures/animated.gif +0 -0
  19. data/spec/support/fixtures/animated.unknown +0 -0
  20. data/spec/support/fixtures/azure.yml +8 -0
  21. data/spec/support/fixtures/bad.png +1 -0
  22. data/spec/support/fixtures/empty.html +1 -0
  23. data/spec/support/fixtures/empty.xlsx +0 -0
  24. data/spec/support/fixtures/fog.yml +8 -0
  25. data/spec/support/fixtures/rotated.jpg +0 -0
  26. data/spec/support/fixtures/spaced file.jpg +0 -0
  27. data/spec/support/fixtures/spaced file.png +0 -0
  28. data/spec/support/fixtures/text.txt +1 -0
  29. data/spec/support/fixtures/twopage.pdf +0 -0
  30. data/spec/support/fixtures/uppercase.PNG +0 -0
  31. data/spec/support/mock_attachment.rb +24 -0
  32. data/spec/support/mock_interpolator.rb +24 -0
  33. data/spec/support/mock_url_generator_builder.rb +27 -0
  34. data/spec/support/model_reconstruction.rb +68 -0
  35. data/spec/support/test_data.rb +13 -0
  36. data/spec/support/version_helper.rb +9 -0
  37. metadata +116 -6
  38. 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