Skip to content

Commit 6361d51

Browse files
committed
Merge remote-tracking branch 'origin/fix-for-multithreading-issue'
2 parents 37a3929 + 0bbb134 commit 6361d51

File tree

2 files changed

+56
-52
lines changed

2 files changed

+56
-52
lines changed

generator/cybersource-ruby-template/api_client.mustache

+28-26
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ module {{moduleName}}
1414
# The Configuration object holding settings to be used in the API client.
1515
attr_accessor :config
1616

17+
attr_accessor :merchantconfig
18+
1719
# Defines the headers to be used in HTTP requests of all API calls by default.
1820
#
1921
# @return [Hash]
@@ -108,13 +110,13 @@ module {{moduleName}}
108110
end
109111

110112
headers = opts[:header_params]
111-
if $merchantconfig_obj.authenticationType.upcase != Constants::AUTH_TYPE_MUTUAL_AUTH
113+
if @merchantconfig.authenticationType.upcase != Constants::AUTH_TYPE_MUTUAL_AUTH
112114
headers = CallAuthenticationHeader(http_method, path, body_params, headers, query_params)
113115
end
114116
http_method = http_method.to_sym.downcase
115117
header_params = headers.merge(@default_headers)
116-
if $merchantconfig_obj.defaultCustomHeaders
117-
header_params = header_params.merge($merchantconfig_obj.defaultCustomHeaders)
118+
if @merchantconfig.defaultCustomHeaders
119+
header_params = header_params.merge(@merchantconfig.defaultCustomHeaders)
118120
end
119121
form_params = opts[:form_params] || {}
120122

@@ -126,9 +128,9 @@ module {{moduleName}}
126128
_verify_ssl_host = @config.verify_ssl_host ? 2 : 0
127129

128130
# client cert
129-
if $merchantconfig_obj.enableClientCert
130-
@config.cert_file = File.join($merchantconfig_obj.clientCertDirectory, $merchantconfig_obj.sslClientCert)
131-
@config.key_file = File.join($merchantconfig_obj.clientCertDirectory, $merchantconfig_obj.privateKey)
131+
if @merchantconfig.enableClientCert
132+
@config.cert_file = File.join(@merchantconfig.clientCertDirectory, @merchantconfig.sslClientCert)
133+
@config.key_file = File.join(@merchantconfig.clientCertDirectory, @merchantconfig.privateKey)
132134
end
133135

