azure-contrib 0.0.2
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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +44 -0
- data/Rakefile +1 -0
- data/azure-contrib.gemspec +26 -0
- data/lib/azure/contrib.rb +10 -0
- data/lib/azure/contrib/auth/shared_access_signature.rb +86 -0
- data/lib/azure/contrib/version.rb +5 -0
- metadata +123 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 36da49c6b4377b239c91448549113c8758086380
|
4
|
+
data.tar.gz: aeaddf13a7d8ba562620c0a706fcf9dc5bcee053
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a4c366aa16cbec9af691d5f0871de427c0dc0fc591d69e90d80b6f14b0207bd35271748ef00f725c8a95091368d6c55c931971705876aa8b2ab32a6a01b2e944
|
7
|
+
data.tar.gz: f8639319d3bc0ce2893585c01b72704423a854ffe47eef3cd22bec9ed5f793d27fb1c92d2c86bfbb820901c682be4c7d98cee88515a88337554b8d9414423433
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 David Michael
|
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,44 @@
|
|
1
|
+
# Microsoft Azure SDK for Ruby ... Extensions!
|
2
|
+
|
3
|
+
This was written as a container to add functionality missing from the Azure SDK, specifically the Shared Access Signature which is needed for CORS requests from JavaScript, among other things
|
4
|
+
|
5
|
+
This bit of code was written with the help of these sources:
|
6
|
+
* http://msdn.microsoft.com/en-us/library/dn140255.aspx
|
7
|
+
* http://msdn.microsoft.com/en-us/library/azure/dn140256.aspx
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'azure-contrib', git: 'https://github.com/dmichael/azure-contrib.git'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
Its a start
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
|
26
|
+
signer = Azure::Contrib::Auth::SharedAccessSignature.new(uri, {
|
27
|
+
resource: 'c',
|
28
|
+
permissions: 'w',
|
29
|
+
start: (Time.now - 5*60).utc.iso8601,
|
30
|
+
expiry: (Time.now + 30*60).utc.iso8601
|
31
|
+
})
|
32
|
+
|
33
|
+
signed_uri = signer.sign
|
34
|
+
|
35
|
+
|
36
|
+
```
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
1. Fork it ( http://github.com/<my-github-username>/azure-contrib/fork )
|
41
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
42
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
43
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
44
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'azure/contrib/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "azure-contrib"
|
8
|
+
spec.version = Azure::Contrib::VERSION
|
9
|
+
spec.authors = ["David Michael"]
|
10
|
+
spec.email = ["david.michael@giantmachines.com"]
|
11
|
+
spec.summary = %q{Extensions to the Azure Ruby SDK}
|
12
|
+
spec.description = %q{Extensions to the Azure Ruby SDK - specifically SAS}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_dependency "azure"
|
24
|
+
spec.add_dependency "hashie"
|
25
|
+
spec.add_dependency "addressable"
|
26
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'azure'
|
4
|
+
require 'hashie/dash'
|
5
|
+
require 'addressable/uri'
|
6
|
+
|
7
|
+
module Azure
|
8
|
+
module Contrib
|
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
|
+
# Do not change this
|
19
|
+
property :version, default: '2103-08-15'
|
20
|
+
end
|
21
|
+
|
22
|
+
attr_accessor :uri, :options
|
23
|
+
|
24
|
+
def initialize(uri, options = {}, account = ENV['AZURE_STORAGE_ACCOUNT'])
|
25
|
+
# This is the uri that we are signing
|
26
|
+
@uri = Addressable::URI.parse(uri)
|
27
|
+
|
28
|
+
is_blob = options[:resource] == 'b'
|
29
|
+
|
30
|
+
# Create the options hash that will be turned into a query string
|
31
|
+
@options = Version20130815.new(options.merge(canonicalized_resource: canonicalized_resource(@uri, account, is_blob)))
|
32
|
+
end
|
33
|
+
|
34
|
+
# Create a "canonicalized resource" from the full uri to be signed
|
35
|
+
def canonicalized_resource(uri, account = ENV['AZURE_STORAGE_ACCOUNT'], is_blob = false)
|
36
|
+
path = uri.path # Addressable::URI
|
37
|
+
# There is only really one level deep for containers, the remainder is the BLOB key (that looks like a path)
|
38
|
+
path_array = path.split('/').reject {|p| p == ''}
|
39
|
+
container = path_array.shift
|
40
|
+
|
41
|
+
string = if is_blob
|
42
|
+
File.join('/', account, container, path_array.join('/'))
|
43
|
+
else
|
44
|
+
File.join('/', account, container)
|
45
|
+
end
|
46
|
+
|
47
|
+
string
|
48
|
+
end
|
49
|
+
|
50
|
+
# When creating the query string from the options, we only include the no-empty fields
|
51
|
+
# - this is opposed to the string that gets signed which includes them as blank.
|
52
|
+
def create_query_values(options = Version20130815.new)
|
53
|
+
# Parts
|
54
|
+
parts = {}
|
55
|
+
parts[:st] = URI.unescape(options[:start]) unless options[:start] == ''
|
56
|
+
parts[:se] = URI.unescape(options[:expiry])
|
57
|
+
parts[:sr] = URI.unescape(options[:resource])
|
58
|
+
parts[:sp] = URI.unescape(options[:permissions])
|
59
|
+
parts[:si] = URI.unescape(options[:identifier]) unless options[:identifier] == ''
|
60
|
+
parts[:sig] = URI.unescape( create_signature(options) )
|
61
|
+
|
62
|
+
parts
|
63
|
+
end
|
64
|
+
|
65
|
+
def create_signature(options = Version20130815)
|
66
|
+
string_to_sign = []
|
67
|
+
string_to_sign << options[:permissions]
|
68
|
+
string_to_sign << options[:start]
|
69
|
+
string_to_sign << options[:expiry]
|
70
|
+
string_to_sign << options[:canonicalized_resource]
|
71
|
+
string_to_sign << options[:identifier]
|
72
|
+
|
73
|
+
Azure::Core::Auth::Signer.new.sign(string_to_sign.join("\n").force_encoding("UTF-8"))
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
def sign
|
79
|
+
@uri.query_values = create_query_values(@options)
|
80
|
+
@uri.to_s
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: azure-contrib
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Michael
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: azure
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: hashie
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: addressable
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Extensions to the Azure Ruby SDK - specifically SAS
|
84
|
+
email:
|
85
|
+
- david.michael@giantmachines.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- azure-contrib.gemspec
|
96
|
+
- lib/azure/contrib.rb
|
97
|
+
- lib/azure/contrib/auth/shared_access_signature.rb
|
98
|
+
- lib/azure/contrib/version.rb
|
99
|
+
homepage: ''
|
100
|
+
licenses:
|
101
|
+
- MIT
|
102
|
+
metadata: {}
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 2.2.2
|
120
|
+
signing_key:
|
121
|
+
specification_version: 4
|
122
|
+
summary: Extensions to the Azure Ruby SDK
|
123
|
+
test_files: []
|