azure-core 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NmExZTJjYWU5OTNjOGQ5NDdiNWI3ZGVlYWRkNjE5ZTRjYjExYzBhMg==
5
+ data.tar.gz: !binary |-
6
+ NWMxMGI5MGEzYzE4NGYzOTRhMGVjMGUzZjk5Y2YxMzlhYTNhMjFhNg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ Njg5NmIzZjA5ZWRjMDkyZWRiOWQ1Y2JlZGNmZDBmOWYzYTI5NmEyOGEzZjY4
10
+ NjNlMzA0MWRhMzEwZjQyN2ExOTE1OGM0MjJhMWIyODhhNjY0ZDY2OWJjOTc3
11
+ NGNlZGE1OGU3YzkwOGMzMjg5YTIzNWU2YWUxNjNlZDZlM2Y2YmE=
12
+ data.tar.gz: !binary |-
13
+ YTQ1YzAxNWUzYmYyNmMzMGE0ZWJjMzI0OGY5ZDU5ZmYwNGYxZjNhMmYxYjlj
14
+ MmNkYTg5ZGM2ZjdmOWE2NzZiMDk5MjYxMDlkZWRlN2E4ODJiOWJjMmE4NjUz
15
+ ZTk0Y2YyM2I0MGMyOGNmNTA3YTIwOGRiZDFmNjE5ZmZiNGRiZjE=
@@ -0,0 +1,32 @@
1
+ .rvmrc
2
+ *.gem
3
+ *.rbc
4
+ *.swp
5
+ *.tmproj
6
+ *~
7
+ .\#*
8
+ tags
9
+ /pkg
10
+ /doc
11
+ Gemfile.lock
12
+ nbproject/*
13
+ *.gem
14
+ .idea
15
+ .project
16
+ .bundle
17
+ .config
18
+ .yardoc
19
+ _yardoc
20
+ coverage
21
+ doc/
22
+ lib/bundler/man
23
+ pkg
24
+ rdoc
25
+
26
+
27
+ .DS_Store
28
+ .ruby-version
29
+ .env
30
+ *.pem
31
+ !service_management/azure/test/fixtures/management_certificate.pem
32
+ *.publishsettings
@@ -0,0 +1,19 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.0.0
5
+ - 2.1.5
6
+ - 2.2.0
7
+ - 2.3.0
8
+ before_install: gem install bundler -v 1.11.2
9
+ script:
10
+ - bundle install && bundle exec rake test:unit
11
+ deploy:
12
+ provider: rubygems
13
+ api_key:
14
+ secure: EN/hvsyyZq4bOxJgJXVP8AttRsn9ajYrtsg47bVcPHtSXP52mT1r800FC50l1V1MoeNPrgjO8WjVY37rR/FerDsdt0rujakfseKOpCeosAX8hbJ2zVcyOnU16TmkNUAqKKprHkvw/8dnNEYmeyUo+VZmizxVhieur8yitKWiP08Ab1ehA8sDfcGsusnE/Las7fyiiCqMfFQJsJWJimIXNYF6pGZs+6l1YE2sH5S4wKLf09+jhP4WZ6nXcYlyUViLqieMx3US1a9jVV534QSIVYk7Z8PdP4eJm4P46UJ1YPc85DceLAZh2dno5l+Eyk16UYBgPichWEqQf3+0SaNKxNDkNYmXPkxNbajIKFLAsTs7CBwhwK3CxfgDok2P3jcB9iJg3ZlWFD6fMxr1Tca1cEkLpxj8S7peB4St0AwVeaEXfUHIDHb706PbOOoy5BOuK+aDotz0/sHQTOHSAPD4IhZ3+GKCkV4NOV2fxKTWXYK1NSx76jyBW3gnSsy9OWKhKxEXaVLB3J1i5dKUw1l4YBJuRATw2GbimMqQf0EpXukXE/fKugU4+EQUZwoIe85GrjaJrU/LXMpp8lBoh5dPZOxtEXGp6cJWcl239FUVSY17Wf/H8cTpahhNR+PNHUyavC2syPOqxrzNKmfNN3bWFm6iJkYCNI2bFxpUB/Ky+Vc=
15
+ gemspec: azure-core.gemspec
16
+ gem: azure-core
17
+ on:
18
+ tags: true
19
+ repo: Azure/azure-ruby-asm-core
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ #-------------------------------------------------------------------------
2
+ # # Copyright (c) Microsoft and contributors. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #--------------------------------------------------------------------------
15
+ source 'https://rubygems.org'
16
+ gemspec
@@ -0,0 +1,32 @@
1
+ # Azure::Core
2
+
3
+ This project provides a Ruby package with core functionality consumed by Azure SDK gems.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'azure-core'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install azure-core
20
+
21
+ ## Usage
22
+ ```ruby
23
+ require 'azure/core'
24
+ ```
25
+
26
+ ## Development
27
+
28
+ After checking out the repo, run `bundle install` to install dependencies. Then, run `rake test` to run the tests.
29
+
30
+ ## Provide Feedback
31
+
32
+ If you encounter any bugs with the library please file an issue.
@@ -0,0 +1,48 @@
1
+ #-------------------------------------------------------------------------
2
+ # # Copyright (c) Microsoft and contributors. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #--------------------------------------------------------------------------
15
+ require 'rake/testtask'
16
+ require 'rubygems/package_task'
17
+
18
+ gem_spec = eval(File.read('./azure-core.gemspec'))
19
+ Gem::PackageTask.new(gem_spec) do |pkg|
20
+ pkg.need_zip = false
21
+ pkg.need_tar = false
22
+ end
23
+
24
+ namespace :test do
25
+
26
+ Rake::TestTask.new :unit do |t|
27
+ t.pattern = 'test/unit/**/*_test.rb'
28
+ t.verbose = true
29
+ t.libs = %w(lib test)
30
+ end
31
+
32
+ namespace :unit do
33
+ def component_task(component)
34
+ Rake::TestTask.new component do |t|
35
+ t.pattern = "test/unit/#{component}/**/*_test.rb"
36
+ t.verbose = true
37
+ t.libs = %w(lib test)
38
+ end
39
+ end
40
+
41
+ component_task :core
42
+ end
43
+
44
+ end
45
+
46
+ task :test => %w(test:unit)
47
+
48
+ task :default => :test
@@ -0,0 +1,43 @@
1
+ #-------------------------------------------------------------------------
2
+ # # Copyright (c) Microsoft and contributors. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #--------------------------------------------------------------------------
15
+ require 'date'
16
+
17
+ require File.expand_path('../lib/azure/core/version', __FILE__)
18
+
19
+ Gem::Specification.new do |s|
20
+ s.name = 'azure-core'
21
+ s.version = Azure::Core::Version
22
+ s.authors = ['Microsoft Corporation', 'AppFog']
23
+ s.email = 'azureruby@microsoft.com'
24
+ s.description = 'Microsoft Azure Client Core Library for Ruby SDK'
25
+ s.summary = 'Core library to be consumed by Ruby SDK gems'
26
+ s.homepage = 'http://github.com/Azure/azure-ruby-asm-core'
27
+ s.license = 'Apache License, Version 2.0'
28
+ s.files = `git ls-files`.split("\n").reject { |f| f.start_with?("test/unit") }
29
+
30
+ s.required_ruby_version = '>= 1.9.3'
31
+
32
+ s.add_runtime_dependency('faraday', '~> 0.9')
33
+ s.add_runtime_dependency('faraday_middleware', '~> 0.10')
34
+ s.add_runtime_dependency('nokogiri', '~> 1.6')
35
+
36
+ s.add_development_dependency('dotenv', '~> 2.0')
37
+ s.add_development_dependency('minitest', '~> 5')
38
+ s.add_development_dependency('minitest-reporters', '~> 1')
39
+ s.add_development_dependency('mocha', '~> 1.0')
40
+ s.add_development_dependency('rake', '~> 10.0')
41
+ s.add_development_dependency('timecop', '~> 0.7')
42
+ s.add_development_dependency('bundler', '~> 1.11')
43
+ end
@@ -0,0 +1,32 @@
1
+ #-------------------------------------------------------------------------
2
+ # # Copyright (c) Microsoft and contributors. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #--------------------------------------------------------------------------
15
+
16
+ require 'rubygems'
17
+ require 'nokogiri'
18
+ require 'faraday'
19
+ require 'faraday_middleware'
20
+
21
+ module Azure
22
+ module Core
23
+ autoload :Utility, 'azure/core/utility'
24
+ autoload :Logger, 'azure/core/utility'
25
+ autoload :Error, 'azure/core/error'
26
+ autoload :Service, 'azure/core/service'
27
+ autoload :FilteredService, 'azure/core/filtered_service'
28
+ autoload :SignedService, 'azure/core/signed_service'
29
+ autoload :Default, 'azure/core/default'
30
+ end
31
+
32
+ end
@@ -0,0 +1,36 @@
1
+ #-------------------------------------------------------------------------
2
+ # # Copyright (c) Microsoft and contributors. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #--------------------------------------------------------------------------
15
+ require "azure/core/configuration"
16
+
17
+ module Azure
18
+ module Core
19
+ module Auth
20
+ class Authorizer
21
+ # Public: Signs an HTTP request before it's made, by adding the
22
+ # Authorization header
23
+ #
24
+ # request - An Azure::Core::HttpRequest that hasn't been signed
25
+ # signer - A signing strategy, such as Azure::Table::Auth::SharedKey
26
+ #
27
+ # Returns the modified request
28
+ def sign(request, signer)
29
+ signature = signer.sign(request.method, request.uri, request.headers)
30
+ request.headers['Authorization'] = "#{signer.name} #{signature}"
31
+ request
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,118 @@
1
+ #-------------------------------------------------------------------------
2
+ # # Copyright (c) Microsoft and contributors. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #--------------------------------------------------------------------------
15
+ require 'cgi'
16
+ require 'azure/core/auth/signer'
17
+
18
+ module Azure
19
+ module Core
20
+ module Auth
21
+ class SharedKey < Signer
22
+ # The Azure account's name.
23
+ attr :account_name
24
+
25
+ # Initialize the Signer.
26
+ #
27
+ # @param account_name [String] The account name. Defaults to the one in the
28
+ # global configuration.
29
+ # @param access_key [String] The access_key encoded in Base64. Defaults to the
30
+ # one in the global configuration.
31
+ def initialize(account_name=Azure.storage_account_name, access_key=Azure.storage_access_key)
32
+ @account_name = account_name
33
+ super(access_key)
34
+ end
35
+
36
+ # The name of the strategy.
37
+ #
38
+ # @return [String]
39
+ def name
40
+ 'SharedKey'
41
+ end
42
+
43
+ # Create the signature for the request parameters
44
+ #
45
+ # @param method [Symbol] HTTP request method.
46
+ # @param uri [URI] URI of the request we're signing.
47
+ # @param headers [Hash] HTTP request headers.
48
+ #
49
+ # @return [String] base64 encoded signature
50
+ def sign(method, uri, headers)
51
+ "#{account_name}:#{super(signable_string(method, uri, headers))}"
52
+ end
53
+
54
+ # Sign the request
55
+ #
56
+ # @param req [Azure::Core::Http::HttpRequest] HTTP request to sign
57
+ #
58
+ # @return [Azure::Core::Http::HttpRequest]
59
+ def sign_request(req)
60
+ req.headers['Authorization'] = "#{name} #{sign(req.method, req.uri, req.headers)}"
61
+ req
62
+ end
63
+
64
+ # Generate the string to sign.
65
+ #
66
+ # @param method [Symbol] HTTP request method.
67
+ # @param uri [URI] URI of the request we're signing.
68
+ # @param headers [Hash] HTTP request headers.
69
+ #
70
+ # @return [String]
71
+ def signable_string(method, uri, headers)
72
+ [
73
+ method.to_s.upcase,
74
+ headers.fetch('Content-Encoding', ''),
75
+ headers.fetch('Content-Language', ''),
76
+ headers.fetch('Content-Length', ''),
77
+ headers.fetch('Content-MD5', ''),
78
+ headers.fetch('Content-Type', ''),
79
+ headers.fetch('Date', ''),
80
+ headers.fetch('If-Modified-Since', ''),
81
+ headers.fetch('If-Match', ''),
82
+ headers.fetch('If-None-Match', ''),
83
+ headers.fetch('If-Unmodified-Since', ''),
84
+ headers.fetch('Range', ''),
85
+ canonicalized_headers(headers),
86
+ canonicalized_resource(uri)
87
+ ].join("\n")
88
+ end
89
+
90
+ # Calculate the Canonicalized Headers string for a request.
91
+ #
92
+ # @param headers [Hash] HTTP request headers.
93
+ #
94
+ # @return [String] a string with the canonicalized headers.
95
+ def canonicalized_headers(headers)
96
+ headers = headers.map { |k,v| [k.to_s.downcase, v] }
97
+ headers.select! { |k,v| k =~ /^x-ms-/ }
98
+ headers.sort_by! { |(k,v)| k }
99
+ headers.map! { |k,v| '%s:%s' % [k, v] }
100
+ headers.map! { |h| h.gsub(/\s+/, ' ') }.join("\n")
101
+ end
102
+
103
+ # Calculate the Canonicalized Resource string for a request.
104
+ #
105
+ # @param uri [URI] URI of the request we're signing.
106
+ #
107
+ # @return [String] a string with the canonicalized resource.
108
+ def canonicalized_resource(uri)
109
+ resource = '/' + account_name + (uri.path.empty? ? '/' : uri.path)
110
+ params = CGI.parse(uri.query.to_s).map { |k,v| [k.downcase, v] }
111
+ params.sort_by! { |k,v| k }
112
+ params.map! { |k,v| '%s:%s' % [k, v.map(&:strip).sort.join(',')] }
113
+ [resource, *params].join("\n")
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,48 @@
1
+ #-------------------------------------------------------------------------
2
+ # # Copyright (c) Microsoft and contributors. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #--------------------------------------------------------------------------
15
+ require "azure/core/auth/shared_key"
16
+
17
+ module Azure
18
+ module Core
19
+ module Auth
20
+ class SharedKeyLite < SharedKey
21
+ # The name of the strategy.
22
+ #
23
+ # @return [String]
24
+ def name
25
+ 'SharedKeyLite'
26
+ end
27
+
28
+ # Generate the string to sign.
29
+ #
30
+ # @param method [Symbol] The HTTP request method.
31
+ # @param uri [URI] The URI of the request we're signing.
32
+ # @param headers [Hash] A Hash of HTTP request headers.
33
+ #
34
+ # Returns a plain text string.
35
+ def signable_string(method, uri, headers)
36
+ [
37
+ method.to_s.upcase,
38
+ headers.fetch('Content-MD5', ''),
39
+ headers.fetch('Content-Type', ''),
40
+ headers.fetch('Date') { raise IndexError, 'Headers must include Date' },
41
+ canonicalized_headers(headers),
42
+ canonicalized_resource(uri)
43
+ ].join("\n")
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end