gitlab-fog-azure-rm 1.9.1 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/.gitlab-ci.yml +1 -1
  3. data/.rubocop.yml +3 -0
  4. data/CHANGELOG.md +19 -0
  5. data/gitlab-fog-azure-rm.gemspec +6 -2
  6. data/lib/azure/core/auth/authorizer.rb +36 -0
  7. data/lib/azure/core/auth/shared_key.rb +125 -0
  8. data/lib/azure/core/auth/shared_key_lite.rb +48 -0
  9. data/lib/azure/core/auth/signer.rb +51 -0
  10. data/lib/azure/core/default.rb +23 -0
  11. data/lib/azure/core/error.rb +21 -0
  12. data/lib/azure/core/filtered_service.rb +45 -0
  13. data/lib/azure/core/http/debug_filter.rb +36 -0
  14. data/lib/azure/core/http/http_error.rb +135 -0
  15. data/lib/azure/core/http/http_filter.rb +53 -0
  16. data/lib/azure/core/http/http_request.rb +195 -0
  17. data/lib/azure/core/http/http_response.rb +102 -0
  18. data/lib/azure/core/http/retry_policy.rb +84 -0
  19. data/lib/azure/core/http/signer_filter.rb +33 -0
  20. data/lib/azure/core/service.rb +46 -0
  21. data/lib/azure/core/signed_service.rb +45 -0
  22. data/lib/azure/core/utility.rb +244 -0
  23. data/lib/azure/core/version.rb +33 -0
  24. data/lib/azure/core.rb +48 -0
  25. data/lib/azure/http_response_helper.rb +38 -0
  26. data/lib/azure/storage/blob/append.rb +244 -0
  27. data/lib/azure/storage/blob/autoload.rb +47 -0
  28. data/lib/azure/storage/blob/blob.rb +932 -0
  29. data/lib/azure/storage/blob/blob_service.rb +720 -0
  30. data/lib/azure/storage/blob/block.rb +530 -0
  31. data/lib/azure/storage/blob/container.rb +634 -0
  32. data/lib/azure/storage/blob/default.rb +171 -0
  33. data/lib/azure/storage/blob/page.rb +566 -0
  34. data/lib/azure/storage/blob/serialization.rb +351 -0
  35. data/lib/azure/storage/blob/version.rb +49 -0
  36. data/lib/azure/storage/blob.rb +26 -0
  37. data/lib/azure/storage/common/autoload.rb +62 -0
  38. data/lib/azure/storage/common/client.rb +162 -0
  39. data/lib/azure/storage/common/client_options.rb +363 -0
  40. data/lib/azure/storage/common/client_options_error.rb +41 -0
  41. data/lib/azure/storage/common/configurable.rb +212 -0
  42. data/lib/azure/storage/common/core/auth/anonymous_signer.rb +43 -0
  43. data/lib/azure/storage/common/core/auth/shared_access_signature.rb +30 -0
  44. data/lib/azure/storage/common/core/auth/shared_access_signature_generator.rb +399 -0
  45. data/lib/azure/storage/common/core/auth/shared_access_signature_signer.rb +57 -0
  46. data/lib/azure/storage/common/core/auth/shared_key.rb +60 -0
  47. data/lib/azure/storage/common/core/auth/token_signer.rb +43 -0
  48. data/lib/azure/storage/common/core/autoload.rb +53 -0
  49. data/lib/azure/storage/common/core/error.rb +43 -0
  50. data/lib/azure/storage/common/core/filter/exponential_retry_filter.rb +64 -0
  51. data/lib/azure/storage/common/core/filter/linear_retry_filter.rb +55 -0
  52. data/lib/azure/storage/common/core/filter/retry_filter.rb +300 -0
  53. data/lib/azure/storage/common/core/http_client.rb +82 -0
  54. data/lib/azure/storage/common/core/sr.rb +85 -0
  55. data/lib/azure/storage/common/core/token_credential.rb +64 -0
  56. data/lib/azure/storage/common/core/utility.rb +261 -0
  57. data/lib/azure/storage/common/core.rb +35 -0
  58. data/lib/azure/storage/common/default.rb +868 -0
  59. data/lib/azure/storage/common/service/access_policy.rb +37 -0
  60. data/lib/azure/storage/common/service/cors.rb +38 -0
  61. data/lib/azure/storage/common/service/cors_rule.rb +48 -0
  62. data/lib/azure/storage/common/service/enumeration_results.rb +32 -0
  63. data/lib/azure/storage/common/service/geo_replication.rb +40 -0
  64. data/lib/azure/storage/common/service/logging.rb +47 -0
  65. data/lib/azure/storage/common/service/metrics.rb +45 -0
  66. data/lib/azure/storage/common/service/retention_policy.rb +37 -0
  67. data/lib/azure/storage/common/service/serialization.rb +335 -0
  68. data/lib/azure/storage/common/service/signed_identifier.rb +40 -0
  69. data/lib/azure/storage/common/service/storage_service.rb +322 -0
  70. data/lib/azure/storage/common/service/storage_service_properties.rb +48 -0
  71. data/lib/azure/storage/common/service/storage_service_stats.rb +39 -0
  72. data/lib/azure/storage/common/service/user_delegation_key.rb +50 -0
  73. data/lib/azure/storage/common/version.rb +49 -0
  74. data/lib/azure/storage/common.rb +26 -0
  75. data/lib/fog/azurerm/version.rb +1 -1
  76. metadata +122 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9e3d095e019cbc998273c882272f179c5490107474e18fe4e723443933136bf7
