ibm_cloud_sdk_core 1.0.0.rc6 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/ibm_cloud_sdk_core/api_exception.rb +2 -2
- data/lib/ibm_cloud_sdk_core/authenticators/no_auth_authenticator.rb +1 -1
- data/lib/ibm_cloud_sdk_core/base_service.rb +11 -9
- data/lib/ibm_cloud_sdk_core/utils.rb +22 -5
- data/lib/ibm_cloud_sdk_core/version.rb +1 -1
- data/test/unit/test_base_service.rb +157 -9
- data/test/unit/test_utils.rb +116 -0
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ea5a5f7575d1adaba82982ad3467bb4a80c39bcc686d291dbb95e450b72e1c1
|
4
|
+
data.tar.gz: 870be154704bc0e75a215ba910be6f72aa110855f65961f73ee937ba650e1103
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '081184cf6a07b9a48bdfcb7c20a97ff27871fb3f35e56defd88dc5e3baba9b71dc4e954ae9d1ec8c78b9929281a2133cd144967e3028463eb2a8287a9aff2560'
|
7
|
+
data.tar.gz: 1ec8854f91cabc79e2bd5e9dadd09278fc72fab8934daf1d9a30e903dd85bdc1ae8aa877beea3cc72ddb5f81b435740c2a5c1fdc93175d721869b198e5606d3c
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
[![Build Status](https://travis-ci.com/IBM/ruby-sdk-core.svg?branch=
|
2
|
-
[![codecov](https://codecov.io/gh/IBM/ruby-sdk-core/branch/
|
1
|
+
[![Build Status](https://travis-ci.com/IBM/ruby-sdk-core.svg?branch=main)](https://travis-ci.com/IBM/ruby-sdk-core)
|
2
|
+
[![codecov](https://codecov.io/gh/IBM/ruby-sdk-core/branch/main/graph/badge.svg)](https://codecov.io/gh/IBM/ruby-sdk-core)
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/ibm_cloud_sdk_core.svg)](https://rubygems.org/gems/ibm_cloud_sdk_core)
|
4
4
|
|
5
5
|
# ruby-sdk-core
|
@@ -31,7 +31,7 @@ This indicates Basic Auth is to be used. Users will pass in a `username` and `pa
|
|
31
31
|
This indicates that bearer token authentication is to be used. Users can pass in an `bearer_token`, and SDK will generate a Bearer Auth header to send with requests to the service.
|
32
32
|
|
33
33
|
### iam
|
34
|
-
This indicates that IAM token authentication is to be used. Users can pass in an `
|
34
|
+
This indicates that IAM token authentication is to be used. Users can pass in an `apikey`. The SDK will manage the token for the user and it will generate a Bearer Auth header to send with requests to the service.
|
35
35
|
|
36
36
|
### cp4d
|
37
37
|
This indicates that the service is an instance of ICP4D, which has its own version of token authentication. Users can pass in a `username` and `password`. If a username and password is given, the SDK will manage the token for the user.
|
@@ -26,8 +26,8 @@ module IBMCloudSdkCore
|
|
26
26
|
@info = info
|
27
27
|
# :nocov:
|
28
28
|
end
|
29
|
-
@transaction_id = transaction_id
|
30
|
-
@global_transaction_id = global_transaction_id
|
29
|
+
@transaction_id = transaction_id || response.headers["X-Dp-Watson-Tran-Id"]
|
30
|
+
@global_transaction_id = global_transaction_id || response.headers["X-Global-Transaction-Id"]
|
31
31
|
end
|
32
32
|
|
33
33
|
def to_s
|
@@ -39,16 +39,11 @@ module IBMCloudSdkCore
|
|
39
39
|
|
40
40
|
raise ArgumentError.new("authenticator must be provided") if @authenticator.nil?
|
41
41
|
|
42
|
-
if @service_name && !@service_url
|
43
|
-
config = get_service_properties(@service_name)
|
44
|
-
@service_url = config[:url] unless config.nil?
|
45
|
-
end
|
46
|
-
|
47
|
-
configure_http_client(disable_ssl_verification: @disable_ssl_verification)
|
48
|
-
@temp_headers = {}
|
49
42
|
@conn = HTTP::Client.new(
|
50
43
|
headers: {}
|
51
44
|
).use normalize_uri: { normalizer: NORMALIZER }
|
45
|
+
configure_service(@service_name)
|
46
|
+
@temp_headers = {}
|
52
47
|
end
|
53
48
|
|
54
49
|
def disable_ssl_verification=(disable_ssl_verification)
|
@@ -61,6 +56,15 @@ module IBMCloudSdkCore
|
|
61
56
|
headers.each_pair { |k, v| @conn.default_options.headers.add(k, v) }
|
62
57
|
end
|
63
58
|
|
59
|
+
def configure_service(service_name)
|
60
|
+
config = get_service_properties(service_name) if service_name
|
61
|
+
|
62
|
+
@service_url = config[:url] unless config.nil? || config[:url].nil?
|
63
|
+
disable_ssl_verification = explicitly_true(config[:disable_ssl]) unless config.nil? || config[:disable_ssl].nil?
|
64
|
+
# configure the http client if ssl is disabled
|
65
|
+
configure_http_client(disable_ssl_verification: disable_ssl_verification) if disable_ssl_verification
|
66
|
+
end
|
67
|
+
|
64
68
|
# @return [DetailedResponse]
|
65
69
|
def request(args)
|
66
70
|
defaults = { method: nil, url: nil, accept_json: false, headers: nil, params: nil, json: {}, data: nil }
|
@@ -143,8 +147,6 @@ module IBMCloudSdkCore
|
|
143
147
|
ssl_context = OpenSSL::SSL::SSLContext.new
|
144
148
|
ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
145
149
|
@conn.default_options = { ssl_context: ssl_context }
|
146
|
-
|
147
|
-
@token_manager&.ssl_verification(true)
|
148
150
|
end
|
149
151
|
add_proxy(proxy) unless proxy.empty? || !proxy.dig(:address).is_a?(String) || !proxy.dig(:port).is_a?(Integer)
|
150
152
|
add_timeout(timeout) unless timeout.empty? || (!timeout.key?(:per_operation) && !timeout.key?(:global))
|
@@ -16,6 +16,13 @@ def check_bad_first_or_last_char(str)
|
|
16
16
|
return str.start_with?("{", "\"") || str.end_with?("}", "\"") unless str.nil?
|
17
17
|
end
|
18
18
|
|
19
|
+
# checks if the provided value is truthy
|
20
|
+
def explicitly_true(value)
|
21
|
+
return value.to_s.casecmp("true").zero? unless value.nil?
|
22
|
+
|
23
|
+
false
|
24
|
+
end
|
25
|
+
|
19
26
|
# Initiates the credentials based on the credential file
|
20
27
|
def load_from_credential_file(service_name, separator = "=")
|
21
28
|
credential_file_path = ENV["IBM_CREDENTIALS_FILE"]
|
@@ -37,8 +44,8 @@ def load_from_credential_file(service_name, separator = "=")
|
|
37
44
|
file_contents = File.open(credential_file_path, "r")
|
38
45
|
config = {}
|
39
46
|
file_contents.each_line do |line|
|
40
|
-
key_val = line.strip.split(separator)
|
41
|
-
|
47
|
+
key_val = line.strip.split(separator, 2)
|
48
|
+
if key_val.length == 2 && !line.start_with?("#")
|
42
49
|
key = parse_key(key_val[0].downcase, service_name) unless key_val[0].nil?
|
43
50
|
config.store(key.to_sym, key_val[1]) unless key.nil?
|
44
51
|
end
|
@@ -63,10 +70,20 @@ def load_from_vcap_services(service_name)
|
|
63
70
|
vcap_services = ENV["VCAP_SERVICES"]
|
64
71
|
unless vcap_services.nil?
|
65
72
|
services = JSON.parse(vcap_services)
|
73
|
+
credentials = ""
|
74
|
+
# search for matching inner name value
|
75
|
+
services.each do |_key, val|
|
76
|
+
service = val.detect { |item| item["name"] == service_name }
|
77
|
+
credentials = service["credentials"] unless service.nil?
|
78
|
+
break unless credentials.nil? || credentials.empty?
|
79
|
+
end
|
66
80
|
config = {}
|
67
|
-
|
68
|
-
|
69
|
-
|
81
|
+
# if no matching inner key is found, then search outer keys
|
82
|
+
if credentials.nil? || credentials.empty?
|
83
|
+
credentials = services[service_name][0]["credentials"] if services.key?(service_name) && !services[service_name].empty?
|
84
|
+
return config if credentials.nil? || credentials.empty?
|
85
|
+
end
|
86
|
+
# store credentials
|
70
87
|
credentials.each do |key, val|
|
71
88
|
config.store(key.to_sym, val)
|
72
89
|
end
|
@@ -26,6 +26,7 @@ class BaseServiceTest < Minitest::Test
|
|
26
26
|
assert_raises do
|
27
27
|
IBMCloudSdkCore::ConfigBasedAuthenticatorFactory.new.get_authenticator(service_name: "wrong")
|
28
28
|
end
|
29
|
+
ENV.delete("IBM_CREDENTIALS_FILE")
|
29
30
|
end
|
30
31
|
|
31
32
|
def test_wrong_url
|
@@ -82,6 +83,47 @@ class BaseServiceTest < Minitest::Test
|
|
82
83
|
ENV.delete("IBM_CREDENTIALS_FILE")
|
83
84
|
end
|
84
85
|
|
86
|
+
def test_set_credentials_from_path_invalid_auth_type_value
|
87
|
+
token_layout = {
|
88
|
+
"username": "dummy",
|
89
|
+
"role": "Admin",
|
90
|
+
"permissions": %w[administrator manage_catalog],
|
91
|
+
"sub": "admin",
|
92
|
+
"iss": "sss",
|
93
|
+
"aud": "sss",
|
94
|
+
"uid": "sss",
|
95
|
+
"iat": Time.now.to_i + 3600,
|
96
|
+
"exp": Time.now.to_i
|
97
|
+
}
|
98
|
+
token = JWT.encode token_layout, "secret", "HS256"
|
99
|
+
response = {
|
100
|
+
"access_token" => token,
|
101
|
+
"token_type" => "Bearer",
|
102
|
+
"expires_in" => 3600,
|
103
|
+
"expiration" => 1_524_167_011,
|
104
|
+
"refresh_token" => "jy4gl91BQ"
|
105
|
+
}
|
106
|
+
stub_request(:post, "https://iam.cloud.ibm.com/identity/token")
|
107
|
+
.with(
|
108
|
+
body: {
|
109
|
+
"apikey" => "sadio",
|
110
|
+
"grant_type" => "urn:ibm:params:oauth:grant-type:apikey",
|
111
|
+
"response_type" => "cloud_iam"
|
112
|
+
},
|
113
|
+
headers: {
|
114
|
+
"Connection" => "close",
|
115
|
+
"Host" => "iam.cloud.ibm.com",
|
116
|
+
"User-Agent" => "http.rb/4.1.1"
|
117
|
+
}
|
118
|
+
)
|
119
|
+
.to_return(status: 200, body: response.to_json, headers: {})
|
120
|
+
file_path = File.join(File.dirname(__FILE__), "../../resources/ibm-credentials.env")
|
121
|
+
ENV["IBM_CREDENTIALS_FILE"] = file_path
|
122
|
+
authenticator = IBMCloudSdkCore::ConfigBasedAuthenticatorFactory.new.get_authenticator(service_name: "mane")
|
123
|
+
assert_equal(authenticator.authentication_type, "iam")
|
124
|
+
ENV.delete("IBM_CREDENTIALS_FILE")
|
125
|
+
end
|
126
|
+
|
85
127
|
def test_set_credentials_from_path_in_env_bearer_token
|
86
128
|
file_path = File.join(File.dirname(__FILE__), "../../resources/ibm-credentials.env")
|
87
129
|
ENV["IBM_CREDENTIALS_FILE"] = file_path
|
@@ -89,6 +131,7 @@ class BaseServiceTest < Minitest::Test
|
|
89
131
|
service = IBMCloudSdkCore::BaseService.new(service_name: "leo_messi", url: "some.url", authenticator: authenticator)
|
90
132
|
assert_equal(authenticator.authentication_type, "bearerToken")
|
91
133
|
refute_nil(service)
|
134
|
+
ENV.delete("IBM_CREDENTIALS_FILE")
|
92
135
|
end
|
93
136
|
|
94
137
|
def test_vcap_services
|
@@ -97,6 +140,7 @@ class BaseServiceTest < Minitest::Test
|
|
97
140
|
service = IBMCloudSdkCore::BaseService.new(service_name: "salah", authenticator: authenticator)
|
98
141
|
assert_equal(authenticator.username, "mo")
|
99
142
|
assert_equal(service.service_name, "salah")
|
143
|
+
ENV.delete("VCAP_SERVICES")
|
100
144
|
end
|
101
145
|
|
102
146
|
def test_dummy_request
|
@@ -108,24 +152,26 @@ class BaseServiceTest < Minitest::Test
|
|
108
152
|
}
|
109
153
|
).to_return(status: 200, body: "", headers: {})
|
110
154
|
authenticator = IBMCloudSdkCore::ConfigBasedAuthenticatorFactory.new.get_authenticator(service_name: "salah")
|
111
|
-
service = IBMCloudSdkCore::BaseService.new(service_name: "salah", authenticator: authenticator
|
155
|
+
service = IBMCloudSdkCore::BaseService.new(service_name: "salah", authenticator: authenticator)
|
156
|
+
service.service_url = "https://we.the.best"
|
112
157
|
service_response = service.request(method: "GET", url: "/music", headers: {})
|
113
158
|
assert_equal("", service_response.result)
|
159
|
+
ENV.delete("VCAP_SERVICES")
|
114
160
|
end
|
115
161
|
|
116
162
|
def test_dummy_request_form_data
|
117
163
|
authenticator = IBMCloudSdkCore::BearerTokenAuthenticator.new(bearer_token: "token")
|
118
164
|
service = IBMCloudSdkCore::BaseService.new(
|
119
165
|
service_name: "assistant",
|
120
|
-
authenticator: authenticator
|
121
|
-
service_url: "https://gateway.watsonplatform.net/"
|
166
|
+
authenticator: authenticator
|
122
167
|
)
|
168
|
+
service.service_url = "https://gateway.watsonplatform.net/assistant/api/"
|
123
169
|
form_data = {}
|
124
170
|
file = File.open(Dir.getwd + "/resources/cnc_test.pdf")
|
125
171
|
filename = file.path if filename.nil? && file.respond_to?(:path)
|
126
172
|
form_data[:file] = HTTP::FormData::File.new(file, content_type: "application/octet-stream", filename: filename)
|
127
173
|
|
128
|
-
stub_request(:post, "https://gateway.watsonplatform.net/").with do |req|
|
174
|
+
stub_request(:post, "https://gateway.watsonplatform.net/assistant/api/dummy/endpoint").with do |req|
|
129
175
|
# Test the headers.
|
130
176
|
assert_equal(req.headers["Accept"], "application/json")
|
131
177
|
assert_match(%r{\Amultipart/form-data}, req.headers["Content-Type"])
|
@@ -134,7 +180,7 @@ class BaseServiceTest < Minitest::Test
|
|
134
180
|
method: "POST",
|
135
181
|
form: form_data,
|
136
182
|
headers: { "Accept" => "application/json" },
|
137
|
-
url: ""
|
183
|
+
url: "dummy/endpoint"
|
138
184
|
)
|
139
185
|
end
|
140
186
|
|
@@ -151,10 +197,12 @@ class BaseServiceTest < Minitest::Test
|
|
151
197
|
}
|
152
198
|
).to_return(status: 500, body: response.to_json, headers: {})
|
153
199
|
authenticator = IBMCloudSdkCore::ConfigBasedAuthenticatorFactory.new.get_authenticator(service_name: "salah")
|
154
|
-
service = IBMCloudSdkCore::BaseService.new(service_name: "salah", authenticator: authenticator
|
200
|
+
service = IBMCloudSdkCore::BaseService.new(service_name: "salah", authenticator: authenticator)
|
201
|
+
service.service_url = "https://we.the.best"
|
155
202
|
assert_raises IBMCloudSdkCore::ApiException do
|
156
203
|
service.request(method: "GET", url: "/music", headers: {})
|
157
204
|
end
|
205
|
+
ENV.delete("VCAP_SERVICES")
|
158
206
|
end
|
159
207
|
|
160
208
|
def test_dummy_request_icp
|
@@ -169,7 +217,8 @@ class BaseServiceTest < Minitest::Test
|
|
169
217
|
stub_request(:get, "https://we.the.best/music")
|
170
218
|
.with(
|
171
219
|
headers: {
|
172
|
-
"Host" => "we.the.best"
|
220
|
+
"Host" => "we.the.best",
|
221
|
+
"Authorization" => "Basic YXBpa2V5OmljcC14eXo="
|
173
222
|
}
|
174
223
|
).to_return(status: 200, body: response.to_json, headers: headers)
|
175
224
|
authenticator = IBMCloudSdkCore::BasicAuthenticator.new(
|
@@ -178,10 +227,109 @@ class BaseServiceTest < Minitest::Test
|
|
178
227
|
)
|
179
228
|
service = IBMCloudSdkCore::BaseService.new(
|
180
229
|
service_name: "assistant",
|
181
|
-
authenticator: authenticator
|
182
|
-
service_url: "https://we.the.best"
|
230
|
+
authenticator: authenticator
|
183
231
|
)
|
232
|
+
service.service_url = "https://we.the.best"
|
184
233
|
service_response = service.request(method: "GET", url: "/music", headers: {})
|
185
234
|
assert_equal(response, service_response.result)
|
186
235
|
end
|
236
|
+
|
237
|
+
def test_configure_service_using_credentials_in_env
|
238
|
+
file_path = File.join(File.dirname(__FILE__), "../../resources/ibm-credentials.env")
|
239
|
+
ENV["IBM_CREDENTIALS_FILE"] = file_path
|
240
|
+
|
241
|
+
authenticator = IBMCloudSdkCore::BasicAuthenticator.new(
|
242
|
+
username: "apikey",
|
243
|
+
password: "icp-xyz"
|
244
|
+
)
|
245
|
+
service = IBMCloudSdkCore::BaseService.new(
|
246
|
+
authenticator: authenticator,
|
247
|
+
service_name: "visual_recognition"
|
248
|
+
)
|
249
|
+
service.configure_service("visual_recognition")
|
250
|
+
|
251
|
+
assert_equal("https://gateway.ronaldo.com", service.service_url)
|
252
|
+
assert(service.disable_ssl_verification)
|
253
|
+
ENV.delete("IBM_CREDENTIALS_FILE")
|
254
|
+
end
|
255
|
+
|
256
|
+
def test_configure_service_using_credentials_in_vcap_match_outer_key
|
257
|
+
authenticator = IBMCloudSdkCore::BasicAuthenticator.new(
|
258
|
+
username: "apikey",
|
259
|
+
password: "icp-xyz"
|
260
|
+
)
|
261
|
+
service = IBMCloudSdkCore::BaseService.new(
|
262
|
+
authenticator: authenticator,
|
263
|
+
service_name: "key_to_service_entry_1"
|
264
|
+
)
|
265
|
+
ENV["VCAP_SERVICES"] = JSON.parse(File.read(Dir.getwd + "/resources/vcap-testing.json")).to_json
|
266
|
+
service.configure_service("key_to_service_entry_1")
|
267
|
+
|
268
|
+
assert_equal("https://on.the.toolchainplatform.net/devops-insights/api", service.service_url)
|
269
|
+
ENV.delete("VCAP_SERVICES")
|
270
|
+
end
|
271
|
+
|
272
|
+
def test_configure_service_using_credentials_in_vcap_match_inner_key
|
273
|
+
authenticator = IBMCloudSdkCore::BasicAuthenticator.new(
|
274
|
+
username: "apikey",
|
275
|
+
password: "icp-xyz"
|
276
|
+
)
|
277
|
+
service = IBMCloudSdkCore::BaseService.new(
|
278
|
+
authenticator: authenticator,
|
279
|
+
service_name: "devops_insights"
|
280
|
+
)
|
281
|
+
ENV["VCAP_SERVICES"] = JSON.parse(File.read(Dir.getwd + "/resources/vcap-testing.json")).to_json
|
282
|
+
service.configure_service("devops_insights")
|
283
|
+
|
284
|
+
assert_equal("https://ibmtesturl.net/devops_insights/api", service.service_url)
|
285
|
+
ENV.delete("VCAP_SERVICES")
|
286
|
+
end
|
287
|
+
|
288
|
+
def test_configure_service_using_credentials_in_vcap_no_matching_key
|
289
|
+
authenticator = IBMCloudSdkCore::BasicAuthenticator.new(
|
290
|
+
username: "apikey",
|
291
|
+
password: "icp-xyz"
|
292
|
+
)
|
293
|
+
service = IBMCloudSdkCore::BaseService.new(
|
294
|
+
authenticator: authenticator,
|
295
|
+
service_name: "different_name_two"
|
296
|
+
)
|
297
|
+
ENV["VCAP_SERVICES"] = JSON.parse(File.read(Dir.getwd + "/resources/vcap-testing.json")).to_json
|
298
|
+
service.configure_service("different_name_two")
|
299
|
+
|
300
|
+
assert_equal("https://gateway.watsonplatform.net/different-name-two/api", service.service_url)
|
301
|
+
ENV.delete("VCAP_SERVICES")
|
302
|
+
end
|
303
|
+
|
304
|
+
def test_configure_service_using_credentials_in_vcap_empty_entry
|
305
|
+
authenticator = IBMCloudSdkCore::BasicAuthenticator.new(
|
306
|
+
username: "apikey",
|
307
|
+
password: "icp-xyz"
|
308
|
+
)
|
309
|
+
service = IBMCloudSdkCore::BaseService.new(
|
310
|
+
authenticator: authenticator,
|
311
|
+
service_name: "empty_service"
|
312
|
+
)
|
313
|
+
ENV["VCAP_SERVICES"] = JSON.parse(File.read(Dir.getwd + "/resources/vcap-testing.json")).to_json
|
314
|
+
service.configure_service("empty_service")
|
315
|
+
|
316
|
+
assert_nil(service.service_url)
|
317
|
+
ENV.delete("VCAP_SERVICES")
|
318
|
+
end
|
319
|
+
|
320
|
+
def test_configure_service_using_credentials_in_vcap_no_creds
|
321
|
+
authenticator = IBMCloudSdkCore::BasicAuthenticator.new(
|
322
|
+
username: "apikey",
|
323
|
+
password: "icp-xyz"
|
324
|
+
)
|
325
|
+
service = IBMCloudSdkCore::BaseService.new(
|
326
|
+
authenticator: authenticator,
|
327
|
+
service_name: "no-creds-service-two"
|
328
|
+
)
|
329
|
+
ENV["VCAP_SERVICES"] = JSON.parse(File.read(Dir.getwd + "/resources/vcap-testing.json")).to_json
|
330
|
+
service.configure_service("no-creds-service-two")
|
331
|
+
|
332
|
+
assert_nil(service.service_url)
|
333
|
+
ENV.delete("VCAP_SERVICES")
|
334
|
+
end
|
187
335
|
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require("json")
|
4
|
+
require("jwt")
|
5
|
+
require_relative("./../test_helper.rb")
|
6
|
+
require_relative("./../../lib/ibm_cloud_sdk_core/authenticators/basic_authenticator")
|
7
|
+
require_relative("./../../lib/ibm_cloud_sdk_core/authenticators/config_based_authenticator_factory")
|
8
|
+
require("webmock/minitest")
|
9
|
+
|
10
|
+
WebMock.disable_net_connect!(allow_localhost: true)
|
11
|
+
|
12
|
+
# Unit tests for the utility methods
|
13
|
+
class UtilsTest < Minitest::Test
|
14
|
+
def test_explicitly_true
|
15
|
+
assert(explicitly_true("true"))
|
16
|
+
assert(explicitly_true("True"))
|
17
|
+
assert(explicitly_true(true))
|
18
|
+
|
19
|
+
assert_equal(explicitly_true("false"), false)
|
20
|
+
assert_equal(explicitly_true("False"), false)
|
21
|
+
assert_equal(explicitly_true("someothervalue"), false)
|
22
|
+
assert_equal(explicitly_true(""), false)
|
23
|
+
assert_equal(explicitly_true(false), false)
|
24
|
+
assert_equal(explicitly_true(nil), false)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_get_configuration_credential_file
|
28
|
+
file_path = File.join(File.dirname(__FILE__), "../../resources/ibm-credentials.env")
|
29
|
+
ENV["IBM_CREDENTIALS_FILE"] = file_path
|
30
|
+
# get properties
|
31
|
+
config = get_service_properties("service_1")
|
32
|
+
auth_type = config[:auth_type] unless config.nil?
|
33
|
+
apikey = config[:apikey] unless config.nil?
|
34
|
+
auth_url = config[:auth_url] unless config.nil?
|
35
|
+
client_id = config[:client_id] unless config.nil?
|
36
|
+
client_secret = config[:client_secret] unless config.nil?
|
37
|
+
service_url = config[:url] unless config.nil?
|
38
|
+
|
39
|
+
assert !auth_type.nil?
|
40
|
+
assert !apikey.nil?
|
41
|
+
assert !auth_url.nil?
|
42
|
+
assert !client_id.nil?
|
43
|
+
assert !client_secret.nil?
|
44
|
+
assert !service_url.nil?
|
45
|
+
|
46
|
+
assert_equal("iam", auth_type)
|
47
|
+
assert_equal("V4HXmoUtMjohnsnow=KotN", apikey)
|
48
|
+
assert_equal("https://iamhost/iam/api=", auth_url)
|
49
|
+
assert_equal("somefake========id", client_id)
|
50
|
+
assert_equal("==my-client-secret==", client_secret)
|
51
|
+
assert_equal("service1.com/api", service_url)
|
52
|
+
ENV.delete("IBM_CREDENTIALS_FILE")
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_get_configuration_from_env
|
56
|
+
# Service1 auth properties configured with IAM and a token containing '='
|
57
|
+
ENV["SERVICE_1_AUTH_TYPE"] = "iam"
|
58
|
+
ENV["SERVICE_1_APIKEY"] = "V4HXmoUtMjohnsnow=KotN"
|
59
|
+
ENV["SERVICE_1_CLIENT_ID"] = "somefake========id"
|
60
|
+
ENV["SERVICE_1_CLIENT_SECRET"] = "==my-client-secret=="
|
61
|
+
ENV["SERVICE_1_AUTH_URL"] = "https://iamhost/iam/api="
|
62
|
+
# Service1 service properties
|
63
|
+
ENV["SERVICE_1_URL"] = "service1.com/api"
|
64
|
+
# get properties
|
65
|
+
config = get_service_properties("service_1")
|
66
|
+
auth_type = config[:auth_type] unless config.nil?
|
67
|
+
apikey = config[:apikey] unless config.nil?
|
68
|
+
auth_url = config[:auth_url] unless config.nil?
|
69
|
+
client_id = config[:client_id] unless config.nil?
|
70
|
+
client_secret = config[:client_secret] unless config.nil?
|
71
|
+
service_url = config[:url] unless config.nil?
|
72
|
+
|
73
|
+
assert !auth_type.nil?
|
74
|
+
assert !apikey.nil?
|
75
|
+
assert !auth_url.nil?
|
76
|
+
assert !client_id.nil?
|
77
|
+
assert !client_secret.nil?
|
78
|
+
assert !service_url.nil?
|
79
|
+
|
80
|
+
assert_equal("iam", auth_type)
|
81
|
+
assert_equal("V4HXmoUtMjohnsnow=KotN", apikey)
|
82
|
+
assert_equal("https://iamhost/iam/api=", auth_url)
|
83
|
+
assert_equal("somefake========id", client_id)
|
84
|
+
assert_equal("==my-client-secret==", client_secret)
|
85
|
+
assert_equal("service1.com/api", service_url)
|
86
|
+
|
87
|
+
ENV.delete("SERVICE_1_AUTH_TYPE")
|
88
|
+
ENV.delete("SERVICE_1_APIKEY")
|
89
|
+
ENV.delete("SERVICE_1_CLIENT_ID")
|
90
|
+
ENV.delete("SERVICE_1_CLIENT_SECRET")
|
91
|
+
ENV.delete("SERVICE_1_AUTH_URL")
|
92
|
+
ENV.delete("SERVICE_1_URL")
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_get_configuration_from_vcap
|
96
|
+
ENV["VCAP_SERVICES"] = JSON.parse(File.read(Dir.getwd + "/resources/vcap-testing.json")).to_json
|
97
|
+
# get properties
|
98
|
+
config = get_service_properties("equals-sign-test")
|
99
|
+
auth_type = config[:auth_type] unless config.nil?
|
100
|
+
apikey = config[:apikey] unless config.nil?
|
101
|
+
iam_url = config[:iam_url] unless config.nil?
|
102
|
+
service_url = config[:url] unless config.nil?
|
103
|
+
|
104
|
+
assert !auth_type.nil?
|
105
|
+
assert !apikey.nil?
|
106
|
+
assert !iam_url.nil?
|
107
|
+
assert !service_url.nil?
|
108
|
+
|
109
|
+
assert_equal("iam", auth_type)
|
110
|
+
assert_equal("V4HXmoUtMjohnsnow=KotN", apikey)
|
111
|
+
assert_equal("https://iamhost/iam/api=", iam_url)
|
112
|
+
assert_equal("https://gateway.watsonplatform.net/testService", service_url)
|
113
|
+
|
114
|
+
ENV.delete("VCAP_SERVICES")
|
115
|
+
end
|
116
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ibm_cloud_sdk_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mamoon Raja
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '1.
|
61
|
+
version: '1.6'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '1.
|
68
|
+
version: '1.6'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: codecov
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -170,14 +170,14 @@ dependencies:
|
|
170
170
|
requirements:
|
171
171
|
- - "~>"
|
172
172
|
- !ruby/object:Gem::Version
|
173
|
-
version: '
|
173
|
+
version: '13.0'
|
174
174
|
type: :development
|
175
175
|
prerelease: false
|
176
176
|
version_requirements: !ruby/object:Gem::Requirement
|
177
177
|
requirements:
|
178
178
|
- - "~>"
|
179
179
|
- !ruby/object:Gem::Version
|
180
|
-
version: '
|
180
|
+
version: '13.0'
|
181
181
|
- !ruby/object:Gem::Dependency
|
182
182
|
name: rubocop
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|
@@ -253,6 +253,7 @@ files:
|
|
253
253
|
- test/unit/test_iam_authenticator.rb
|
254
254
|
- test/unit/test_iam_token_manager.rb
|
255
255
|
- test/unit/test_jwt_token_manager.rb
|
256
|
+
- test/unit/test_utils.rb
|
256
257
|
homepage: https://www.github.com/IBM
|
257
258
|
licenses:
|
258
259
|
- Apache-2.0
|
@@ -271,12 +272,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
271
272
|
version: '2.3'
|
272
273
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
273
274
|
requirements:
|
274
|
-
- - "
|
275
|
+
- - ">="
|
275
276
|
- !ruby/object:Gem::Version
|
276
|
-
version:
|
277
|
+
version: '0'
|
277
278
|
requirements: []
|
278
|
-
|
279
|
-
rubygems_version: 2.7.8
|
279
|
+
rubygems_version: 3.0.8
|
280
280
|
signing_key:
|
281
281
|
specification_version: 4
|
282
282
|
summary: Official IBM Cloud SDK core library
|