ibm_cloud_sdk_core 1.0.0 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ca58ef3d25ee02da45482dda4dfd00f3c3271c8374963ba4062dc4b202321be5
4
- data.tar.gz: f9420fee2e7ddf2b694e9b03bf31e71038da04cb4ada8e508a8ff3daeddabc09
3
+ metadata.gz: 0c9b7ef0229991386edba6b798b8dfbe46863a789cf3e224e4a4dd1a3a0c77b9
4
+ data.tar.gz: 78f9a4edfe95f69a19ecf88a7c914f34beb7d8f6776ee6fec87464fcd03c889b
5
5
  SHA512:
6
- metadata.gz: 880bbdf1443b486eece94359d223aaae1b597996744a26a2359d476ce20bb0b8483ca0bf5248543a47eb397c05a85b7465047c68505d5516d6068454e69bc130
7
- data.tar.gz: dd994f5342fb05e25684e5abec41aec7fb87de1ff6d072b99734c55d06a22f55d828e5371d8ea57560c385fae4bc3f1355d2778adbbcc8f040093ea2ab6bd461
6
+ metadata.gz: f3496ff88377fcf4bf3efea81161642ba457d09c8c755da289afdae16597cfbb8d1f6e488fa259b3152c2cceb48329e1dc058dddf9ebd4d5f00d6e6f4cfd0072
7
+ data.tar.gz: fd308b61b2aa884f3110d125733024306ef06b15c416b4d12730a700a6ab17ffac79c459b076655e407ca11f4b7ef7cc7c59f9a45c53fa7cf35cf124130223b4
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
- [![Build Status](https://travis-ci.com/IBM/ruby-sdk-core.svg?branch=master)](https://travis-ci.com/IBM/ruby-sdk-core)
2
- [![codecov](https://codecov.io/gh/IBM/ruby-sdk-core/branch/master/graph/badge.svg)](https://codecov.io/gh/IBM/ruby-sdk-core)
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
@@ -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
@@ -10,7 +10,7 @@ module IBMCloudSdkCore
10
10
  @authentication_type = AUTH_TYPE_NO_AUTH
11
11
  end
12
12
 
13
- def authenticate
13
+ def authenticate(*)
14
14
  nil
15
15
  end
16
16
 
@@ -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
- unless line.start_with?("#") && key.length == 2
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
- credentials = services[service_name][0]["credentials"] if services.key?(service_name)
68
- return config if credentials.nil?
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IBMCloudSdkCore
4
- VERSION = "1.0.0"
4
+ VERSION = "1.1.3"
5
5
  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.4.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, service_url: "https://we.the.best")
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, service_url: "https://we.the.best")
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
@@ -37,7 +37,7 @@ class Cp4dAuthenticatorTest < Minitest::Test
37
37
  "Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
38
38
  "Connection" => "close",
39
39
  "Host" => "icp.com",
40
- "User-Agent" => "http.rb/4.1.1"
40
+ "User-Agent" => "http.rb/4.4.1"
41
41
  }
42
42
  )
43
43
  .to_return(status: 200, body: response.to_json, headers: {})
@@ -77,7 +77,7 @@ class Cp4dAuthenticatorTest < Minitest::Test
77
77
  "Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
78
78
  "Connection" => "close",
79
79
  "Host" => "icp.com",
80
- "User-Agent" => "http.rb/4.1.1"
80
+ "User-Agent" => "http.rb/4.4.1"
81
81
  }
82
82
  )
83
83
  .to_return(status: 200, body: response.to_json, headers: {})
@@ -41,7 +41,7 @@ class IamAuthenticatorTest < Minitest::Test
41
41
  headers: {
42
42
  "Connection" => "close",
43
43
  "Host" => "iam.cloud.ibm.com",
44
- "User-Agent" => "http.rb/4.1.1"
44
+ "User-Agent" => "http.rb/4.4.1"
45
45
  }
46
46
  )
47
47
  .to_return(status: 200, body: response.to_json, headers: {})
@@ -83,7 +83,7 @@ class IamAuthenticatorTest < Minitest::Test
83
83
  "Connection" => "close",
84
84
  "Authorization" => "Basic Yng6Yng=",
85
85
  "Host" => "iam.cloud.ibm.com",
86
- "User-Agent" => "http.rb/4.1.1"
86
+ "User-Agent" => "http.rb/4.4.1"
87
87
  }
88
88
  )
89
89
  .to_return(status: 200, body: response.to_json, headers: {})
@@ -126,7 +126,7 @@ class IamAuthenticatorTest < Minitest::Test
126
126
  headers: {
127
127
  "Connection" => "close",
128
128
  "Host" => "iam.cloud.ibm.com",
129
- "User-Agent" => "http.rb/4.1.1"
129
+ "User-Agent" => "http.rb/4.4.1"
130
130
  }
131
131
  )
132
132
  .to_return(status: 200, body: response.to_json, headers: {})
@@ -173,7 +173,7 @@ class IamAuthenticatorTest < Minitest::Test
173
173
  headers: {
174
174
  "Connection" => "close",
175
175
  "Host" => "my.link",
176
- "User-Agent" => "http.rb/4.1.1"
176
+ "User-Agent" => "http.rb/4.4.1"
177
177
  }
178
178
  )
179
179
  .to_return(status: 200, body: response.to_json, headers: {})
@@ -114,7 +114,7 @@ class JWTTokenManagerTest < Minitest::Test
114
114
  "Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
115
115
  "Connection" => "close",
116
116
  "Host" => "icp.com",
117
- "User-Agent" => "http.rb/4.1.1"
117
+ "User-Agent" => "http.rb/4.4.1"
118
118
  }
119
119
  )
120
120
  .to_return(status: 200, body: response.to_json, headers: {})
@@ -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.0.0
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mamoon Raja
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-03 00:00:00.000000000 Z
11
+ date: 2021-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 4.1.0
33
+ version: 4.4.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 4.1.0
40
+ version: 4.4.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: jwt
43
43
  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
@@ -275,8 +276,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
275
276
  - !ruby/object:Gem::Version
276
277
  version: '0'
277
278
  requirements: []
278
- rubyforge_project:
279
- rubygems_version: 2.7.7
279
+ rubygems_version: 3.0.8
280
280
  signing_key:
281
281
  specification_version: 4
282
282
  summary: Official IBM Cloud SDK core library