4
- data.tar.gz: cac7852c0917d11234f0c3aacc99608a7b74e8b1ab47f5ff6532d764503e027b
3
+ metadata.gz: 210f48fcb786a9f8f7c58ddc46cb903cfd66a75756705485a99f28f8ffd53201
4
+ data.tar.gz: 2e97f3af92d4caf1999c89c86247945f7085d247dcc5f8728ccba1b64aea955b
5
5
  SHA512:
6
- metadata.gz: 5432a3edbc3820350aa4e789e066801838883522057e148422f66bff0df632072eecae63431909fc0b406e5d1d82f8f90615583bb7202fbdb7fc75562781ce7d
7
- data.tar.gz: 7f0b8fc9d208def6e9740e298c8cf63386898b7a7e81eddbc8f25ba76ffe59ab6a3dae8752563ac0d1ef5521f7012683275096ae9aadaefce2be34ac5146becf
6
+ metadata.gz: 8e078581d9658e16ac11c8204cc4818217c6c405b68bc0f60394d1f86df179b14312d52ef1918e4a611bd9dd6c1300eae72d84dd36cd43e9857d208fdfcb3521
7
+ data.tar.gz: f279152168a8ee526141d726fe4b2c7d2ecb4b6df2a11b3d632fbad6b048c6dcff6c0fb9ceb9196ea3d52e452805ba08117c7cedc11e46e6e1bd3eeb33020c3e
data/.gitlab-ci.yml CHANGED
@@ -23,7 +23,7 @@ rubocop:
23
23
  script:
24
24
  - bundle exec rubocop
25
25
  variables:
26
- RUBY_VERSION: "2.7"
26
+ RUBY_VERSION: "3.1"
27
27
 
28
28
  integration:
29
29
  services:
data/.rubocop.yml CHANGED
@@ -3,3 +3,6 @@ inherit_from: .rubocop_todo.yml
3
3
  AllCops:
4
4
  NewCops: enable
5
5
  TargetRubyVersion: 2.7
6
+ Exclude:
7
+ - 'lib/azure/**/*'
8
+ - 'vendor/**/*'
data/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  ## Unreleased
2
2
 
3
+ ## 2.0.1
4
+
5
+ - Remove vendor directory and copy files into lib/azure !50
6
+
7
+ ## 2.0.0
8
+
9
+ - Vendor Microsoft Azure gems and upgrade to Faraday 2 !48
10
+
11
+ ## 1.9.1
12
+
13
+ - Duplicate options after modifying it !47
14
+
15
+ ## 1.9.0
16
+
17
+ - Cleanup dead code and tests !41
18
+ - Preserve compressed response bodies when reading blobs !42
19
+ - Add support for using a token signer instead of an account access key !43
20
+ - Support setting Content-Type in pre-signed URLs !44
21
+
3
22
  ## 1.8.0
4
23
 
5
24
  - Remove deprecated ms_rest_azure dependency (thanks to @jasoncodes) !38
@@ -23,9 +23,13 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency 'rubocop', '~> 0.89.1'
24
24
  spec.add_development_dependency 'simplecov'
25
25
  spec.add_development_dependency 'webrick', '~> 1.8'
26
- spec.add_dependency 'azure-storage-blob', '~> 2.0'
27
- spec.add_dependency 'azure-storage-common', '~> 2.0'
26
+
27
+ spec.add_dependency 'faraday', "~> 2.0"
28
+ spec.add_dependency "faraday-follow_redirects", "~> 0.3.0"
29
+ spec.add_dependency "faraday-net_http_persistent", "~> 2.0"
28
30
  spec.add_dependency 'fog-core', '~> 2.1'
29
31
  spec.add_dependency 'fog-json', '~> 1.2'
30
32
  spec.add_dependency 'mime-types'
33
+ spec.add_dependency "net-http-persistent", "~> 4.0"
34
+ spec.add_dependency 'nokogiri', "~> 1", ">= 1.10.8"
31
35
  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