ibm_cloud_sdk_core 1.0.0.rc3 → 1.0.0.rc4

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: 552a7ea5d30afc2a3e9764b365e6a1ea1666852e7eefe54e01e63dc949cfdf02
4
- data.tar.gz: 5acfc4a1cfd2f358096bf4c6153282ad39761ed9535ee283dfb28a3f499c7858
3
+ metadata.gz: 2199b7e854aa1782e0a5f75e89ed01033c93eba058a7143213668625ebf6a9ce
4
+ data.tar.gz: 0175abf279e3d455ccc8b9fd226024d4a9ab0052720e3644661f0cdb40bcf96d
5
5
  SHA512:
6
- metadata.gz: 967664c0155975c23714884c142259824a74e363df6134bbfaff7236701f61ef3ec5b37950509cd78fcbb37b185e75eda451891fdc88f02f5f9766b9e7c040ed
7
- data.tar.gz: e9005fe810d53199e88963ff13a4099c09c624e7f7664243aae7be405bd5bf77d71639cf8a0ace8f61a55beb569eb14343f430bbc8e689abdd8ab42c86003c96
6
+ metadata.gz: c003a64cb4671105912a4d7428098b25230ad04d63a04b6a0304e7117f3f5b22c01f4bd9348e8fa9e423f75a2bc8b4fd47d3dc5cafa2a81cc22e17d660593bb4
7
+ data.tar.gz: 93670092b8bd6d66fd4c607e01590cb9f1bfbb6f4b7e245dc8fb702cbb8c1083cd5ba323bd7b65ce790112f787d5af94ab22303c1c38685229f359a2d9f01455
@@ -24,7 +24,6 @@ module IBMCloudSdkCore
24
24
  def authenticate(headers)
25
25
  base64_authentication = Base64.strict_encode64("#{@username}:#{@password}")
26
26
  headers["Authorization"] = "Basic #{base64_authentication}"
27
- headers
28
27
  end
29
28
 
30
29
  # Checks if all the inputs needed are present
@@ -21,7 +21,6 @@ module IBMCloudSdkCore
21
21
  # Adds the Authorization header, if possible
22
22
  def authenticate(headers)
23
23
  headers["Authorization"] = "Bearer #{@bearer_token}"
24
- headers
25
24
  end
26
25
 
27
26
  # Checks if all the inputs needed are present
@@ -26,6 +26,8 @@ module IBMCloudSdkCore
26
26
  else
27
27
  auth_type = config[:auth_type]
28
28
  end
29
+ config.delete(:url) unless config[:url].nil?
30
+ config[:url] = config[:auth_url] unless config[:auth_url].nil?
29
31
  return BasicAuthenticator.new(config) if auth_type.casecmp(AUTH_TYPE_BASIC).zero?
30
32
  return BearerTokenAuthenticator.new(config) if auth_type.casecmp(AUTH_TYPE_BEARER_TOKEN).zero?
31
33
  return CloudPakForDataAuthenticator.new(config) if auth_type.casecmp(AUTH_TYPE_CP4D).zero?
@@ -23,21 +23,21 @@ end
23
23
  module IBMCloudSdkCore
24
24
  # Class for interacting with the API
25
25
  class BaseService
26
- attr_accessor :display_name, :service_url, :disable_ssl_verification
26
+ attr_accessor :service_name, :service_url, :disable_ssl_verification
27
27
  attr_reader :conn, :authenticator
28
28
  def initialize(vars)
29
29
  defaults = {
30
30
  authenticator: nil,
31
31
  disable_ssl_verification: false,
32
- display_name: nil
32
+ service_name: nil
33
33
  }
34
34
  vars = defaults.merge(vars)
35
35
  @service_url = vars[:service_url]
36
36
  @authenticator = vars[:authenticator]
37
37
  @disable_ssl_verification = vars[:disable_ssl_verification]
38
- @display_name = vars[:display_name]
39
- @service_name = @display_name.tr(" ", "_").downcase unless @display_name.nil?
40
- @authenticator = IBMCloudSdkCore::ConfigBasedAuthenticatorFactory.new.get_authenticator(service_name: @service_name) if @authenticator.nil?
38
+ @service_name = vars[:service_name]
39
+
40
+ raise ArgumentError.new("authenticator must be provided") if @authenticator.nil?
41
41
 
42
42
  if @service_name && !@service_url
43
43
  config = get_service_properties(@service_name)
@@ -75,9 +75,9 @@ module IBMCloudSdkCore
75
75
 
76
76
  conn = @conn
77
77
 
78
- @authenticator.authenticate(@temp_headers)
78
+ @authenticator.authenticate(args[:headers])
79
79
  args[:headers] = args[:headers].merge(@temp_headers) unless @temp_headers.nil?
