ibm_cloud_sdk_core 0.3.3 → 1.0.0.rc1
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/ibm_cloud_sdk_core/authenticators/authenticator.rb +22 -0
- data/lib/ibm_cloud_sdk_core/authenticators/basic_authenticator.rb +35 -0
- data/lib/ibm_cloud_sdk_core/authenticators/bearer_token_authenticator.rb +31 -0
- data/lib/ibm_cloud_sdk_core/authenticators/config_based_authenticator_factory.rb +36 -0
- data/lib/ibm_cloud_sdk_core/authenticators/cp4d_authenticator.rb +49 -0
- data/lib/ibm_cloud_sdk_core/authenticators/iam_authenticator.rb +60 -0
- data/lib/ibm_cloud_sdk_core/authenticators/no_auth_authenticator.rb +21 -0
- data/lib/ibm_cloud_sdk_core/base_service.rb +13 -169
- data/lib/ibm_cloud_sdk_core/{icp4d_token_manager.rb → token_managers/cp4d_token_manager.rb} +7 -6
- data/lib/ibm_cloud_sdk_core/token_managers/iam_token_manager.rb +60 -0
- data/lib/ibm_cloud_sdk_core/{jwt_token_manager.rb → token_managers/jwt_token_manager.rb} +5 -8
- data/lib/ibm_cloud_sdk_core/utils.rb +78 -0
- data/lib/ibm_cloud_sdk_core/version.rb +1 -1
- data/test/unit/test_base_service.rb +63 -241
- data/test/unit/test_iam_token_manager.rb +26 -62
- data/test/unit/test_icp4d_token_manager.rb +4 -6
- data/test/unit/test_jwt_token_manager.rb +3 -16
- metadata +16 -8
- data/lib/ibm_cloud_sdk_core/iam_token_manager.rb +0 -66
@@ -5,8 +5,8 @@ require("webmock/minitest")
|
|
5
5
|
|
6
6
|
WebMock.disable_net_connect!(allow_localhost: true)
|
7
7
|
|
8
|
-
# Unit tests for the
|
9
|
-
class
|
8
|
+
# Unit tests for the CP4D Token Manager
|
9
|
+
class CP4DTokenManagerTest < Minitest::Test
|
10
10
|
def test_request_token
|
11
11
|
response = {
|
12
12
|
"access_token" => "oAeisG8yqPY7sFR_x66Z15",
|
@@ -16,7 +16,7 @@ class ICP4DTokenManagerTest < Minitest::Test
|
|
16
16
|
"refresh_token" => "jy4gl91BQ"
|
17
17
|
}
|
18
18
|
|
19
|
-
token_manager = IBMCloudSdkCore::
|
19
|
+
token_manager = IBMCloudSdkCore::CP4DTokenManager.new(
|
20
20
|
url: "https://the.sixth.one",
|
21
21
|
username: "you",
|
22
22
|
password: "me"
|
@@ -30,12 +30,10 @@ class ICP4DTokenManagerTest < Minitest::Test
|
|
30
30
|
).to_return(status: 200, body: response.to_json, headers: {})
|
31
31
|
token_response = token_manager.send(:request_token)
|
32
32
|
assert_equal(response, token_response)
|
33
|
-
token_manager.access_token("token")
|
34
|
-
assert_equal(token_manager.instance_variable_get(:@user_access_token), "token")
|
35
33
|
end
|
36
34
|
|
37
35
|
def test_request_token_fails
|
38
|
-
token_manager = IBMCloudSdkCore::
|
36
|
+
token_manager = IBMCloudSdkCore::CP4DTokenManager.new(
|
39
37
|
url: "https://the.sixth.one",
|
40
38
|
username: "you",
|
41
39
|
password: "me"
|
@@ -18,7 +18,7 @@ class JWTTokenManagerTest < Minitest::Test
|
|
18
18
|
}
|
19
19
|
|
20
20
|
token_manager = IBMCloudSdkCore::JWTTokenManager.new(
|
21
|
-
|
21
|
+
CP4D_url: "https://the.sixth.one",
|
22
22
|
username: "you",
|
23
23
|
password: "me"
|
24
24
|
)
|
@@ -31,13 +31,11 @@ class JWTTokenManagerTest < Minitest::Test
|
|
31
31
|
).to_return(status: 200, body: response.to_json, headers: {})
|
32
32
|
token_response = token_manager.send(:request, method: "get", url: "https://the.sixth.one")
|
33
33
|
assert_equal(response, token_response)
|
34
|
-
token_manager.access_token("token")
|
35
|
-
assert_equal(token_manager.instance_variable_get(:@user_access_token), "token")
|
36
34
|
end
|
37
35
|
|
38
36
|
def test_request_token_fails
|
39
37
|
token_manager = IBMCloudSdkCore::JWTTokenManager.new(
|
40
|
-
|
38
|
+
url: "https://the.sixth.one",
|
41
39
|
username: "you",
|
42
40
|
password: "me"
|
43
41
|
)
|
@@ -59,17 +57,6 @@ class JWTTokenManagerTest < Minitest::Test
|
|
59
57
|
end
|
60
58
|
end
|
61
59
|
|
62
|
-
def test_request_token_exists
|
63
|
-
token_manager = IBMCloudSdkCore::JWTTokenManager.new(
|
64
|
-
icp4d_url: "https://the.sixth.one",
|
65
|
-
username: "you",
|
66
|
-
password: "me",
|
67
|
-
access_token: "token"
|
68
|
-
)
|
69
|
-
token_response = token_manager.send(:token)
|
70
|
-
assert_equal("token", token_response)
|
71
|
-
end
|
72
|
-
|
73
60
|
def test_request_token_not_expired
|
74
61
|
access_token_layout = {
|
75
62
|
"username" => "dummy",
|
@@ -93,7 +80,7 @@ class JWTTokenManagerTest < Minitest::Test
|
|
93
80
|
}
|
94
81
|
|
95
82
|
token_manager = IBMCloudSdkCore::JWTTokenManager.new(
|
96
|
-
|
83
|
+
CP4D_url: "https://the.sixth.one",
|
97
84
|
username: "you",
|
98
85
|
password: "me",
|
99
86
|
token_name: "accessToken"
|
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: 0.
|
4
|
+
version: 1.0.0.rc1
|
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-08-
|
11
|
+
date: 2019-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -229,11 +229,19 @@ files:
|
|
229
229
|
- README.md
|
230
230
|
- lib/ibm_cloud_sdk_core.rb
|
231
231
|
- lib/ibm_cloud_sdk_core/api_exception.rb
|
232
|
+
- lib/ibm_cloud_sdk_core/authenticators/authenticator.rb
|
233
|
+
- lib/ibm_cloud_sdk_core/authenticators/basic_authenticator.rb
|
234
|
+
- lib/ibm_cloud_sdk_core/authenticators/bearer_token_authenticator.rb
|
235
|
+
- lib/ibm_cloud_sdk_core/authenticators/config_based_authenticator_factory.rb
|
236
|
+
- lib/ibm_cloud_sdk_core/authenticators/cp4d_authenticator.rb
|
237
|
+
- lib/ibm_cloud_sdk_core/authenticators/iam_authenticator.rb
|
238
|
+
- lib/ibm_cloud_sdk_core/authenticators/no_auth_authenticator.rb
|
232
239
|
- lib/ibm_cloud_sdk_core/base_service.rb
|
233
240
|
- lib/ibm_cloud_sdk_core/detailed_response.rb
|
234
|
-
- lib/ibm_cloud_sdk_core/
|
235
|
-
- lib/ibm_cloud_sdk_core/
|
236
|
-
- lib/ibm_cloud_sdk_core/jwt_token_manager.rb
|
241
|
+
- lib/ibm_cloud_sdk_core/token_managers/cp4d_token_manager.rb
|
242
|
+
- lib/ibm_cloud_sdk_core/token_managers/iam_token_manager.rb
|
243
|
+
- lib/ibm_cloud_sdk_core/token_managers/jwt_token_manager.rb
|
244
|
+
- lib/ibm_cloud_sdk_core/utils.rb
|
237
245
|
- lib/ibm_cloud_sdk_core/version.rb
|
238
246
|
- rakefile
|
239
247
|
- test/test_helper.rb
|
@@ -261,12 +269,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
261
269
|
version: '2.3'
|
262
270
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
263
271
|
requirements:
|
264
|
-
- - "
|
272
|
+
- - ">"
|
265
273
|
- !ruby/object:Gem::Version
|
266
|
-
version:
|
274
|
+
version: 1.3.1
|
267
275
|
requirements: []
|
268
276
|
rubyforge_project:
|
269
|
-
rubygems_version: 2.7.
|
277
|
+
rubygems_version: 2.7.8
|
270
278
|
signing_key:
|
271
279
|
specification_version: 4
|
272
280
|
summary: Official IBM Cloud SDK core library
|
@@ -1,66 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require("http")
|
4
|
-
require("json")
|
5
|
-
require("rbconfig")
|
6
|
-
require_relative("./version.rb")
|
7
|
-
require_relative("./jwt_token_manager")
|
8
|
-
|
9
|
-
module IBMCloudSdkCore
|
10
|
-
# Class to manage IAM Token Authentication
|
11
|
-
class IAMTokenManager < JWTTokenManager
|
12
|
-
DEFAULT_IAM_URL = "https://iam.cloud.ibm.com/identity/token"
|
13
|
-
CONTENT_TYPE = "application/x-www-form-urlencoded"
|
14
|
-
ACCEPT = "application/json"
|
15
|
-
DEFAULT_AUTHORIZATION = "Basic Yng6Yng="
|
16
|
-
DEFAULT_CLIENT_ID = "bx"
|
17
|
-
DEFAULT_CLIENT_SECRET = "bx"
|
18
|
-
REQUEST_TOKEN_GRANT_TYPE = "urn:ibm:params:oauth:grant-type:apikey"
|
19
|
-
REQUEST_TOKEN_RESPONSE_TYPE = "cloud_iam"
|
20
|
-
TOKEN_NAME = "access_token"
|
21
|
-
|
22
|
-
attr_accessor :token_info, :user_access_token
|
23
|
-
def initialize(iam_apikey: nil, iam_access_token: nil, iam_url: nil,
|
24
|
-
iam_client_id: nil, iam_client_secret: nil)
|
25
|
-
@iam_apikey = iam_apikey
|
26
|
-
@user_access_token = iam_access_token
|
27
|
-
@iam_url = iam_url.nil? ? DEFAULT_IAM_URL : iam_url
|
28
|
-
super(url: iam_url, access_token: iam_access_token, token_name: TOKEN_NAME)
|
29
|
-
|
30
|
-
# Both the client id and secret should be provided or neither should be provided.
|
31
|
-
if !iam_client_id.nil? && !iam_client_secret.nil?
|
32
|
-
@iam_client_id = iam_client_id
|
33
|
-
@iam_client_secret = iam_client_secret
|
34
|
-
elsif iam_client_id.nil? && iam_client_secret.nil?
|
35
|
-
@iam_client_id = DEFAULT_CLIENT_ID
|
36
|
-
@iam_client_secret = DEFAULT_CLIENT_SECRET
|
37
|
-
else
|
38
|
-
raise ArgumentError.new("Only one of 'iam_client_id' or 'iam_client_secret' were specified, but both parameters should be specified together.")
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
# Request an IAM token using an API key
|
45
|
-
def request_token
|
46
|
-
headers = {
|
47
|
-
"Content-Type" => CONTENT_TYPE,
|
48
|
-
"Accept" => ACCEPT
|
49
|
-
}
|
50
|
-
data = {
|
51
|
-
"grant_type" => REQUEST_TOKEN_GRANT_TYPE,
|
52
|
-
"apikey" => @iam_apikey,
|
53
|
-
"response_type" => REQUEST_TOKEN_RESPONSE_TYPE
|
54
|
-
}
|
55
|
-
response = request(
|
56
|
-
method: "POST",
|
57
|
-
url: @iam_url,
|
58
|
-
headers: headers,
|
59
|
-
data: HTTP::URI.form_encode(data),
|
60
|
-
username: @iam_client_id,
|
61
|
-
password: @iam_client_secret
|
62
|
-
)
|
63
|
-
response
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|