azure-storage-common 1.1.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/azure/core.rb +47 -0
- data/lib/azure/core/auth/authorizer.rb +36 -0
- data/lib/azure/core/auth/shared_key.rb +125 -0
- data/lib/azure/core/auth/shared_key_lite.rb +48 -0
- data/lib/azure/core/auth/signer.rb +51 -0
- data/lib/azure/core/default.rb +23 -0
- data/lib/azure/core/error.rb +21 -0
- data/lib/azure/core/filtered_service.rb +45 -0
- data/lib/azure/core/http/debug_filter.rb +36 -0
- data/lib/azure/core/http/http_error.rb +135 -0
- data/lib/azure/core/http/http_filter.rb +53 -0
- data/lib/azure/core/http/http_request.rb +194 -0
- data/lib/azure/core/http/http_response.rb +102 -0
- data/lib/azure/core/http/retry_policy.rb +84 -0
- data/lib/azure/core/http/signer_filter.rb +33 -0
- data/lib/azure/core/service.rb +46 -0
- data/lib/azure/core/signed_service.rb +45 -0
- data/lib/azure/core/utility.rb +244 -0
- data/lib/azure/core/version.rb +33 -0
- data/lib/azure/http_response_helper.rb +38 -0
- data/lib/azure/storage/common.rb +26 -26
- data/lib/azure/storage/common/autoload.rb +62 -61
- data/lib/azure/storage/common/client.rb +162 -162
- data/lib/azure/storage/common/client_options.rb +363 -363
- data/lib/azure/storage/common/client_options_error.rb +41 -41
- data/lib/azure/storage/common/configurable.rb +212 -212
- data/lib/azure/storage/common/core.rb +35 -35
- data/lib/azure/storage/common/core/auth/anonymous_signer.rb +43 -43
- data/lib/azure/storage/common/core/auth/shared_access_signature.rb +30 -30
- data/lib/azure/storage/common/core/auth/shared_access_signature_generator.rb +399 -352
- data/lib/azure/storage/common/core/auth/shared_access_signature_signer.rb +57 -57
- data/lib/azure/storage/common/core/auth/shared_key.rb +60 -60
- data/lib/azure/storage/common/core/auth/token_signer.rb +43 -43
- data/lib/azure/storage/common/core/autoload.rb +53 -53
- data/lib/azure/storage/common/core/error.rb +43 -43
- data/lib/azure/storage/common/core/filter/exponential_retry_filter.rb +64 -64
- data/lib/azure/storage/common/core/filter/linear_retry_filter.rb +55 -55
- data/lib/azure/storage/common/core/filter/retry_filter.rb +300 -300
- data/lib/azure/storage/common/core/http_client.rb +79 -69
- data/lib/azure/storage/common/core/sr.rb +85 -85
- data/lib/azure/storage/common/core/token_credential.rb +64 -64
- data/lib/azure/storage/common/core/utility.rb +255 -255
- data/lib/azure/storage/common/default.rb +868 -868
- data/lib/azure/storage/common/service/access_policy.rb +37 -37
- data/lib/azure/storage/common/service/cors.rb +38 -38
- data/lib/azure/storage/common/service/cors_rule.rb +48 -48
- data/lib/azure/storage/common/service/enumeration_results.rb +32 -32
- data/lib/azure/storage/common/service/geo_replication.rb +40 -40
- data/lib/azure/storage/common/service/logging.rb +47 -47
- data/lib/azure/storage/common/service/metrics.rb +45 -45
- data/lib/azure/storage/common/service/retention_policy.rb +37 -37
- data/lib/azure/storage/common/service/serialization.rb +335 -335
- data/lib/azure/storage/common/service/signed_identifier.rb +40 -40
- data/lib/azure/storage/common/service/storage_service.rb +322 -322
- data/lib/azure/storage/common/service/storage_service_properties.rb +48 -48
- data/lib/azure/storage/common/service/storage_service_stats.rb +39 -39
- data/lib/azure/storage/common/service/user_delegation_key.rb +50 -0
- data/lib/azure/storage/common/version.rb +49 -49
- metadata +60 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7452db26abde9be86812725e1b5e404bb6e516f87b91998bfc5fd947eac8c83f
|
4
|
+
data.tar.gz: f95cc3f2014cbef0e77e268d6f609ef13204ccad8d081dd22060cb47fa54a3af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d28194e508f11824e00131a0efa398caa590273b36dea55fbc8935880a643c3ad68428658629a3eed92aaf8599d4d9c503f0fc13d244c264741e3280e5cb01e3
|
7
|
+
data.tar.gz: ce4a878c07971a45bce0b8f1e436ac097aa0f9ba2ead1a18d9d5bef6ce40582cce0ae302e1e3ee9a099a07fd8c7ff02ff89cd7ef426c189bcb18c4da88ff0b2c
|
data/lib/azure/core.rb
ADDED
@@ -0,0 +1,47 @@
|
|
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
|
+
module Auth
|
31
|
+
autoload :SharedKey, 'azure/core/auth/shared_key'
|
32
|
+
autoload :Signer, 'azure/core/auth/signer'
|
33
|
+
autoload :Authorizer, 'azure/core/auth/authorizer'
|
34
|
+
autoload :SharedKeyLite, 'azure/core/auth/shared_key_lite'
|
35
|
+
end
|
36
|
+
module Http
|
37
|
+
autoload :DebugFilter, 'azure/core/http/debug_filter'
|
38
|
+
autoload :HTTPError, 'azure/core/http/http_error'
|
39
|
+
autoload :HttpFilter, 'azure/core/http/http_filter'
|
40
|
+
autoload :HttpRequest, 'azure/core/http/http_request'
|
41
|
+
autoload :HttpResponse, 'azure/core/http/http_response'
|
42
|
+
autoload :RetryPolicy, 'azure/core/http/retry_policy'
|
43
|
+
autoload :SignerFilter, 'azure/core/http/signer_filter'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
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
|