gitlab-fog-azure-rm 1.9.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -0
  3. data/Gemfile +3 -0
  4. data/gitlab-fog-azure-rm.gemspec +1 -3
  5. data/lib/fog/azurerm/version.rb +1 -1
  6. data/vendor/azure-storage-ruby/.env_sample +8 -0
  7. data/vendor/azure-storage-ruby/.gitignore +35 -0
  8. data/vendor/azure-storage-ruby/.rubocop.yml +132 -0
  9. data/vendor/azure-storage-ruby/.travis.yml +23 -0
  10. data/vendor/azure-storage-ruby/BreakingChanges.md +34 -0
  11. data/vendor/azure-storage-ruby/CONTRIBUTING.md +74 -0
  12. data/vendor/azure-storage-ruby/ChangeLog.md +198 -0
  13. data/vendor/azure-storage-ruby/Gemfile +41 -0
  14. data/vendor/azure-storage-ruby/README.md +48 -0
  15. data/vendor/azure-storage-ruby/Rakefile +216 -0
  16. data/vendor/azure-storage-ruby/SECURITY.md +41 -0
  17. data/vendor/azure-storage-ruby/blob/BreakingChanges.md +10 -0
  18. data/vendor/azure-storage-ruby/blob/ChangeLog.md +33 -0
  19. data/vendor/azure-storage-ruby/blob/Gemfile +30 -0
  20. data/vendor/azure-storage-ruby/blob/LICENSE.txt +21 -0
  21. data/vendor/azure-storage-ruby/blob/README.md +188 -0
  22. data/vendor/azure-storage-ruby/blob/azure-storage-blob.gemspec +52 -0
  23. data/vendor/azure-storage-ruby/blob/lib/azure/storage/blob/append.rb +244 -0
  24. data/vendor/azure-storage-ruby/blob/lib/azure/storage/blob/autoload.rb +47 -0
  25. data/vendor/azure-storage-ruby/blob/lib/azure/storage/blob/blob.rb +932 -0
  26. data/vendor/azure-storage-ruby/blob/lib/azure/storage/blob/blob_service.rb +720 -0
  27. data/vendor/azure-storage-ruby/blob/lib/azure/storage/blob/block.rb +530 -0
  28. data/vendor/azure-storage-ruby/blob/lib/azure/storage/blob/container.rb +634 -0
  29. data/vendor/azure-storage-ruby/blob/lib/azure/storage/blob/default.rb +171 -0
  30. data/vendor/azure-storage-ruby/blob/lib/azure/storage/blob/page.rb +566 -0
  31. data/vendor/azure-storage-ruby/blob/lib/azure/storage/blob/serialization.rb +351 -0
  32. data/vendor/azure-storage-ruby/blob/lib/azure/storage/blob/version.rb +49 -0
  33. data/vendor/azure-storage-ruby/blob/lib/azure/storage/blob.rb +26 -0
  34. data/vendor/azure-storage-ruby/common/BreakingChanges.md +8 -0
  35. data/vendor/azure-storage-ruby/common/ChangeLog.md +41 -0
  36. data/vendor/azure-storage-ruby/common/Gemfile +30 -0
  37. data/vendor/azure-storage-ruby/common/LICENSE.txt +21 -0
  38. data/vendor/azure-storage-ruby/common/README.md +146 -0
  39. data/vendor/azure-storage-ruby/common/azure-storage-common.gemspec +57 -0
  40. data/vendor/azure-storage-ruby/common/lib/azure/core/auth/authorizer.rb +36 -0
  41. data/vendor/azure-storage-ruby/common/lib/azure/core/auth/shared_key.rb +125 -0
  42. data/vendor/azure-storage-ruby/common/lib/azure/core/auth/shared_key_lite.rb +48 -0
  43. data/vendor/azure-storage-ruby/common/lib/azure/core/auth/signer.rb +51 -0
  44. data/vendor/azure-storage-ruby/common/lib/azure/core/default.rb +23 -0
  45. data/vendor/azure-storage-ruby/common/lib/azure/core/error.rb +21 -0
  46. data/vendor/azure-storage-ruby/common/lib/azure/core/filtered_service.rb +45 -0
  47. data/vendor/azure-storage-ruby/common/lib/azure/core/http/debug_filter.rb +36 -0
  48. data/vendor/azure-storage-ruby/common/lib/azure/core/http/http_error.rb +135 -0
  49. data/vendor/azure-storage-ruby/common/lib/azure/core/http/http_filter.rb +53 -0
  50. data/vendor/azure-storage-ruby/common/lib/azure/core/http/http_request.rb +195 -0
  51. data/vendor/azure-storage-ruby/common/lib/azure/core/http/http_response.rb +102 -0
  52. data/vendor/azure-storage-ruby/common/lib/azure/core/http/retry_policy.rb +84 -0
  53. data/vendor/azure-storage-ruby/common/lib/azure/core/http/signer_filter.rb +33 -0
  54. data/vendor/azure-storage-ruby/common/lib/azure/core/service.rb +46 -0
  55. data/vendor/azure-storage-ruby/common/lib/azure/core/signed_service.rb +45 -0
  56. data/vendor/azure-storage-ruby/common/lib/azure/core/utility.rb +244 -0
  57. data/vendor/azure-storage-ruby/common/lib/azure/core/version.rb +33 -0
  58. data/vendor/azure-storage-ruby/common/lib/azure/core.rb +48 -0
  59. data/vendor/azure-storage-ruby/common/lib/azure/http_response_helper.rb +38 -0
  60. data/vendor/azure-storage-ruby/common/lib/azure/storage/common/autoload.rb +62 -0
  61. data/vendor/azure-storage-ruby/common/lib/azure/storage/common/client.rb +162 -0
  62. data/vendor/azure-storage-ruby/common/lib/azure/storage/common/client_options.rb +363 -0
  63. data/vendor/azure-storage-ruby/common/lib/azure/storage/common/client_options_error.rb +41 -0
  64. data/vendor/azure-storage-ruby/common/lib/azure/storage/common/configurable.rb +212 -0
  65. data/vendor/azure-storage-ruby/common/lib/azure/storage/common/core/auth/anonymous_signer.rb +43 -0
  66. data/vendor/azure-storage-ruby/common/lib/azure/storage/common/core/auth/shared_access_signature.rb +30 -0
  67. data/vendor/azure-storage-ruby/common/lib/azure/storage/common/core/auth/shared_access_signature_generator.rb +399 -0
  68. data/vendor/azure-storage-ruby/common/lib/azure/storage/common/core/auth/shared_access_signature_signer.rb +57 -0
  69. data/vendor/azure-storage-ruby/common/lib/azure/storage/common/core/auth/shared_key.rb +60 -0
  70. data/vendor/azure-storage-ruby/common/lib/azure/storage/common/core/auth/token_signer.rb +43 -0
  71. data/vendor/azure-storage-ruby/common/lib/azure/storage/common/core/autoload.rb +53 -0
  72. data/vendor/azure-storage-ruby/common/lib/azure/storage/common/core/error.rb +43 -0
  73. data/vendor/azure-storage-ruby/common/lib/azure/storage/common/core/filter/exponential_retry_filter.rb +64 -0
  74. data/vendor/azure-storage-ruby/common/lib/azure/storage/common/core/filter/linear_retry_filter.rb +55 -0
  75. data/vendor/azure-storage-ruby/common/lib/azure/storage/common/core/filter/retry_filter.rb +300 -0
  76. data/vendor/azure-storage-ruby/common/lib/azure/storage/common/core/http_client.rb +82 -0
  77. data/vendor/azure-storage-ruby/common/lib/azure/storage/common/core/sr.rb +85 -0
  78. data/vendor/azure-storage-ruby/common/lib/azure/storage/common/core/token_credential.rb +64 -0
  79. data/vendor/azure-storage-ruby/common/lib/azure/storage/common/core/utility.rb +261 -0
  80. data/vendor/azure-storage-ruby/common/lib/azure/storage/common/core.rb +35 -0
  81. data/vendor/azure-storage-ruby/common/lib/azure/storage/common/default.rb +868 -0
  82. data/vendor/azure-storage-ruby/common/lib/azure/storage/common/service/access_policy.rb +37 -0
  83. data/vendor/azure-storage-ruby/common/lib/azure/storage/common/service/cors.rb +38 -0
  84. data/vendor/azure-storage-ruby/common/lib/azure/storage/common/service/cors_rule.rb +48 -0
  85. data/vendor/azure-storage-ruby/common/lib/azure/storage/common/service/enumeration_results.rb +32 -0
  86. data/vendor/azure-storage-ruby/common/lib/azure/storage/common/service/geo_replication.rb +40 -0
  87. data/vendor/azure-storage-ruby/common/lib/azure/storage/common/service/logging.rb +47 -0
  88. data/vendor/azure-storage-ruby/common/lib/azure/storage/common/service/metrics.rb +45 -0
  89. data/vendor/azure-storage-ruby/common/lib/azure/storage/common/service/retention_policy.rb +37 -0
  90. data/vendor/azure-storage-ruby/common/lib/azure/storage/common/service/serialization.rb +335 -0
  91. data/vendor/azure-storage-ruby/common/lib/azure/storage/common/service/signed_identifier.rb +40 -0
  92. data/vendor/azure-storage-ruby/common/lib/azure/storage/common/service/storage_service.rb +322 -0
  93. data/vendor/azure-storage-ruby/common/lib/azure/storage/common/service/storage_service_properties.rb +48 -0
  94. data/vendor/azure-storage-ruby/common/lib/azure/storage/common/service/storage_service_stats.rb +39 -0
  95. data/vendor/azure-storage-ruby/common/lib/azure/storage/common/service/user_delegation_key.rb +50 -0
  96. data/vendor/azure-storage-ruby/common/lib/azure/storage/common/version.rb +49 -0
  97. data/vendor/azure-storage-ruby/common/lib/azure/storage/common.rb +26 -0
  98. metadata +95 -31
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ #-------------------------------------------------------------------------
4
+ # # Copyright (c) Microsoft and contributors. All rights reserved.
5
+ #
6
+ # The MIT License(MIT)
7
+
8
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ # of this software and associated documentation files(the "Software"), to deal
10
+ # in the Software without restriction, including without limitation the rights
11
+ # to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
12
+ # copies of the Software, and to permit persons to whom the Software is
13
+ # furnished to do so, subject to the following conditions :
14
+
15
+ # The above copyright notice and this permission notice shall be included in
16
+ # all copies or substantial portions of the Software.
17
+
18
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
21
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ # THE SOFTWARE.
25
+ #--------------------------------------------------------------------------
26
+ require "date"
27
+
28
+ require_relative "./lib/azure/storage/common/version"
29
+
30
+ Gem::Specification.new do |s|
31
+ s.name = "azure-storage-common"
32
+ s.version = Azure::Storage::Common::Version
33
+ s.authors = ["Microsoft Corporation"]
34
+ s.email = "ascl@microsoft.com"
35
+ s.description = "Microsoft Azure Storage Common Client Library for Ruby"
36
+ s.summary = "Official Ruby client library to consume Azure Storage Common service"
37
+ s.homepage = "http://github.com/azure/azure-storage-ruby"
38
+ s.license = "MIT"
39
+ s.files = `git ls-files ./lib/azure/storage/common/`.split("\n") << "./lib/azure/storage/common.rb"
40
+ s.files += `git ls-files ./lib/azure/core/`.split("\n") << "./lib/azure/core.rb" << "./lib/azure/http_response_helper.rb"
41
+
42
+ s.required_ruby_version = ">= 2.3.0"
43
+
44
+ s.add_runtime_dependency('faraday', '~> 2.0')
45
+ s.add_runtime_dependency('faraday-follow_redirects','~> 0.3.0')
46
+ s.add_runtime_dependency('faraday-net_http_persistent', '~> 2.0')
47
+ s.add_runtime_dependency("net-http-persistent", '~> 4.0')
48
+ s.add_runtime_dependency("nokogiri", "~> 1", ">= 1.10.8")
49
+ s.add_development_dependency("dotenv", "~> 2.0")
50
+ s.add_development_dependency("minitest", "~> 5")
51
+ s.add_development_dependency("minitest-reporters", "~> 1")
52
+ s.add_development_dependency("mocha", "~> 1.0")
53
+ s.add_development_dependency("rake", "~> 13.0")
54
+ s.add_development_dependency("timecop", "~> 0.7")
55
+ s.add_development_dependency("yard", "~> 0.9", ">= 0.9.11")
56
+ s.add_development_dependency('bundler', '~> 1.11')
57
+ 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,125 @@
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
+ # Need to make sure Content-Length is correctly set.
61
+ if ((!req.body.nil?)) then
62
+ if (req.body.respond_to? :bytesize) then
63
+ req.headers['Content-Length'] = req.body.bytesize.to_s
64
+ elsif (req.body.respond_to? :size)
65
+ req.headers['Content-Length'] = req.body.size.to_s
66
+ end
67
+ end
68
+ req.headers['Authorization'] = "#{name} #{sign(req.method, req.uri, req.headers)}"
69
+ req
70
+ end
71
+
72
+ # Generate the string to sign.
73
+ #
74
+ # @param method [Symbol] HTTP request method.
75
+ # @param uri [URI] URI of the request we're signing.
76
+ # @param headers [Hash] HTTP request headers.
77
+ #
78
+ # @return [String]
79
+ def signable_string(method, uri, headers)
80
+ [
81
+ method.to_s.upcase,
82
+ headers.fetch('Content-Encoding', ''),
83
+ headers.fetch('Content-Language', ''),
84
+ headers.fetch('Content-Length', ''),
85
+ headers.fetch('Content-MD5', ''),
86
+ headers.fetch('Content-Type', ''),
87
+ headers.fetch('Date', ''),
88
+ headers.fetch('If-Modified-Since', ''),
89
+ headers.fetch('If-Match', ''),
90
+ headers.fetch('If-None-Match', ''),
91
+ headers.fetch('If-Unmodified-Since', ''),
92
+ headers.fetch('Range', ''),
93
+ canonicalized_headers(headers),
94
+ canonicalized_resource(uri)
95
+ ].join("\n")
96
+ end
97
+
98
+ # Calculate the Canonicalized Headers string for a request.
99
+ #
100
+ # @param headers [Hash] HTTP request headers.
101
+ #
102
+ # @return [String] a string with the canonicalized headers.
103
+ def canonicalized_headers(headers)
104
+ headers = headers.map { |k,v| [k.to_s.downcase, v] }
105
+ headers.select! { |k,_| k =~ /^x-ms-/ }
106
+ headers.sort_by! { |(k,_)| k }
107
+ headers.map! { |k,v| '%s:%s' % [k, v] }.join("\n")
108
+ end
109
+
110
+ # Calculate the Canonicalized Resource string for a request.
111
+ #
112
+ # @param uri [URI] URI of the request we're signing.
113
+ #
114
+ # @return [String] a string with the canonicalized resource.
115
+ def canonicalized_resource(uri)
116
+ resource = '/' + account_name + (uri.path.empty? ? '/' : uri.path)
117
+ params = CGI.parse(uri.query.to_s).map { |k,v| [k.downcase, v] }
118
+ params.sort_by! { |k,_| k }
119
+ params.map! { |k,v| '%s:%s' % [k, v.map(&:strip).sort.join(',')] }
120
+ [resource, *params].join("\n")
121
+ end
122
+ end
123
+ end
124
+ end
125
+ 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
@@ -0,0 +1,51 @@
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 'openssl'
16
+ require 'base64'
17
+
18
+ module Azure
19
+ module Core
20
+ module Auth
21
+ # Utility class to sign strings with HMAC-256 and then encode the
22
+ # signed string using Base64.
23
+ class Signer
24
+ # The access key for the account
25
+ attr :access_key
26
+
27
+ # Initialize the Signer.
28
+ #
29
+ # @param access_key [String] The access_key encoded in Base64.
30
+ def initialize(access_key)
31
+ if access_key.nil?
32
+ raise ArgumentError, 'Signing key must be provided'
33
+ end
34
+
35
+ @access_key = Base64.decode64(access_key)
36
+ end
37
+
38
+ # Generate an HMAC signature.
39
+ #
40
+ # @param body [String] The string to sign.
41
+ #
42
+ # @return [String] a Base64 String signed with HMAC.
43
+ def sign(body)
44
+ signed = OpenSSL::HMAC.digest('sha256', access_key, body)
45
+ Base64.strict_encode64(signed)
46
+ end
47
+
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,23 @@
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
+ module Azure
17
+ module Core
18
+ module Default
19
+ # Default User Agent header string
20
+ USER_AGENT = "Azure-Core/#{Azure::Core::Version}".freeze
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,21 @@
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
+ module Azure
16
+ module Core
17
+ # Superclass for errors generated from this library, so people can
18
+ # just rescue this for generic error handling
19
+ class Error < StandardError;end
20
+ end
21
+ end
@@ -0,0 +1,45 @@
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/service'
16
+
17
+ module Azure
18
+ module Core
19
+ # A base class for Service implementations
20
+ class FilteredService < Service
21
+
22
+ # Create a new instance of the FilteredService
23
+ #
24
+ # @param host [String] The hostname. (optional, Default empty)
25
+ # @param options [Hash] options including {:client} (optional, Default {})
26
+ def initialize(host='', options={})
27
+ super
28
+ @filters = []
29
+ end
30
+
31
+ attr_accessor :filters
32
+
33
+ def call(method, uri, body=nil, headers=nil, options={})
34
+ super(method, uri, body, headers) do |request|
35
+ filters.reverse.each { |filter| request.with_filter filter, options } if filters
36
+ end
37
+ end
38
+
39
+ def with_filter(filter=nil, &block)
40
+ filter = filter || block
41
+ filters.push filter if filter
42
+ end
43
+ end
44
+ end
45
+ 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/http/http_filter"
16
+
17
+ module Azure
18
+ module Core
19
+ module Http
20
+ # A HttpFilter implementation that displays information about the request and response for debugging
21
+ class DebugFilter < HttpFilter
22
+ def call(req, _next)
23
+ puts "--REQUEST-BEGIN---------------------------"
24
+ puts "method:", req.method, "uri:", req.uri, "headers:", req.headers, "body:", req.body
25
+ puts "--REQUEST-END---------------------------"
26
+
27
+ r = _next.call
28
+ puts "--RESPONSE-BEGIN---------------------------"
29
+ puts "status_code:", r.status_code, "headers:", r.headers, "body:", r.body
30
+ puts "--RESPONSE-END---------------------------"
31
+ r
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,135 @@
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/error'
16
+ require 'nokogiri'
17
+ require 'json'
18
+
19
+ module Azure
20
+ module Core
21
+ module Http
22
+ # Public: Class for handling all HTTP response errors
23
+ class HTTPError < Azure::Core::Error
24
+
25
+ # Public: Detail of the response
26
+ #
27
+ # Returns an Azure::Core::Http::HttpResponse object
28
+ attr :http_response
29
+
30
+ # Public: The request URI
31
+ #
32
+ # Returns a String
33
+ attr :uri
34
+
35
+ # Public: The HTTP status code of this error
36
+ #
37
+ # Returns a Fixnum
38
+ attr :status_code
39
+
40
+ # Public: The type of error
41
+ #
42
+ # http://msdn.microsoft.com/en-us/library/azure/dd179357
43
+ #
44
+ # Returns a String
45
+ attr :type
46
+
47
+ # Public: Description of the error
48
+ #
49
+ # Returns a String
50
+ attr :description
51
+
52
+ # Public: Detail of the error
53
+ #
54
+ # Returns a String
55
+ attr :detail
56
+
57
+ # Public: The header name whose value is invalid
58
+ #
59
+ # Returns a String
60
+ attr :header
61
+
62
+ # Public: The invalid header value
63
+ #
64
+ # Returns a String
65
+ attr :header_value
66
+
67
+ # Public: Initialize an error
68
+ #
69
+ # http_response - An Azure::Core::HttpResponse
70
+ def initialize(http_response)
71
+ @http_response = http_response
72
+ @uri = http_response.uri
73
+ @status_code = http_response.status_code
74
+ parse_response
75
+ # Use reason phrase as the description if description is empty
76
+ @description = http_response.reason_phrase if (@description.nil? || @description.empty?) && http_response.reason_phrase
77
+ super("#{type} (#{status_code}): #{description}")
78
+ end
79
+
80
+ # Extract the relevant information from the response's body. If the response
81
+ # body is not an XML, we return an 'Unknown' error with the entire body as
82
+ # the description
83
+ #
84
+ # Returns nothing
85
+ def parse_response
86
+ if @http_response.body && @http_response.respond_to?(:headers) && @http_response.headers['Content-Type']
87
+ if @http_response.headers['Content-Type'].include?('xml')
88
+ parse_xml_response
89
+ elsif @http_response.headers['Content-Type'].include?('json')
90
+ parse_json_response
91
+ end
92
+ else
93
+ parse_unknown_response
94
+ end
95
+ end
96
+
97
+ def parse_xml_response
98
+ document = Nokogiri.Slop(@http_response.body)
99
+
100
+ @type = document.css('code').first.text if document.css('code').any?
101
+ @type = document.css('Code').first.text if document.css('Code').any?
102
+ @description = document.css('message').first.text if document.css('message').any?
103
+ @description = document.css('Message').first.text if document.css('Message').any?
104
+ @header = document.css('headername').first.text if document.css('headername').any?
105
+ @header = document.css('HeaderName').first.text if document.css('HeaderName').any?
106
+ @header_value = document.css('headervalue').first.text if document.css('headervalue').any?
107
+ @header_value = document.css('HeaderValue').first.text if document.css('HeaderValue').any?
108
+
109
+ # service bus uses detail instead of message
110
+ @detail = document.css('detail').first.text if document.css('detail').any?
111
+ @detail = document.css('Detail').first.text if document.css('Detail').any?
112
+ end
113
+
114
+ def parse_json_response
115
+ odata_error = JSON.parse(@http_response.body)['odata.error']
116
+ @type = odata_error['code']
117
+ @description = odata_error['message']['value']
118
+ end
119
+
120
+ def parse_unknown_response
121
+ @type = 'Unknown'
122
+ if @http_response.body
123
+ @description = "#{@http_response.body.strip}"
124
+ end
125
+ end
126
+
127
+ def inspect
128
+ string = "#<#{self.class.name}:#{self.object_id} "
129
+ fields = self.instance_variables.map{|field| "#{field}: #{self.send(field.to_s.delete("@")).inspect}"}
130
+ string << fields.join(", ") << ">"
131
+ end
132
+ end
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,53 @@
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
+ module Azure
16
+ module Core
17
+ module Http
18
+ # A filter which can modify the HTTP pipeline both before and
19
+ # after requests/responses. Multiple filters can be nested in a
20
+ # "Russian Doll" model to create a compound HTTP pipeline
21
+ class HttpFilter
22
+
23
+ # Initialize a HttpFilter
24
+ #
25
+ # &block - An inline block which implements the filter.
26
+ #
27
+ # The inline block should take parameters |request, _next| where
28
+ # request is a HttpRequest and _next is an object that implements
29
+ # a method .call which returns an HttpResponse. The block passed
30
+ # to the constructor should also return HttpResponse, either as
31
+ # the result of calling _next.call or by customized logic.
32
+ #
33
+ def initialize(&block)
34
+ @block = block
35
+ end
36
+
37
+ # Executes the filter
38
+ #
39
+ # request - HttpRequest. The request
40
+ # _next - An object that implements .call (no params)
41
+ #
42
+ # NOTE: _next is a either a subsequent HttpFilter wrapped in a
43
+ # closure, or the HttpRequest object's call method. Either way,
44
+ # it must have it's .call method executed within each filter to
45
+ # complete the pipeline. _next.call should return an HttpResponse
46
+ # and so should this Filter.
47
+ def call(request, _next)
48
+ @block ? @block.call(request, _next) : _next.call
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end