Skip to content

Commit acd5a99

Browse files
removing request fields from merchantConfig
1 parent 0ec713e commit acd5a99

File tree

6 files changed

+41
-44
lines changed

6 files changed

+41
-44
lines changed

CyberSource/api_client.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -169,24 +169,17 @@ def set_configuration(self,config):
169169
self.host = self.mconfig.request_host
170170

171171
# Calling the authentication header
172-
def call_authentication_header(self, method, header_params, body):
172+
def call_authentication_header(self, method, header_params, body, request_target=None):
173173

174174
time = self.mconfig.get_time()
175175

176-
self.mconfig.request_type_method = method
177-
178-
179-
180-
if method.upper() == GlobalLabelParameters.POST or method.upper() == GlobalLabelParameters.PUT or method.upper() == GlobalLabelParameters.PATCH:
181-
self.mconfig.request_json_path_data = body
182-
183176
header_params['v-c-client-id'] = self.client_id
184177

185178
# if not self.mconfig.solution_id in (None, ''):
186179
# header_params['v-c-solution-id'] = self.mconfig.solution_id
187180

188181
auth = Authorization()
189-
token = auth.get_token(self.mconfig, self.mconfig.get_time())
182+
token = auth.get_token(self.mconfig, self.mconfig.get_time(), method, request_target, body)
190183
if self.mconfig.authentication_type.upper() == GlobalLabelParameters.HTTP.upper():
191184
header_params['Accept-Encoding'] = '*'
192185
header_params['v-c-merchant-id'] = self.mconfig.merchant_id
@@ -466,13 +459,10 @@ def call_api(self, resource_path, method,
466459
post_params = body
467460

468461
query_param_path = self.set_query_params(resource_path, query_params)
469-
if query_param_path:
470-
self.mconfig.request_target = query_param_path
471-
else:
472-
self.mconfig.request_target = resource_path
462+
request_target = query_param_path if query_param_path else resource_path
473463

474464
if self.mconfig.authentication_type.upper() != GlobalLabelParameters.MUTUAL_AUTH.upper():
475-
self.call_authentication_header(method, header_params, body)
465+
self.call_authentication_header(method, header_params, body, request_target)
476466

477467
"""
478468
Makes the HTTP request (synchronous) and return the deserialized data.

authenticationsdk/core/Authorization.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ def __init__(self):
1313
self.logger = None
1414

1515
# This method generates and return a encrypted signature based on the Authentication type
16-
def get_token(self, mconfig, date_time, logger = None):
16+
def get_token(self, mconfig, date_time, request_type_method, request_target=None, request_json_path_data=None, logger=None):
1717
authentication_type = mconfig.authentication_type
18-
self.validate_request_type_method(mconfig)
18+
self.validate_request_type_method(request_type_method)
1919
# Initializing the logger object
2020
self.logger = LogFactory.setup_logger(self.__class__.__name__, mconfig.log_config)
2121

@@ -24,21 +24,21 @@ def get_token(self, mconfig, date_time, logger = None):
2424

2525
if authentication_type.upper() == GlobalLabelParameters.HTTP.upper():
2626
http_sig_token = HTTPSignatureToken()
27-
http_sig_token.http_signature_token(mconfig, date_time)
27+
http_sig_token.http_signature_token(mconfig, date_time, request_type_method, request_target, request_json_path_data)
2828
sig_token = http_sig_token.get_token()
2929
# Logging the parameters Content-Type,Merchant id,Date ,Host to the log file
3030
if mconfig.log_config.enable_log is True:
31-
self.logger.info("Using Request Target: " + mconfig.request_target)
31+
self.logger.info("Using Request Target: " + request_target)
3232
self.logger.info("Authentication Type: " + mconfig.authentication_type)
33-
self.logger.info("Request-Type: " + mconfig.request_type_method)
33+
self.logger.info("Request-Type: " + request_type_method)
3434
self.logger.info(GlobalLabelParameters.CONTENT_TYPE + ": " + GlobalLabelParameters.APPLICATION_JSON)
3535
self.logger.info(GlobalLabelParameters.MERCHANT_ID + ": " + str(mconfig.merchant_id))
3636
self.logger.info(GlobalLabelParameters.DATE + ": " + date_time)
3737
self.logger.info(GlobalLabelParameters.HOST + ": " + mconfig.request_host)
3838
# Logging the Digest when Request_type_method is Post
39-
if mconfig.request_type_method.upper() == GlobalLabelParameters.POST or mconfig.request_type_method.upper() == GlobalLabelParameters.PUT:
39+
if request_type_method.upper() == GlobalLabelParameters.POST or request_type_method.upper() == GlobalLabelParameters.PUT:
4040
digest_obj = DigestAndPayload()
41-
encoded_digest = digest_obj.string_digest_generation(mconfig.request_json_path_data)
41+
encoded_digest = digest_obj.string_digest_generation(request_json_path_data)
4242
# self.logger.info(GlobalLabelParameters.DIGEST + ":" + GlobalLabelParameters.DIGEST_PREFIX + (encoded_digest).decode("utf-8"))
4343
# self.logger.info("Signature: " + sig_token)
4444

@@ -47,14 +47,14 @@ def get_token(self, mconfig, date_time, logger = None):
4747
elif authentication_type.upper() == GlobalLabelParameters.JWT.upper():
4848

4949
jwt_sig_token = JwtSignatureToken()
50-
jwt_sig_token.jwt_signature_token(mconfig, date_time)
50+
jwt_sig_token.jwt_signature_token(mconfig, date_time, request_type_method, request_json_path_data)
5151
sig_token_jwt = jwt_sig_token.get_token()
5252

5353
# Logging the parameters Content-Type,Merchant id,Date ,Host to the log file
5454
if mconfig.log_config.enable_log is True:
55-
self.logger.info("Using Request Target: " + mconfig.request_target)
55+
self.logger.info("Using Request Target: " + request_target)
5656
self.logger.info("Authentication Type: " + mconfig.authentication_type)
57-
self.logger.info("Request-Type: " + mconfig.request_type_method)
57+
self.logger.info("Request-Type: " + request_type_method)
5858
self.logger.info(GlobalLabelParameters.CONTENT_TYPE + ": " + GlobalLabelParameters.APPLICATION_JSON)
5959
self.logger.info(GlobalLabelParameters.MERCHANT_ID + ": " + str(mconfig.merchant_id))
6060
self.logger.info(GlobalLabelParameters.DATE + ": " + date_time)
@@ -88,8 +88,8 @@ def get_token(self, mconfig, date_time, logger = None):
8888
authenticationsdk.util.ExceptionAuth.log_exception(self.logger, repr(e), mconfig.log_config)
8989

9090
# noinspection PyMethodMayBeStatic
91-
def validate_request_type_method(self, mconfig):
91+
def validate_request_type_method(self, request_type_method):
9292

9393
if not (
94-
mconfig.request_type_method.upper() == GlobalLabelParameters.GET or mconfig.request_type_method.upper() == GlobalLabelParameters.POST or mconfig.request_type_method.upper() == GlobalLabelParameters.PUT or mconfig.request_type_method.upper() == GlobalLabelParameters.DELETE or mconfig.request_type_method.upper() == GlobalLabelParameters.PATCH):
94+
request_type_method.upper() == GlobalLabelParameters.GET or request_type_method.upper() == GlobalLabelParameters.POST or request_type_method.upper() == GlobalLabelParameters.PUT or request_type_method.upper() == GlobalLabelParameters.DELETE or request_type_method.upper() == GlobalLabelParameters.PATCH):
9595
raise ApiException(1, GlobalLabelParameters.INVALID_REQUEST_TYPE_METHOD)

authenticationsdk/core/MerchantConfiguration.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ def __init__(self):
2121
self.host_name = None
2222
self.url = None
2323
self.request_host = None
24-
self.request_type_method = None
25-
self.request_target = None
2624
self.authentication_type = None
2725
self.key_file_path = None
2826
self.run_environment = None
@@ -46,7 +44,6 @@ def __init__(self):
4644
self.proxy_address = None
4745
self.proxy_port = None
4846
self.key_file_name = None
49-
self.request_json_path_data = None
5047
self.solution_id = None
5148
self.log_config = None
5249
self.__jwePEMFileDirectory = None

authenticationsdk/http/GetSignatureParameter.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ def __init__(self):
1919
self.merchant_config_sigparam = None
2020
self.date = None
2121

22-
def get_signature_parameter(self, mconfig, merchant_secret_key, merchant_id, httpmethod, date):
22+
def get_signature_parameter(self, mconfig, merchant_secret_key, merchant_id, httpmethod, date, request_target=None, request_json_path_data=None):
2323

2424
self.merchant_config_sigparam = mconfig
2525
self.date = date
26+
self.request_target = request_target
27+
self.request_json_path_data = request_json_path_data
2628

2729
return self.get_signature_param(merchant_secret_key, merchant_id, httpmethod)
2830

@@ -51,20 +53,20 @@ def get_signature_param(self, merchant_secret_key, merchant_id, httpmethod):
5153
signature_list.append(": ")
5254
# This forms the get_request_target
5355
if httpmethod.upper() == GlobalLabelParameters.GET:
54-
get_request_target = GlobalLabelParameters.GET_LOWER_CASE + self.merchant_config_sigparam.request_target
56+
get_request_target = GlobalLabelParameters.GET_LOWER_CASE + self.request_target
5557
signature_list.append(get_request_target)
5658
# This forms the post_request_target
5759
elif httpmethod.upper() == GlobalLabelParameters.POST:
58-
post_request_target = GlobalLabelParameters.POST_LOWER_CASE + self.merchant_config_sigparam.request_target
60+
post_request_target = GlobalLabelParameters.POST_LOWER_CASE + self.request_target
5961
signature_list.append(post_request_target)
6062
elif httpmethod.upper() == GlobalLabelParameters.PUT:
61-
put_request_target = GlobalLabelParameters.PUT_LOWER_CASE + self.merchant_config_sigparam.request_target
63+
put_request_target = GlobalLabelParameters.PUT_LOWER_CASE + self.request_target
6264
signature_list.append(put_request_target)
6365
elif httpmethod.upper() == GlobalLabelParameters.PATCH:
64-
patch_request_target = GlobalLabelParameters.PATCH_LOWER_CASE + self.merchant_config_sigparam.request_target
66+
patch_request_target = GlobalLabelParameters.PATCH_LOWER_CASE + self.request_target
6567
signature_list.append(patch_request_target)
6668
elif httpmethod.upper() == GlobalLabelParameters.DELETE:
67-
delete_request_target = GlobalLabelParameters.DELETE_LOWER_CASE + self.merchant_config_sigparam.request_target
69+
delete_request_target = GlobalLabelParameters.DELETE_LOWER_CASE + self.request_target
6870
signature_list.append(delete_request_target)
6971

7072
signature_list.append("\n")
@@ -73,7 +75,7 @@ def get_signature_param(self, merchant_secret_key, merchant_id, httpmethod):
7375
if httpmethod.upper() == GlobalLabelParameters.POST or httpmethod.upper() == GlobalLabelParameters.PUT or httpmethod.upper() == GlobalLabelParameters.PATCH :
7476
digest_get_obj = DigestAndPayload()
7577
digest = digest_get_obj.string_digest_generation(
76-
self.merchant_config_sigparam.request_json_path_data)
78+
self.request_json_path_data)
7779
signature_list.append(GlobalLabelParameters.DIGEST.lower())
7880
signature_list.append(": ")
7981
signature_list.append(GlobalLabelParameters.DIGEST_PREFIX + digest.decode("utf-8"))

authenticationsdk/http/HTTPSignatureToken.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,19 @@ def __init__(self):
2424
self.http_merchant_id = None
2525
self.http_get_id = None
2626
self.date_time = None
27+
self.request_target = None
28+
self.request_json_path_data = None
2729

28-
def http_signature_token(self, mconfig,date_time):
30+
def http_signature_token(self, mconfig, date_time, request_type_method, request_target=None, request_json_path_data=None):
2931

3032
self.merchant_config_sighead = mconfig
3133
self.merchant_key_id_sig = str(mconfig.merchant_keyid)
3234
self.merchant_secret_key_sig = str(mconfig.merchant_secretkey)
33-
self.http_method_sig = mconfig.request_type_method
35+
self.http_method_sig = request_type_method
3436
self.http_merchant_id = mconfig.merchant_id
3537
self.date_time = date_time
38+
self.request_target = request_target
39+
self.request_json_path_data = request_json_path_data
3640

3741

3842
def get_token(self):
@@ -68,7 +72,9 @@ def signature_header(self):
6872
signature = get_signature_paramobj.get_signature_parameter(self.merchant_config_sighead,
6973
self.merchant_secret_key_sig,
7074
self.http_merchant_id, self.http_method_sig,
71-
self.date_time)
75+
self.date_time,
76+
self.request_target,
77+
self.request_json_path_data)
7278

7379
header_list.append(
7480
GlobalLabelParameters.SIGNATURE_HEADER + signature + "\"")

authenticationsdk/jwt/Token.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ def __init__(self):
1010
self.request_body = None
1111
self.jwt_method = None
1212
self.date = None
13+
self.request_json_path_data = None
1314

14-
def jwt_signature_token(self, mconfig, date_time):
15+
def jwt_signature_token(self, mconfig, date_time, request_type_method, request_json_path_data=None):
1516
self.merchant_config = mconfig
16-
self.jwt_method = mconfig.request_type_method
17+
self.jwt_method = request_type_method
1718
self.date = date_time
19+
self.request_json_path_data = request_json_path_data
1820

1921
def get_token(self):
2022
return self.set_token()
@@ -65,7 +67,7 @@ def token_for_post(self):
6567

6668
digest_payload_obj = DigestAndPayload()
6769
digest = digest_payload_obj.string_digest_generation(
68-
self.merchant_config.request_json_path_data)
70+
self.request_json_path_data)
6971
# Setting the jwt body for JWT-post
7072

7173
jwt_body = {GlobalLabelParameters.JWT_DIGEST: digest.decode("utf-8"), GlobalLabelParameters.JWT_ALGORITHM: "SHA-256",
@@ -92,7 +94,7 @@ def token_for_put(self):
9294

9395
digest_payload_obj = DigestAndPayload()
9496
digest = digest_payload_obj.string_digest_generation(
95-
self.merchant_config.request_json_path_data)
97+
self.request_json_path_data)
9698
# Setting the jwt body for JWT-post
9799
jwt_body = {GlobalLabelParameters.JWT_DIGEST: digest.decode("utf-8"), GlobalLabelParameters.JWT_ALGORITHM: "SHA-256",
98100
GlobalLabelParameters.JWT_TIME: self.date}
@@ -118,7 +120,7 @@ def token_for_patch(self):
118120

119121
digest_payload_obj = DigestAndPayload()
120122
digest = digest_payload_obj.string_digest_generation(
121-
self.merchant_config.request_json_path_data)
123+
self.request_json_path_data)
122124
# Setting the jwt body for JWT-post
123125
jwt_body = {GlobalLabelParameters.JWT_DIGEST: digest.decode("utf-8"),
124126
GlobalLabelParameters.JWT_ALGORITHM: "SHA-256",

0 commit comments

Comments
 (0)