134136
req_opts = {
@@ -140,7 +142,7 @@ module {{moduleName}}
140142
:ssl_verifypeer => @config.verify_ssl,
141143
:ssl_verifyhost => _verify_ssl_host,
142144
:sslcert => @config.cert_file,
143-
:sslkeypasswd => $merchantconfig_obj.sslKeyPassword || "",
145+
:sslkeypasswd => @merchantconfig.sslKeyPassword || "",
144146
:sslkey => @config.key_file,
145147
:verbose => @config.debugging
146148
}
@@ -168,13 +170,13 @@ module {{moduleName}}
168170
# set merchantConfig
169171
def set_configuration(config)
170172
require_relative '../AuthenticationSDK/core/MerchantConfig.rb'
171-
$merchantconfig_obj = Merchantconfig.new(config)
172-
@config.host = $merchantconfig_obj.requestHost
173-
if $merchantconfig_obj.intermediateHost
174-
@config.host = $merchantconfig_obj.intermediateHost
175-
if $merchantconfig_obj.intermediateHost.start_with?(Constants::HTTPS_URI_PREFIX)
173+
@merchantconfig = Merchantconfig.new(config)
174+
@config.host = @merchantconfig.requestHost
175+
if @merchantconfig.intermediateHost
176+
@config.host = @merchantconfig.intermediateHost
177+
if @merchantconfig.intermediateHost.start_with?(Constants::HTTPS_URI_PREFIX)
176178
@config.scheme = 'https'
177-
elsif $merchantconfig_obj.intermediateHost.start_with?(Constants::HTTP_URI_PREFIX)
179+
elsif @merchantconfig.intermediateHost.start_with?(Constants::HTTP_URI_PREFIX)
178180
@config.scheme = 'http'
179181
end
180182
end
@@ -186,44 +188,44 @@ module {{moduleName}}
186188
request_target = get_query_param(path, query_params)
187189
# Request Type. [Non-Editable]
188190
request_type = http_method.to_s
189-
log_obj = Log.new $merchantconfig_obj.log_config, "ApiClient"
191+
log_obj = Log.new @merchantconfig.log_config, "ApiClient"
190192
# Set Request Type into the merchant config object.
191-
$merchantconfig_obj.requestType = request_type
193+
@merchantconfig.requestType = request_type
192194
# Set Request Target into the merchant config object.
193-
$merchantconfig_obj.requestTarget = request_target
195+
@merchantconfig.requestTarget = request_target
194196
# Construct the URL.
195-
url = Constants::HTTPS_URI_PREFIX + $merchantconfig_obj.requestHost + $merchantconfig_obj.requestTarget
197+
url = Constants::HTTPS_URI_PREFIX + @merchantconfig.requestHost + @merchantconfig.requestTarget
196198
# set Request Json to Merchant config object
197-
$merchantconfig_obj.requestJsonData = body_params
199+
@merchantconfig.requestJsonData = body_params
198200
# Set URL into the merchant config object.
199-
$merchantconfig_obj.requestUrl = url
201+
@merchantconfig.requestUrl = url
200202
# Calling APISDK, Apisdk.controller.
201203
gmtDateTime = DateTime.now.httpdate
202-
token = Authorization.new.getToken($merchantconfig_obj, gmtDateTime)
204+
token = Authorization.new.getToken(@merchantconfig, gmtDateTime)
203205

204206
# Adding client ID header
205207
header_params['v-c-client-id'] = @client_id
206208

207209
# Adding solution ID header
208-
# header_params['v-c-solution-id'] = $merchantconfig_obj.solutionId if !$merchantconfig_obj.solutionId.nil? && !$merchantconfig_obj.solutionId.empty?
210+
# header_params['v-c-solution-id'] = @merchantconfig.solutionId if !@merchantconfig.solutionId.nil? && !@merchantconfig.solutionId.empty?
209211
# HTTP header 'Accept' (if needed)
210-
if $merchantconfig_obj.authenticationType.upcase == Constants::AUTH_TYPE_HTTP
212+
if @merchantconfig.authenticationType.upcase == Constants::AUTH_TYPE_HTTP
211213
# Appending headers for Get Connection
212-
header_params['v-c-merchant-id'] = $merchantconfig_obj.merchantId
214+
header_params['v-c-merchant-id'] = @merchantconfig.merchantId
213215
header_params['Date'] = gmtDateTime
214-
header_params['Host'] = $merchantconfig_obj.requestHost
216+
header_params['Host'] = @merchantconfig.requestHost
215217
header_params['Signature'] = token
216218
if request_type == Constants::POST_REQUEST_TYPE || request_type == Constants::PUT_REQUEST_TYPE || request_type == Constants::PATCH_REQUEST_TYPE
217219
digest = DigestGeneration.new.generateDigest(body_params)
218220
digest_payload = Constants::SHA256 + digest
219221
header_params['Digest'] = digest_payload
220222
end
221223
end
222-
if $merchantconfig_obj.authenticationType.upcase == Constants::AUTH_TYPE_JWT
224+
if @merchantconfig.authenticationType.upcase == Constants::AUTH_TYPE_JWT
223225
token = "Bearer " + token
224226
header_params['Authorization'] = token
225227
end
226-
if $merchantconfig_obj.authenticationType.upcase == Constants::AUTH_TYPE_OAUTH
228+
if @merchantconfig.authenticationType.upcase == Constants::AUTH_TYPE_OAUTH
227229
token = "Bearer " + token
228230
header_params['Authorization'] = token
229231
end

