ms_rest 0.7.4 → 0.7.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +46 -46
- data/LICENSE.txt +21 -21
- data/README.md +67 -67
- data/ca-cert.pem +3865 -3865
- data/lib/ms_rest.rb +29 -29
- data/lib/ms_rest/credentials/basic_authentication_credentials.rb +62 -62
- data/lib/ms_rest/credentials/service_client_credentials.rb +22 -22
- data/lib/ms_rest/credentials/string_token_provider.rb +0 -0
- data/lib/ms_rest/credentials/token_credentials.rb +61 -61
- data/lib/ms_rest/credentials/token_provider.rb +19 -19
- data/lib/ms_rest/deserialization_error.rb +43 -43
- data/lib/ms_rest/http_operation_error.rb +72 -72
- data/lib/ms_rest/http_operation_request.rb +135 -135
- data/lib/ms_rest/http_operation_response.rb +37 -37
- data/lib/ms_rest/jsonable.rb +39 -39
- data/lib/ms_rest/rest_error.rb +11 -11
- data/lib/ms_rest/retry_policy_middleware.rb +44 -44
- data/lib/ms_rest/serialization.rb +4 -4
- data/lib/ms_rest/service_client.rb +115 -115
- data/lib/ms_rest/validation_error.rb +11 -11
- data/lib/ms_rest/version.rb +7 -7
- metadata +4 -4
data/lib/ms_rest.rb
CHANGED
@@ -1,29 +1,29 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# Copyright (c) Microsoft Corporation. All rights reserved.
|
3
|
-
# Licensed under the MIT License. See License.txt in the project root for license information.
|
4
|
-
|
5
|
-
require 'base64'
|
6
|
-
require 'openssl'
|
7
|
-
require 'faraday'
|
8
|
-
require 'timeliness'
|
9
|
-
require 'ms_rest/version'
|
10
|
-
|
11
|
-
require 'ms_rest/credentials/token_provider'
|
12
|
-
require 'ms_rest/credentials/string_token_provider'
|
13
|
-
require 'ms_rest/credentials/service_client_credentials'
|
14
|
-
require 'ms_rest/credentials/basic_authentication_credentials'
|
15
|
-
require 'ms_rest/credentials/token_credentials'
|
16
|
-
|
17
|
-
require 'ms_rest/rest_error.rb'
|
18
|
-
require 'ms_rest/deserialization_error.rb'
|
19
|
-
require 'ms_rest/validation_error.rb'
|
20
|
-
require 'ms_rest/serialization.rb'
|
21
|
-
require 'ms_rest/http_operation_response'
|
22
|
-
require 'ms_rest/http_operation_request'
|
23
|
-
require 'ms_rest/http_operation_error'
|
24
|
-
require 'ms_rest/retry_policy_middleware'
|
25
|
-
require 'ms_rest/service_client'
|
26
|
-
require 'ms_rest/jsonable'
|
27
|
-
|
28
|
-
module MsRest end
|
29
|
-
module MsRest::Serialization end
|
1
|
+
# encoding: utf-8
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
3
|
+
# Licensed under the MIT License. See License.txt in the project root for license information.
|
4
|
+
|
5
|
+
require 'base64'
|
6
|
+
require 'openssl'
|
7
|
+
require 'faraday'
|
8
|
+
require 'timeliness'
|
9
|
+
require 'ms_rest/version'
|
10
|
+
|
11
|
+
require 'ms_rest/credentials/token_provider'
|
12
|
+
require 'ms_rest/credentials/string_token_provider'
|
13
|
+
require 'ms_rest/credentials/service_client_credentials'
|
14
|
+
require 'ms_rest/credentials/basic_authentication_credentials'
|
15
|
+
require 'ms_rest/credentials/token_credentials'
|
16
|
+
|
17
|
+
require 'ms_rest/rest_error.rb'
|
18
|
+
require 'ms_rest/deserialization_error.rb'
|
19
|
+
require 'ms_rest/validation_error.rb'
|
20
|
+
require 'ms_rest/serialization.rb'
|
21
|
+
require 'ms_rest/http_operation_response'
|
22
|
+
require 'ms_rest/http_operation_request'
|
23
|
+
require 'ms_rest/http_operation_error'
|
24
|
+
require 'ms_rest/retry_policy_middleware'
|
25
|
+
require 'ms_rest/service_client'
|
26
|
+
require 'ms_rest/jsonable'
|
27
|
+
|
28
|
+
module MsRest end
|
29
|
+
module MsRest::Serialization end
|
@@ -1,62 +1,62 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# Copyright (c) Microsoft Corporation. All rights reserved.
|
3
|
-
# Licensed under the MIT License. See License.txt in the project root for license information.
|
4
|
-
|
5
|
-
module MsRest
|
6
|
-
#
|
7
|
-
# Class which keeps functionality and data for performing HTTP basic authentication.
|
8
|
-
|
9
|
-
#
|
10
|
-
class BasicAuthenticationCredentials < ServiceClientCredentials
|
11
|
-
|
12
|
-
private
|
13
|
-
|
14
|
-
DEFAULT_SCHEME = 'Basic'
|
15
|
-
|
16
|
-
# @return [String] the scheme for composing credentials.
|
17
|
-
attr_accessor :scheme
|
18
|
-
|
19
|
-
# @return [String] the username for authentication.
|
20
|
-
attr_accessor :user_name
|
21
|
-
|
22
|
-
# @return [String] password for authentication.
|
23
|
-
attr_accessor :password
|
24
|
-
|
25
|
-
public
|
26
|
-
|
27
|
-
#
|
28
|
-
# Creates and initialize new instance of the BasicAuthenticationCredentials class.
|
29
|
-
# @param user_name [String] the username for authentication.
|
30
|
-
# @param password [String] the password for authentication.
|
31
|
-
# @param scheme = DEFAULT_SCHEME [String] the scheme for composing credentials.
|
32
|
-
def initialize(user_name, password, scheme = DEFAULT_SCHEME)
|
33
|
-
fail ArgumentError, 'user_name cannot be nil' if user_name.nil?
|
34
|
-
fail ArgumentError, 'password cannot be nil' if password.nil?
|
35
|
-
fail ArgumentError, 'scheme cannot be nil' if scheme.nil?
|
36
|
-
|
37
|
-
@user_name = user_name
|
38
|
-
@password = password
|
39
|
-
@scheme = scheme
|
40
|
-
end
|
41
|
-
|
42
|
-
#
|
43
|
-
# Attaches basic authentication header to the given HTTP request.
|
44
|
-
# @param request [Net::HTTPRequest] the request authentication header needs to be attached to.
|
45
|
-
#
|
46
|
-
# @return [Net::HTTPRequest] request with attached authentication header.
|
47
|
-
def sign_request(request)
|
48
|
-
super(request)
|
49
|
-
encodeCredentials = Base64.strict_encode64("#{user_name}:#{password}")
|
50
|
-
credentials = "#{scheme} #{encodeCredentials}"
|
51
|
-
|
52
|
-
if (request.respond_to?(:request_headers))
|
53
|
-
request.request_headers[AUTHORIZATION] = credentials
|
54
|
-
elsif request.respond_to?(:headers)
|
55
|
-
request.headers[AUTHORIZATION] = credentials
|
56
|
-
else
|
57
|
-
fail ArgumentError, 'Incorrect request object was provided'
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
62
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
3
|
+
# Licensed under the MIT License. See License.txt in the project root for license information.
|
4
|
+
|
5
|
+
module MsRest
|
6
|
+
#
|
7
|
+
# Class which keeps functionality and data for performing HTTP basic authentication.
|
8
|
+
|
9
|
+
#
|
10
|
+
class BasicAuthenticationCredentials < ServiceClientCredentials
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
DEFAULT_SCHEME = 'Basic'
|
15
|
+
|
16
|
+
# @return [String] the scheme for composing credentials.
|
17
|
+
attr_accessor :scheme
|
18
|
+
|
19
|
+
# @return [String] the username for authentication.
|
20
|
+
attr_accessor :user_name
|
21
|
+
|
22
|
+
# @return [String] password for authentication.
|
23
|
+
attr_accessor :password
|
24
|
+
|
25
|
+
public
|
26
|
+
|
27
|
+
#
|
28
|
+
# Creates and initialize new instance of the BasicAuthenticationCredentials class.
|
29
|
+
# @param user_name [String] the username for authentication.
|
30
|
+
# @param password [String] the password for authentication.
|
31
|
+
# @param scheme = DEFAULT_SCHEME [String] the scheme for composing credentials.
|
32
|
+
def initialize(user_name, password, scheme = DEFAULT_SCHEME)
|
33
|
+
fail ArgumentError, 'user_name cannot be nil' if user_name.nil?
|
34
|
+
fail ArgumentError, 'password cannot be nil' if password.nil?
|
35
|
+
fail ArgumentError, 'scheme cannot be nil' if scheme.nil?
|
36
|
+
|
37
|
+
@user_name = user_name
|
38
|
+
@password = password
|
39
|
+
@scheme = scheme
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# Attaches basic authentication header to the given HTTP request.
|
44
|
+
# @param request [Net::HTTPRequest] the request authentication header needs to be attached to.
|
45
|
+
#
|
46
|
+
# @return [Net::HTTPRequest] request with attached authentication header.
|
47
|
+
def sign_request(request)
|
48
|
+
super(request)
|
49
|
+
encodeCredentials = Base64.strict_encode64("#{user_name}:#{password}")
|
50
|
+
credentials = "#{scheme} #{encodeCredentials}"
|
51
|
+
|
52
|
+
if (request.respond_to?(:request_headers))
|
53
|
+
request.request_headers[AUTHORIZATION] = credentials
|
54
|
+
elsif request.respond_to?(:headers)
|
55
|
+
request.headers[AUTHORIZATION] = credentials
|
56
|
+
else
|
57
|
+
fail ArgumentError, 'Incorrect request object was provided'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
@@ -1,22 +1,22 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# Copyright (c) Microsoft Corporation. All rights reserved.
|
3
|
-
# Licensed under the MIT License. See License.txt in the project root for license information.
|
4
|
-
|
5
|
-
module MsRest
|
6
|
-
#
|
7
|
-
# Class that serves as a base for all authentications classes.
|
8
|
-
#
|
9
|
-
class ServiceClientCredentials
|
10
|
-
|
11
|
-
AUTHORIZATION = 'authorization'
|
12
|
-
|
13
|
-
#
|
14
|
-
# Base method for performing authentication of HTTP requests.
|
15
|
-
# @param request [Net::HTTPRequest] HTTP request to authenticate
|
16
|
-
#
|
17
|
-
# @return [Net::HTTPRequest] authenticated HTTP request
|
18
|
-
def sign_request(request)
|
19
|
-
fail ArgumentError, 'request is nil.' if request.nil?
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
3
|
+
# Licensed under the MIT License. See License.txt in the project root for license information.
|
4
|
+
|
5
|
+
module MsRest
|
6
|
+
#
|
7
|
+
# Class that serves as a base for all authentications classes.
|
8
|
+
#
|
9
|
+
class ServiceClientCredentials
|
10
|
+
|
11
|
+
AUTHORIZATION = 'authorization'
|
12
|
+
|
13
|
+
#
|
14
|
+
# Base method for performing authentication of HTTP requests.
|
15
|
+
# @param request [Net::HTTPRequest] HTTP request to authenticate
|
16
|
+
#
|
17
|
+
# @return [Net::HTTPRequest] authenticated HTTP request
|
18
|
+
def sign_request(request)
|
19
|
+
fail ArgumentError, 'request is nil.' if request.nil?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
File without changes
|
@@ -1,61 +1,61 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# Copyright (c) Microsoft Corporation. All rights reserved.
|
3
|
-
# Licensed under the MIT License. See License.txt in the project root for license information.
|
4
|
-
|
5
|
-
module MsRest
|
6
|
-
#
|
7
|
-
# Class which keeps functionality and date for performing OAuth (token based) authentication.
|
8
|
-
#
|
9
|
-
class TokenCredentials < ServiceClientCredentials
|
10
|
-
|
11
|
-
private
|
12
|
-
|
13
|
-
DEFAULT_SCHEME = 'Bearer'
|
14
|
-
|
15
|
-
# @return [String] the scheme for arranging token in the HTTP header.
|
16
|
-
attr_accessor :token_provider
|
17
|
-
|
18
|
-
public
|
19
|
-
|
20
|
-
#
|
21
|
-
# Creates and initialize new instance of the TokenCredentials class.
|
22
|
-
# @param token_provider [TokenProvider] the token provider.
|
23
|
-
# @param token [String] the token.
|
24
|
-
def initialize(*args)
|
25
|
-
if (args.size == 1)
|
26
|
-
if args[0].respond_to? :get_authentication_header
|
27
|
-
@token_provider = args[0]
|
28
|
-
elsif args[0].is_a? String
|
29
|
-
@token_provider = StringTokenProvider.new args[0], DEFAULT_SCHEME
|
30
|
-
else
|
31
|
-
fail ArgumentError, 'Invalid argument was passed, is can be either TokenProvider or token'
|
32
|
-
end
|
33
|
-
elsif (args.size == 2)
|
34
|
-
token = args[0]
|
35
|
-
token_type = args[1]
|
36
|
-
@token_provider = StringTokenProvider.new token, token_type
|
37
|
-
else
|
38
|
-
fail ArgumentError, 'Invalid number of parameters was passed to TokenCredentials constructor, valid number is 1 or 2'
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
#
|
43
|
-
# Attaches OAuth authentication header to the given HTTP request.
|
44
|
-
# @param request [Net::HTTPRequest] the request authentication header needs to be attached to.
|
45
|
-
#
|
46
|
-
# @return [Net::HTTPRequest] request with attached authentication header
|
47
|
-
def sign_request(request)
|
48
|
-
super(request)
|
49
|
-
header = @token_provider.get_authentication_header
|
50
|
-
|
51
|
-
if (request.respond_to?(:request_headers))
|
52
|
-
request.request_headers[AUTHORIZATION] = header
|
53
|
-
elsif request.respond_to?(:headers)
|
54
|
-
request.headers[AUTHORIZATION] = header
|
55
|
-
else
|
56
|
-
fail ArgumentError, 'Incorrect request object was provided'
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
end
|
61
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
3
|
+
# Licensed under the MIT License. See License.txt in the project root for license information.
|
4
|
+
|
5
|
+
module MsRest
|
6
|
+
#
|
7
|
+
# Class which keeps functionality and date for performing OAuth (token based) authentication.
|
8
|
+
#
|
9
|
+
class TokenCredentials < ServiceClientCredentials
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
DEFAULT_SCHEME = 'Bearer'
|
14
|
+
|
15
|
+
# @return [String] the scheme for arranging token in the HTTP header.
|
16
|
+
attr_accessor :token_provider
|
17
|
+
|
18
|
+
public
|
19
|
+
|
20
|
+
#
|
21
|
+
# Creates and initialize new instance of the TokenCredentials class.
|
22
|
+
# @param token_provider [TokenProvider] the token provider.
|
23
|
+
# @param token [String] the token.
|
24
|
+
def initialize(*args)
|
25
|
+
if (args.size == 1)
|
26
|
+
if args[0].respond_to? :get_authentication_header
|
27
|
+
@token_provider = args[0]
|
28
|
+
elsif args[0].is_a? String
|
29
|
+
@token_provider = StringTokenProvider.new args[0], DEFAULT_SCHEME
|
30
|
+
else
|
31
|
+
fail ArgumentError, 'Invalid argument was passed, is can be either TokenProvider or token'
|
32
|
+
end
|
33
|
+
elsif (args.size == 2)
|
34
|
+
token = args[0]
|
35
|
+
token_type = args[1]
|
36
|
+
@token_provider = StringTokenProvider.new token, token_type
|
37
|
+
else
|
38
|
+
fail ArgumentError, 'Invalid number of parameters was passed to TokenCredentials constructor, valid number is 1 or 2'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# Attaches OAuth authentication header to the given HTTP request.
|
44
|
+
# @param request [Net::HTTPRequest] the request authentication header needs to be attached to.
|
45
|
+
#
|
46
|
+
# @return [Net::HTTPRequest] request with attached authentication header
|
47
|
+
def sign_request(request)
|
48
|
+
super(request)
|
49
|
+
header = @token_provider.get_authentication_header
|
50
|
+
|
51
|
+
if (request.respond_to?(:request_headers))
|
52
|
+
request.request_headers[AUTHORIZATION] = header
|
53
|
+
elsif request.respond_to?(:headers)
|
54
|
+
request.headers[AUTHORIZATION] = header
|
55
|
+
else
|
56
|
+
fail ArgumentError, 'Incorrect request object was provided'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
@@ -1,19 +1,19 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# Copyright (c) Microsoft Corporation. All rights reserved.
|
3
|
-
# Licensed under the MIT License. See License.txt in the project root for license information.
|
4
|
-
|
5
|
-
module MsRest
|
6
|
-
#
|
7
|
-
# Class that provides access to authentication token.
|
8
|
-
#
|
9
|
-
class TokenProvider
|
10
|
-
|
11
|
-
#
|
12
|
-
# Returns the string value which needs to be attached
|
13
|
-
# to HTTP request header in order to be authorized.
|
14
|
-
#
|
15
|
-
# @return [String] authentication headers.
|
16
|
-
def get_authentication_header
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
3
|
+
# Licensed under the MIT License. See License.txt in the project root for license information.
|
4
|
+
|
5
|
+
module MsRest
|
6
|
+
#
|
7
|
+
# Class that provides access to authentication token.
|
8
|
+
#
|
9
|
+
class TokenProvider
|
10
|
+
|
11
|
+
#
|
12
|
+
# Returns the string value which needs to be attached
|
13
|
+
# to HTTP request header in order to be authorized.
|
14
|
+
#
|
15
|
+
# @return [String] authentication headers.
|
16
|
+
def get_authentication_header
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,43 +1,43 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# Copyright (c) Microsoft Corporation. All rights reserved.
|
3
|
-
# Licensed under the MIT License. See License.txt in the project root for license information.
|
4
|
-
require 'json'
|
5
|
-
|
6
|
-
module MsRest
|
7
|
-
#
|
8
|
-
# Class which represents an error happening during deserialization of server response.
|
9
|
-
#
|
10
|
-
class DeserializationError < RestError
|
11
|
-
|
12
|
-
# @return [String] the inner exception message.
|
13
|
-
attr_accessor :exception_message
|
14
|
-
|
15
|
-
# @return [String] the inner exception stacktrace.
|
16
|
-
attr_accessor :exception_stacktrace
|
17
|
-
|
18
|
-
# @return [MsRest::HttpOperationResponse] server response which client was unable to parse.
|
19
|
-
attr_accessor :result
|
20
|
-
|
21
|
-
#
|
22
|
-
# Creates and initialize new instance of the DeserializationError class.
|
23
|
-
# @param [String] message message the human readable description of error.
|
24
|
-
# @param [String] exception_message the inner exception stacktrace.
|
25
|
-
# @param [String] exception_stacktrace the inner exception stacktrace.
|
26
|
-
# @param [MsRest::HttpOperationResponse] the request and response
|
27
|
-
def initialize(msg, exception_message, exception_stacktrace, result)
|
28
|
-
@msg = msg || self.class.name
|
29
|
-
@exception_message = exception_message
|
30
|
-
@exception_stacktrace = exception_stacktrace
|
31
|
-
@result = result
|
32
|
-
end
|
33
|
-
|
34
|
-
def to_json(*a)
|
35
|
-
{exception_message: exception_message, message: @msg, stacktrace: exception_stacktrace, result: result}.to_json(*a)
|
36
|
-
end
|
37
|
-
|
38
|
-
def to_s
|
39
|
-
JSON.pretty_generate(self)
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
3
|
+
# Licensed under the MIT License. See License.txt in the project root for license information.
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module MsRest
|
7
|
+
#
|
8
|
+
# Class which represents an error happening during deserialization of server response.
|
9
|
+
#
|
10
|
+
class DeserializationError < RestError
|
11
|
+
|
12
|
+
# @return [String] the inner exception message.
|
13
|
+
attr_accessor :exception_message
|
14
|
+
|
15
|
+
# @return [String] the inner exception stacktrace.
|
16
|
+
attr_accessor :exception_stacktrace
|
17
|
+
|
18
|
+
# @return [MsRest::HttpOperationResponse] server response which client was unable to parse.
|
19
|
+
attr_accessor :result
|
20
|
+
|
21
|
+
#
|
22
|
+
# Creates and initialize new instance of the DeserializationError class.
|
23
|
+
# @param [String] message message the human readable description of error.
|
24
|
+
# @param [String] exception_message the inner exception stacktrace.
|
25
|
+
# @param [String] exception_stacktrace the inner exception stacktrace.
|
26
|
+
# @param [MsRest::HttpOperationResponse] the request and response
|
27
|
+
def initialize(msg, exception_message, exception_stacktrace, result)
|
28
|
+
@msg = msg || self.class.name
|
29
|
+
@exception_message = exception_message
|
30
|
+
@exception_stacktrace = exception_stacktrace
|
31
|
+
@result = result
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_json(*a)
|
35
|
+
{exception_message: exception_message, message: @msg, stacktrace: exception_stacktrace, result: result}.to_json(*a)
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_s
|
39
|
+
JSON.pretty_generate(self)
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|