80
- @temp_headers = nil unless @temp_headers.nil?
80
+ @temp_headers = {} unless @temp_headers.nil?
81
81
 
82
82
  raise ArgumentError.new("service_url must be provided") if @service_url.nil?
83
83
  raise ArgumentError.new('The service_url shouldn\'t start or end with curly brackets or quotes. Be sure to remove any {} and \" characters surrounding your username') if check_bad_first_or_last_char(@service_url)
@@ -20,15 +20,15 @@ end
20
20
  def load_from_credential_file(service_name, separator = "=")
21
21
  credential_file_path = ENV["IBM_CREDENTIALS_FILE"]
22
22
 
23
- # Home directory
23
+ # Top-level directory of the project
24
24
  if credential_file_path.nil?
25
- file_path = ENV["HOME"] + "/" + DEFAULT_CREDENTIALS_FILE_NAME
25
+ file_path = File.join(File.dirname(__FILE__), "/../../" + DEFAULT_CREDENTIALS_FILE_NAME)
26
26
  credential_file_path = file_path if File.exist?(file_path)
27
27
  end
28
28
 
29
- # Top-level directory of the project
29
+ # Home directory
30
30
  if credential_file_path.nil?
31
- file_path = File.join(File.dirname(__FILE__), "/../../" + DEFAULT_CREDENTIALS_FILE_NAME)
31
+ file_path = ENV["HOME"] + "/" + DEFAULT_CREDENTIALS_FILE_NAME
32
32
  credential_file_path = file_path if File.exist?(file_path)
33
33
  end
34
34
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IBMCloudSdkCore
4
- VERSION = "1.0.0.rc3"
4
+ VERSION = "1.0.0.rc4"
5
5
  end
@@ -48,10 +48,11 @@ class BaseServiceTest < Minitest::Test
48
48
  ENV["IBM_CREDENTIALS_FILE"] = file_path
49
49
  authenticator = IBMCloudSdkCore::ConfigBasedAuthenticatorFactory.new.get_authenticator(service_name: "red_sox")
50
50
  service = IBMCloudSdkCore::BaseService.new(
51
- display_name: "Assistant",
51
+ service_name: "assistant",
52
52
  authenticator: authenticator
53
53
  )
54
54
  refute_nil(service)
55
+ ENV.delete("IBM_CREDENTIALS_FILE")
55
56
  end
56
57
 
57
58
  def test_correct_creds_and_headers
@@ -60,7 +61,7 @@ class BaseServiceTest < Minitest::Test
60
61
  password: "password"
61
62
  )
62
63
  service = IBMCloudSdkCore::BaseService.new(
63
- display_name: "Assistant",
64
+ service_name: "assistant",
64
65
  authenticator: authenticator
65
66
  )
66
67
  service.add_default_headers(
@@ -85,7 +86,7 @@ class BaseServiceTest < Minitest::Test
85
86
  file_path = File.join(File.dirname(__FILE__), "../../resources/ibm-credentials.env")
86
87
  ENV["IBM_CREDENTIALS_FILE"] = file_path
87
88
  authenticator = IBMCloudSdkCore::ConfigBasedAuthenticatorFactory.new.get_authenticator(service_name: "leo_messi")
88
- service = IBMCloudSdkCore::BaseService.new(display_name: "Leo Messi", url: "some.url", authenticator: authenticator)
89
+ service = IBMCloudSdkCore::BaseService.new(service_name: "leo_messi", url: "some.url", authenticator: authenticator)
89
90
  assert_equal(authenticator.authentication_type, "bearerToken")
90
91
  refute_nil(service)
91
92
  end
@@ -93,9 +94,9 @@ class BaseServiceTest < Minitest::Test
93
94
  def test_vcap_services
94
95
  ENV["VCAP_SERVICES"] = JSON.parse(File.read(Dir.getwd + "/resources/vcap-testing.json")).to_json
95
96
  authenticator = IBMCloudSdkCore::ConfigBasedAuthenticatorFactory.new.get_authenticator(service_name: "salah")
96
- service = IBMCloudSdkCore::BaseService.new(display_name: "salah", authenticator: authenticator)
97
+ service = IBMCloudSdkCore::BaseService.new(service_name: "salah", authenticator: authenticator)
97
98
  assert_equal(authenticator.username, "mo")
98
- assert_equal(service.display_name, "salah")
99
+ assert_equal(service.service_name, "salah")
99
100
  end
100
101
 
101
102
  def test_dummy_request
@@ -107,7 +108,7 @@ class BaseServiceTest < Minitest::Test
107
108
  }
108
109
  ).to_return(status: 200, body: "", headers: {})
109
110
  authenticator = IBMCloudSdkCore::ConfigBasedAuthenticatorFactory.new.get_authenticator(service_name: "salah")