lib/cybersource_rest_client/api_client.rb

+28-26
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ module CyberSource
2020
class ApiClient
2121
# The Configuration object holding settings to be used in the API client.
2222
attr_accessor :config
23+
24+
attr_accessor :merchantconfig
2325

2426
# Defines the headers to be used in HTTP requests of all API calls by default.
2527
#
@@ -115,13 +117,13 @@ def build_request(http_method, path, opts = {})
115117
end
116118

117119
headers = opts[:header_params]
118-
if $merchantconfig_obj.authenticationType.upcase != Constants::AUTH_TYPE_MUTUAL_AUTH
120+
if @merchantconfig.authenticationType.upcase != Constants::AUTH_TYPE_MUTUAL_AUTH
119121
headers = CallAuthenticationHeader(http_method, path, body_params, headers, query_params)
120122
end
121123
http_method = http_method.to_sym.downcase
122124
header_params = headers.merge(@default_headers)
123-
if $merchantconfig_obj.defaultCustomHeaders
124-
header_params = header_params.merge($merchantconfig_obj.defaultCustomHeaders)
125+
if @merchantconfig.defaultCustomHeaders
126+
header_params = header_params.merge(@merchantconfig.defaultCustomHeaders)
125127
end
126128
form_params = opts[:form_params] || {}
127129

@@ -130,9 +132,9 @@ def build_request(http_method, path, opts = {})
130132
_verify_ssl_host = @config.verify_ssl_host ? 2 : 0
131133

132134
# client cert
133-
if $merchantconfig_obj.enableClientCert
134-
@config.cert_file = File.join($merchantconfig_obj.clientCertDirectory, $merchantconfig_obj.sslClientCert)
135-
@config.key_file = File.join($merchantconfig_obj.clientCertDirectory, $merchantconfig_obj.privateKey)
135+
if @merchantconfig.enableClientCert
136+
@config.cert_file = File.join(@merchantconfig.clientCertDirectory, @merchantconfig.sslClientCert)
137+
@config.key_file = File.join(@merchantconfig.clientCertDirectory, @merchantconfig.privateKey)
136138
end
137139

138140
req_opts = {
@@ -144,7 +146,7 @@ def build_request(http_method, path, opts = {})
144146
:ssl_verifypeer => @config.verify_ssl,
145147
:ssl_verifyhost => _verify_ssl_host,
146148
:sslcert => @config.cert_file,
147-
:sslkeypasswd => $merchantconfig_obj.sslKeyPassword || "",
149+
:sslkeypasswd => @merchantconfig.sslKeyPassword || "",
148150
:sslkey => @config.key_file,
149151
:verbose => @config.debugging
150152
}
@@ -172,13 +174,13 @@ def build_request(http_method, path, opts = {})
172174
# set merchantConfig
173175
def set_configuration(config)
174176
require_relative '../AuthenticationSDK/core/MerchantConfig.rb'
175-
$merchantconfig_obj = Merchantconfig.new(config)
176-
@config.host = $merchantconfig_obj.requestHost
177-
if $merchantconfig_obj.intermediateHost
178-
@config.host = $merchantconfig_obj.intermediateHost
179-
if $merchantconfig_obj.intermediateHost.start_with?(Constants::HTTPS_URI_PREFIX)
177+
@merchantconfig = Merchantconfig.new(config)
178+
@config.host = @merchantconfig.requestHost
179+
if @merchantconfig.intermediateHost
180+
@config.host = @merchantconfig.intermediateHost
181+
if @merchantconfig.intermediateHost.start_with?(Constants::HTTPS_URI_PREFIX)
180182
@config.scheme = 'https'
181-
elsif $merchantconfig_obj.intermediateHost.start_with?(Constants::HTTP_URI_PREFIX)
183+
elsif @merchantconfig.intermediateHost.start_with?(Constants::HTTP_URI_PREFIX)
182184
@config.scheme = 'http'
183185
end
184186
end
@@ -190,44 +192,44 @@ def CallAuthenticationHeader(http_method, path, body_params, header_params, quer
190192
request_target = get_query_param(path, query_params)
191193
# Request Type. [Non-Editable]
192194
request_type = http_method.to_s
193-
log_obj = Log.new $merchantconfig_obj.log_config, "ApiClient"
195+
log_obj = Log.new @merchantconfig.log_config, "ApiClient"
194196
# Set Request Type into the merchant config object.
195-
$merchantconfig_obj.requestType = request_type
197+
@merchantconfig.requestType = request_type
196198
# Set Request Target into the merchant config object.
197-
$merchantconfig_obj.requestTarget = request_target
199+
@merchantconfig.requestTarget = request_target
198200
# Construct the URL.
199-
url = Constants::HTTPS_URI_PREFIX + $merchantconfig_obj.requestHost + $merchantconfig_obj.requestTarget
201+
url = Constants::HTTPS_URI_PREFIX + @merchantconfig.requestHost + @merchantconfig.requestTarget
200202
# set Request Json to Merchant config object
201-
$merchantconfig_obj.requestJsonData = body_params
203+
@merchantconfig.requestJsonData = body_params
202204
# Set URL into the merchant config object.
203-
$merchantconfig_obj.requestUrl = url
205+
@merchantconfig.requestUrl = url
204206
# Calling APISDK, Apisdk.controller.
205207
gmtDateTime = DateTime.now.httpdate
206-
token = Authorization.new.getToken($merchantconfig_obj, gmtDateTime)
208+
token = Authorization.new.getToken(@merchantconfig, gmtDateTime)
207209

208210
# Adding client ID header
209211
header_params['v-c-client-id'] = @client_id
210212

211213
# Adding solution ID header
212-
# header_params['v-c-solution-id'] = $merchantconfig_obj.solutionId if !$merchantconfig_obj.solutionId.nil? && !$merchantconfig_obj.solutionId.empty?
214+
# header_params['v-c-solution-id'] = @merchantconfig.solutionId if !@merchantconfig.solutionId.nil? && !@merchantconfig.solutionId.empty?
213215
# HTTP header 'Accept' (if needed)
214-
if $merchantconfig_obj.authenticationType.upcase == Constants::AUTH_TYPE_HTTP
216+
if @merchantconfig.authenticationType.upcase == Constants::AUTH_TYPE_HTTP
215217
# Appending headers for Get Connection
216-
header_params['v-c-merchant-id'] = $merchantconfig_obj.merchantId
218+
header_params['v-c-merchant-id'] = @merchantconfig.merchantId
217219
header_params['Date'] = gmtDateTime
218-
header_params['Host'] = $merchantconfig_obj.requestHost
220+
header_params['Host'] = @merchantconfig.requestHost
219221
header_params['Signature'] = token
220222
if request_type == Constants::POST_REQUEST_TYPE || request_type == Constants::PUT_REQUEST_TYPE || request_type == Constants::PATCH_REQUEST_TYPE
221223
digest = DigestGeneration.new.generateDigest(body_params)
222224
digest_payload = Constants::SHA256 + digest
223225
header_params['Digest'] = digest_payload
224226
end
225227
end
226-
if $merchantconfig_obj.authenticationType.upcase == Constants::AUTH_TYPE_JWT
228+
if @merchantconfig.authenticationType.upcase == Constants::AUTH_TYPE_JWT
227229
token = "Bearer " + token
228230
header_params['Authorization'] = token
229231
end
230-
if $merchantconfig_obj.authenticationType.upcase == Constants::AUTH_TYPE_OAUTH
232+
if @merchantconfig.authenticationType.upcase == Constants::AUTH_TYPE_OAUTH
231233
token = "Bearer " + token
232234
header_params['Authorization'] = token
233235
end

0 commit comments

Comments
 (0)