microsoft_kiota_abstractions 0.25.2 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/microsoft_kiota_abstractions/authentication/allowed_hosts_validator.rb +38 -7
- data/lib/microsoft_kiota_abstractions/authentication/base_bearer_token_authentication_provider.rb +28 -2
- data/lib/microsoft_kiota_abstractions/request_headers.rb +49 -14
- data/lib/microsoft_kiota_abstractions/request_information.rb +16 -7
- data/lib/microsoft_kiota_abstractions/serialization/parse_node_factory_registry.rb +5 -5
- data/lib/microsoft_kiota_abstractions/serialization/serialization_writer_factory_registry.rb +4 -4
- data/lib/microsoft_kiota_abstractions/version.rb +1 -1
- data/microsoft_kiota_abstractions.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6c50ee601efebfe772b5db15f70dab16639280ceff867bf6c3738d1efe32fe8c
|
|
4
|
+
data.tar.gz: 6c836c49bd80738c93ac3b11274979b1036490d9f86ea955a9656988f859c66e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2480624018e4c17ddb67b0d8c11ff781c9385ce976e8a9ae1fc6ad03c06d25da9aec3d3c426f8f21302e27b81cdc75983277bb3a92b70fd83c2f7282bf48884d
|
|
7
|
+
data.tar.gz: e475b25ed724dc7ff768c646b593e248cf90628333420879c6c1dbcdfb430e2485bd5b793c61a1d06bbc02d4132a5d98eadc91d3a835210090c43586d6a4edef
|
|
@@ -4,32 +4,63 @@ require 'uri'
|
|
|
4
4
|
|
|
5
5
|
module MicrosoftKiotaAbstractions
|
|
6
6
|
# Maintains a list of valid hosts and allows authentication providers to check whether
|
|
7
|
-
# a host is valid before authenticating a request
|
|
7
|
+
# a host is valid before authenticating a request.
|
|
8
|
+
#
|
|
9
|
+
# @note Passing +nil+ or an empty collection explicitly enables allow-all semantics for HTTPS hosts,
|
|
10
|
+
# disabling host restriction checks.
|
|
8
11
|
class AllowedHostsValidator
|
|
9
12
|
LOCALHOST_STRINGS = ['localhost', '::1', '[::1]', '127.0.0.1'].freeze
|
|
10
13
|
|
|
11
|
-
# creates a new
|
|
14
|
+
# creates a new AllowedHostsValidator with provided values
|
|
15
|
+
#
|
|
16
|
+
# @param allowed_hosts [Enumerable, nil] collection of valid hosts. If nil or empty, allow-all semantics are enabled.
|
|
12
17
|
def initialize(allowed_hosts)
|
|
13
18
|
self.allowed_hosts = allowed_hosts
|
|
14
19
|
end
|
|
15
20
|
|
|
16
21
|
# sets the list of valid hosts with provided value (val)
|
|
22
|
+
#
|
|
23
|
+
# @note Passing +nil+ or an empty collection explicitly enables allow-all semantics for HTTPS hosts,
|
|
24
|
+
# disabling host restriction checks.
|
|
25
|
+
# @param val [Enumerable, nil] collection of valid hosts.
|
|
17
26
|
def allowed_hosts=(val)
|
|
27
|
+
if val.nil?
|
|
28
|
+
@allowed_hosts = {}
|
|
29
|
+
return
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
raise ArgumentError, 'allowed_hosts cannot be a string' if val.is_a?(String)
|
|
33
|
+
raise ArgumentError, 'allowed_hosts must be an Enumerable collection or nil' unless val.respond_to?(:each)
|
|
34
|
+
|
|
35
|
+
elements = val.to_a
|
|
36
|
+
if elements.empty?
|
|
37
|
+
@allowed_hosts = {}
|
|
38
|
+
return
|
|
39
|
+
end
|
|
40
|
+
|
|
18
41
|
hosts = {}
|
|
19
|
-
|
|
20
|
-
|
|
42
|
+
elements.each do |host|
|
|
43
|
+
next if host.nil?
|
|
21
44
|
|
|
22
|
-
|
|
45
|
+
cleaned = host.to_s.strip
|
|
46
|
+
next if cleaned.empty?
|
|
47
|
+
|
|
48
|
+
raise ArgumentError, "host should not contain http or https prefix: #{cleaned}" if cleaned.match?(%r{\Ahttps?://}i)
|
|
49
|
+
|
|
50
|
+
hosts[cleaned.downcase] = true
|
|
23
51
|
end
|
|
52
|
+
|
|
53
|
+
raise ArgumentError, 'allowed_hosts must contain at least one valid host when provided as a non-empty list' if hosts.empty?
|
|
54
|
+
|
|
24
55
|
@allowed_hosts = hosts
|
|
25
56
|
end
|
|
26
57
|
|
|
27
58
|
# checks whether the provided host is valid
|
|
28
59
|
def url_host_valid?(url)
|
|
29
|
-
return false if url.nil?
|
|
60
|
+
return false if url.nil? || (url.respond_to?(:empty?) && url.empty?)
|
|
30
61
|
|
|
31
62
|
begin
|
|
32
|
-
parsed_url = URI(url)
|
|
63
|
+
parsed_url = URI(url.respond_to?(:strip) ? url.strip : url)
|
|
33
64
|
rescue URI::InvalidURIError, ArgumentError
|
|
34
65
|
return false
|
|
35
66
|
end
|
data/lib/microsoft_kiota_abstractions/authentication/base_bearer_token_authentication_provider.rb
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative 'authentication_provider'
|
|
4
4
|
require_relative 'access_token_provider'
|
|
5
|
+
require_relative '../request_headers'
|
|
5
6
|
|
|
6
7
|
module MicrosoftKiotaAbstractions
|
|
7
8
|
# Provides a base class for implementing AuthenticationProvider for Bearer token scheme
|
|
@@ -19,16 +20,41 @@ module MicrosoftKiotaAbstractions
|
|
|
19
20
|
raise StandardError, 'Request cannot be null' if request.nil?
|
|
20
21
|
|
|
21
22
|
# If request contains already an authorization header, nothing needs to be done.
|
|
22
|
-
if request.headers.
|
|
23
|
+
has_auth_header = if request.headers.respond_to?(:key?)
|
|
24
|
+
request.headers.key?(AUTHORIZATION_HEADER_KEY)
|
|
25
|
+
elsif request.headers.respond_to?(:get_all) && request.headers.get_all
|
|
26
|
+
request.headers.get_all.keys.any? { |k| k.to_s.casecmp?(AUTHORIZATION_HEADER_KEY) }
|
|
27
|
+
else
|
|
28
|
+
false
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
if has_auth_header
|
|
23
32
|
Fiber.new do
|
|
24
33
|
end
|
|
25
34
|
else
|
|
26
35
|
Fiber.new do
|
|
27
36
|
auth_fiber = @access_token_provider.get_authorization_token(request.uri, additional_properties)
|
|
28
37
|
token = auth_fiber.resume if auth_fiber
|
|
29
|
-
|
|
38
|
+
unless token.nil? || token.empty?
|
|
39
|
+
headers = ensure_request_headers(request)
|
|
40
|
+
headers.add(AUTHORIZATION_HEADER_KEY, "Bearer #{token}")
|
|
41
|
+
end
|
|
30
42
|
end
|
|
31
43
|
end
|
|
32
44
|
end
|
|
45
|
+
|
|
46
|
+
private
|
|
47
|
+
|
|
48
|
+
def ensure_request_headers(request)
|
|
49
|
+
return request.headers unless request.headers.nil?
|
|
50
|
+
|
|
51
|
+
headers = RequestHeaders.new
|
|
52
|
+
if request.respond_to?(:headers=)
|
|
53
|
+
request.headers = headers
|
|
54
|
+
elsif request.instance_variable_defined?(:@headers)
|
|
55
|
+
request.instance_variable_set(:@headers, headers)
|
|
56
|
+
end
|
|
57
|
+
headers
|
|
58
|
+
end
|
|
33
59
|
end
|
|
34
60
|
end
|
|
@@ -7,46 +7,60 @@ module MicrosoftKiotaAbstractions
|
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
def add(key, value)
|
|
10
|
-
if key.nil? || key.empty? || value.nil? || value.empty?
|
|
10
|
+
if key.nil? || key.to_s.empty? || value.nil? || (value.respond_to?(:empty?) && value.empty?)
|
|
11
11
|
raise ArgumentError, 'key and value cannot be nil or empty'
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
key = key.to_s
|
|
15
|
+
existing_key = find_key(key)
|
|
16
|
+
if existing_key.nil?
|
|
16
17
|
@headers[key] = if value.is_a?(Array)
|
|
17
|
-
value
|
|
18
|
+
value.map(&:to_s)
|
|
18
19
|
else
|
|
19
20
|
[value.to_s]
|
|
20
21
|
end
|
|
21
22
|
elsif value.is_a?(Array)
|
|
22
|
-
@headers[
|
|
23
|
+
@headers[existing_key] = @headers[existing_key] | value.map(&:to_s)
|
|
23
24
|
else
|
|
24
|
-
|
|
25
|
+
@headers[existing_key] = @headers[existing_key] | [value.to_s]
|
|
25
26
|
end
|
|
26
27
|
end
|
|
27
28
|
|
|
28
29
|
def try_add(key, value)
|
|
29
|
-
if key.nil? || key.empty? || value.nil? || value.empty?
|
|
30
|
+
if key.nil? || key.to_s.empty? || value.nil? || (value.respond_to?(:empty?) && value.empty?)
|
|
30
31
|
raise ArgumentError, 'key and value cannot be nil or empty'
|
|
31
32
|
end
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
key = key.to_s
|
|
35
|
+
existing_key = find_key(key)
|
|
36
|
+
return false if existing_key && !@headers[existing_key].empty?
|
|
35
37
|
|
|
36
|
-
@headers[key] =
|
|
38
|
+
@headers[existing_key || key] = if value.is_a?(Array)
|
|
39
|
+
value.map(&:to_s)
|
|
40
|
+
else
|
|
41
|
+
[value.to_s]
|
|
42
|
+
end
|
|
37
43
|
true
|
|
38
44
|
end
|
|
39
45
|
|
|
40
46
|
def get(key)
|
|
41
|
-
raise ArgumentError, 'key cannot be nil or empty' if key.nil? || key.empty?
|
|
47
|
+
raise ArgumentError, 'key cannot be nil or empty' if key.nil? || key.to_s.empty?
|
|
42
48
|
|
|
43
|
-
|
|
49
|
+
existing_key = find_key(key.to_s)
|
|
50
|
+
existing_key ? @headers[existing_key] : nil
|
|
44
51
|
end
|
|
45
52
|
|
|
46
53
|
def remove(key)
|
|
47
|
-
raise ArgumentError, 'key cannot be nil or empty' if key.nil? || key.empty?
|
|
54
|
+
raise ArgumentError, 'key cannot be nil or empty' if key.nil? || key.to_s.empty?
|
|
48
55
|
|
|
49
|
-
|
|
56
|
+
existing_key = find_key(key.to_s)
|
|
57
|
+
@headers.delete(existing_key) if existing_key
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def key?(key)
|
|
61
|
+
return false if key.nil? || key.to_s.empty?
|
|
62
|
+
|
|
63
|
+
!find_key(key.to_s).nil?
|
|
50
64
|
end
|
|
51
65
|
|
|
52
66
|
def clear
|
|
@@ -56,5 +70,26 @@ module MicrosoftKiotaAbstractions
|
|
|
56
70
|
def get_all
|
|
57
71
|
@headers
|
|
58
72
|
end
|
|
73
|
+
|
|
74
|
+
def add_all(other)
|
|
75
|
+
return if other.nil?
|
|
76
|
+
|
|
77
|
+
if other.respond_to?(:get_all)
|
|
78
|
+
other.get_all.each { |k, v| add(k.to_s, v) }
|
|
79
|
+
elsif other.is_a?(Hash)
|
|
80
|
+
other.each { |k, v| add(k.to_s, v) }
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
private
|
|
85
|
+
|
|
86
|
+
def find_key(key)
|
|
87
|
+
return key if @headers.key?(key)
|
|
88
|
+
|
|
89
|
+
key_str = key.to_s
|
|
90
|
+
return key_str if @headers.key?(key_str)
|
|
91
|
+
|
|
92
|
+
@headers.keys.find { |k| k.to_s.casecmp?(key_str) }
|
|
93
|
+
end
|
|
59
94
|
end
|
|
60
95
|
end
|
|
@@ -10,7 +10,8 @@ require_relative 'request_headers'
|
|
|
10
10
|
|
|
11
11
|
module MicrosoftKiotaAbstractions
|
|
12
12
|
class RequestInformation
|
|
13
|
-
attr_reader :content, :http_method
|
|
13
|
+
attr_reader :content, :http_method
|
|
14
|
+
attr_writer :headers
|
|
14
15
|
attr_accessor :url_template, :path_parameters, :query_parameters
|
|
15
16
|
|
|
16
17
|
@@binary_content_type = 'application/octet-stream'
|
|
@@ -23,6 +24,10 @@ module MicrosoftKiotaAbstractions
|
|
|
23
24
|
@path_parameters = {}
|
|
24
25
|
end
|
|
25
26
|
|
|
27
|
+
def headers
|
|
28
|
+
@headers ||= RequestHeaders.new
|
|
29
|
+
end
|
|
30
|
+
|
|
26
31
|
def uri=(arg)
|
|
27
32
|
raise ArgumentError, 'arg cannot be nil or empty' if arg.nil? || arg.empty?
|
|
28
33
|
|
|
@@ -35,6 +40,8 @@ module MicrosoftKiotaAbstractions
|
|
|
35
40
|
return @uri unless @uri.nil?
|
|
36
41
|
|
|
37
42
|
if path_parameters[@@raw_url_key].nil?
|
|
43
|
+
raise StandardError, 'url_template cannot be nil or empty' if @url_template.nil? || @url_template.empty?
|
|
44
|
+
|
|
38
45
|
values = path_parameters.merge(query_parameters).transform_values { |v| template_value(v) }
|
|
39
46
|
return URI(StdUriTemplate.expand(@url_template, values))
|
|
40
47
|
end
|
|
@@ -82,7 +89,7 @@ module MicrosoftKiotaAbstractions
|
|
|
82
89
|
def set_stream_content(value = $stdin, content_type)
|
|
83
90
|
@content = value
|
|
84
91
|
content_type = @@binary_content_type if content_type.nil? || content_type.empty?
|
|
85
|
-
|
|
92
|
+
headers.try_add(@@content_type_header, content_type)
|
|
86
93
|
end
|
|
87
94
|
|
|
88
95
|
SCALAR_WRITERS = {
|
|
@@ -101,7 +108,7 @@ module MicrosoftKiotaAbstractions
|
|
|
101
108
|
|
|
102
109
|
def set_content_from_scalar(request_adapter, content_type, values)
|
|
103
110
|
writer = request_adapter.get_serialization_writer_factory.get_serialization_writer(content_type)
|
|
104
|
-
|
|
111
|
+
headers.try_add(@@content_type_header, content_type)
|
|
105
112
|
if values.is_a?(Array)
|
|
106
113
|
writer.write_collection_of_primitive_values(nil, values)
|
|
107
114
|
else
|
|
@@ -118,9 +125,9 @@ module MicrosoftKiotaAbstractions
|
|
|
118
125
|
if values.is_a?(MultipartBody)
|
|
119
126
|
content_type = "#{content_type.gsub(/;\s*boundary=[^;]*/i, '')}; boundary=#{values.boundary}"
|
|
120
127
|
values.request_adapter = request_adapter
|
|
121
|
-
|
|
128
|
+
headers.remove(@@content_type_header)
|
|
122
129
|
end
|
|
123
|
-
|
|
130
|
+
headers.try_add(@@content_type_header, content_type)
|
|
124
131
|
if !values.nil? && values.is_a?(Array)
|
|
125
132
|
writer.write_collection_of_object_values(nil, values)
|
|
126
133
|
else
|
|
@@ -130,7 +137,9 @@ module MicrosoftKiotaAbstractions
|
|
|
130
137
|
end
|
|
131
138
|
|
|
132
139
|
def add_headers_from_raw_object(h)
|
|
133
|
-
|
|
140
|
+
return if h.nil?
|
|
141
|
+
|
|
142
|
+
headers.add_all(h)
|
|
134
143
|
end
|
|
135
144
|
|
|
136
145
|
def set_query_string_parameters_from_raw_object(q)
|
|
@@ -147,7 +156,7 @@ module MicrosoftKiotaAbstractions
|
|
|
147
156
|
rescue StandardError
|
|
148
157
|
key = method_name
|
|
149
158
|
end
|
|
150
|
-
value =
|
|
159
|
+
value = q.public_send(x)
|
|
151
160
|
query_parameters[key] = value unless value.nil?
|
|
152
161
|
end
|
|
153
162
|
end
|
|
@@ -21,15 +21,15 @@ module MicrosoftKiotaAbstractions
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def get_parse_node(content_type, content)
|
|
24
|
-
raise
|
|
25
|
-
raise
|
|
24
|
+
raise ArgumentError, 'content type cannot be undefined or empty' if content_type.nil? || content_type.strip.empty?
|
|
25
|
+
raise ArgumentError, 'content cannot be undefined or empty' if content.nil? || (content.respond_to?(:empty?) && content.empty?)
|
|
26
26
|
|
|
27
|
-
vendor_specific_content_type = content_type.split(';').first
|
|
28
|
-
factory =
|
|
27
|
+
vendor_specific_content_type = content_type.split(';').first.strip
|
|
28
|
+
factory = content_type_associated_factories[vendor_specific_content_type]
|
|
29
29
|
return factory.get_parse_node(vendor_specific_content_type, content) if factory
|
|
30
30
|
|
|
31
31
|
clean_content_type = get_clean_content_type(vendor_specific_content_type)
|
|
32
|
-
factory =
|
|
32
|
+
factory = content_type_associated_factories[clean_content_type]
|
|
33
33
|
return factory.get_parse_node(clean_content_type, content) if factory
|
|
34
34
|
|
|
35
35
|
raise StandardError, "Content type #{content_type} does not have a factory to be parsed"
|
data/lib/microsoft_kiota_abstractions/serialization/serialization_writer_factory_registry.rb
CHANGED
|
@@ -21,14 +21,14 @@ module MicrosoftKiotaAbstractions
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def get_serialization_writer(content_type)
|
|
24
|
-
raise
|
|
24
|
+
raise ArgumentError, 'content type cannot be undefined or empty' if content_type.nil? || content_type.strip.empty?
|
|
25
25
|
|
|
26
|
-
vendor_specific_content_type = content_type.split(';').first
|
|
27
|
-
factory =
|
|
26
|
+
vendor_specific_content_type = content_type.split(';').first.strip
|
|
27
|
+
factory = content_type_associated_factories[vendor_specific_content_type]
|
|
28
28
|
return factory.get_serialization_writer(vendor_specific_content_type) if factory
|
|
29
29
|
|
|
30
30
|
clean_content_type = get_clean_content_type(vendor_specific_content_type)
|
|
31
|
-
factory =
|
|
31
|
+
factory = content_type_associated_factories[clean_content_type]
|
|
32
32
|
return factory.get_serialization_writer(clean_content_type) if factory
|
|
33
33
|
|
|
34
34
|
raise StandardError, "Content type #{content_type} does not have a factory to be serialized"
|
|
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
|
|
|
28
28
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
29
29
|
spec.require_paths = ['lib']
|
|
30
30
|
spec.add_dependency 'iso8601', '~> 0.13.0'
|
|
31
|
-
spec.add_dependency 'stduritemplate', '>=
|
|
31
|
+
spec.add_dependency 'stduritemplate', '>= 2.0.13', '< 2.1.0'
|
|
32
32
|
spec.add_development_dependency 'rake', '~> 13.0'
|
|
33
33
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
34
34
|
spec.add_development_dependency 'rubocop'
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: microsoft_kiota_abstractions
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.26.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Microsoft Corporation
|
|
@@ -29,7 +29,7 @@ dependencies:
|
|
|
29
29
|
requirements:
|
|
30
30
|
- - ">="
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version:
|
|
32
|
+
version: 2.0.13
|
|
33
33
|
- - "<"
|
|
34
34
|
- !ruby/object:Gem::Version
|
|
35
35
|
version: 2.1.0
|
|
@@ -39,7 +39,7 @@ dependencies:
|
|
|
39
39
|
requirements:
|
|
40
40
|
- - ">="
|
|
41
41
|
- !ruby/object:Gem::Version
|
|
42
|
-
version:
|
|
42
|
+
version: 2.0.13
|
|
43
43
|
- - "<"
|
|
44
44
|
- !ruby/object:Gem::Version
|
|
45
45
|
version: 2.1.0
|