110
- service = IBMCloudSdkCore::BaseService.new(display_name: "Salah", authenticator: authenticator, service_url: "https://we.the.best")
111
+ service = IBMCloudSdkCore::BaseService.new(service_name: "salah", authenticator: authenticator, service_url: "https://we.the.best")
111
112
  service_response = service.request(method: "GET", url: "/music", headers: {})
112
113
  assert_equal("", service_response.result)
113
114
  end
@@ -115,7 +116,7 @@ class BaseServiceTest < Minitest::Test
115
116
  def test_dummy_request_form_data
116
117
  authenticator = IBMCloudSdkCore::BearerTokenAuthenticator.new(bearer_token: "token")
117
118
  service = IBMCloudSdkCore::BaseService.new(
118
- display_name: "Assistant",
119
+ service_name: "assistant",
119
120
  authenticator: authenticator,
120
121
  service_url: "https://gateway.watsonplatform.net/"
121
122
  )
@@ -150,7 +151,7 @@ class BaseServiceTest < Minitest::Test
150
151
  }
151
152
  ).to_return(status: 500, body: response.to_json, headers: {})
152
153
  authenticator = IBMCloudSdkCore::ConfigBasedAuthenticatorFactory.new.get_authenticator(service_name: "salah")
153
- service = IBMCloudSdkCore::BaseService.new(display_name: "Salah", authenticator: authenticator, service_url: "https://we.the.best")
154
+ service = IBMCloudSdkCore::BaseService.new(service_name: "salah", authenticator: authenticator, service_url: "https://we.the.best")
154
155
  assert_raises IBMCloudSdkCore::ApiException do
155
156
  service.request(method: "GET", url: "/music", headers: {})
156
157
  end
@@ -176,7 +177,7 @@ class BaseServiceTest < Minitest::Test
176
177
  password: "icp-xyz"
177
178
  )
178
179
  service = IBMCloudSdkCore::BaseService.new(
179
- display_name: "Assistant",
180
+ service_name: "assistant",
180
181
  authenticator: authenticator,
181
182
  service_url: "https://we.the.best"
182
183
  )
@@ -140,4 +140,46 @@ class IamAuthenticatorTest < Minitest::Test
140
140
  authenticator.authenticate(headers)
141
141
  assert_equal(headers, authenticated_headers)
142
142
  end
143
+
144
+ def test_iam_authenticator_auth_url
145
+ file_path = File.join(File.dirname(__FILE__), "../../resources/ibm-credentials.env")
146
+ ENV["IBM_CREDENTIALS_FILE"] = file_path
147
+ token_layout = {
148
+ "username": "dummy",
149
+ "role": "Admin",
150
+ "permissions": %w[administrator manage_catalog],
151
+ "sub": "admin",
152
+ "iss": "sss",
153
+ "aud": "sss",
154
+ "uid": "sss",
155
+ "iat": Time.now.to_i + 3600,
156
+ "exp": Time.now.to_i
157
+ }
158
+ token = JWT.encode token_layout, "secret", "HS256"
159
+ response = {
160
+ "access_token" => token,
161
+ "token_type" => "Bearer",
162
+ "expires_in" => 3600,
163
+ "expiration" => 1_524_167_011,
164
+ "refresh_token" => "jy4gl91BQ"
165
+ }
166
+ stub_request(:post, "https://my.link/identity/token")
167
+ .with(
168
+ body: {
169
+ "apikey" => "mesSi",
170
+ "grant_type" => "urn:ibm:params:oauth:grant-type:apikey",
171
+ "response_type" => "cloud_iam"
172
+ },
173
+ headers: {
174
+ "Connection" => "close",
175
+ "Host" => "my.link",
176
+ "User-Agent" => "http.rb/4.1.1"
177
+ }
178
+ )
179
+ .to_return(status: 200, body: response.to_json, headers: {})
180
+ authenticator = IBMCloudSdkCore::ConfigBasedAuthenticatorFactory.new.get_authenticator(service_name: "my_service")
181
+ refute_nil(authenticator)
182
+ assert_equal(authenticator.instance_variable_get(:@token_manager).access_token, token)
183
+ ENV.delete("IBM_CREDENTIALS_FILE")
184
+ end
143
185
  end
@@ -125,7 +125,7 @@ class JWTTokenManagerTest < Minitest::Test
125
125
  disable_ssl_verification: true
126
126
  )
127
127
  IBMCloudSdkCore::BaseService.new(
128
- display_name: "Assistant",
128
+ service_name: "assistant",
129
129
  service_url: "http://the.com",
130
130
  authenticator: authenticator
131
131
  )
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.rc3
4
+ version: 1.0.0.rc4
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-09-12 00:00:00.000000000 Z
11
+ date: 2019-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby