Skip to content

Check IS MLE Flag #153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions authenticationsdk/core/MerchantConfiguration.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def __init__(self):
self.log_config = None
self.__jwePEMFileDirectory = None
self.useMLEGlobally = None
self.useMLEGloballyForRequest = None
self.mapToControlMLEonAPI = None
self.mleKeyAlias = None
self.logger = LogFactory.setup_logger(self.__class__.__name__)
Expand Down Expand Up @@ -184,14 +185,22 @@ def set_jwePEMFileDirectory(self, value):
def get_jwePEMFileDirectory(self):
return self.__jwePEMFileDirectory

def set_useMLEGlobally(self, value):
if not (value.get('useMLEGlobally') is None):
self.useMLEGlobally = value['useMLEGlobally']
def set_useMLEGloballyForRequest(self, value):
if value.get('useMLEGloballyForRequest') is not None:
self.useMLEGloballyForRequest = value['useMLEGloballyForRequest']
elif value.get('useMLEGlobally') is not None:
self.useMLEGloballyForRequest = value['useMLEGlobally']
else:
self.useMLEGlobally = False

def get_useMLEGlobally(self):
return self.useMLEGlobally
self.useMLEGloballyForRequest = False

# self.useMLEGloballyForRequest = (
# value.get('useMLEGloballyForRequest')
# or value.get('useMLEGlobally')
# or False
# )

def get_useMLEGloballyForRequest(self):
return self.useMLEGloballyForRequest

def set_mapToControlMLEonAPI(self, value):
map_to_control_mle_on_api = value.get('mapToControlMLEonAPI')
Expand Down Expand Up @@ -245,7 +254,7 @@ def set_merchantconfig(self, val):
self.set_refresh_token(val)
self.set_log_configuration(val)
self.set_jwePEMFileDirectory(val)
self.set_useMLEGlobally(val)
self.set_useMLEGloballyForRequest(val)
self.set_mapToControlMLEonAPI(val)
self.set_mleKeyAlias(val)

Expand Down Expand Up @@ -375,8 +384,8 @@ def validate_merchant_details(self, details, mconfig = None):
GlobalLabelParameters.AUTH_ERROR,
self.log_config)
# useMLEGlobally check for auth Type
if self.useMLEGlobally is True or self.mapToControlMLEonAPI is not None:
if self.useMLEGlobally is True and self.authentication_type.lower() != GlobalLabelParameters.JWT.lower():
if self.useMLEGloballyForRequest is True or self.mapToControlMLEonAPI is not None:
if self.useMLEGloballyForRequest is True and self.authentication_type.lower() != GlobalLabelParameters.JWT.lower():
authenticationsdk.util.ExceptionAuth.validate_merchant_details_log(self.logger,
GlobalLabelParameters.MLE_AUTH_ERROR,
self.log_config)
Expand Down
21 changes: 18 additions & 3 deletions authenticationsdk/util/MLEUtility.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,26 @@ def __init__(self, message, errors=None):
self.errors = errors

@staticmethod
def check_is_mle_for_api(merchant_config, is_mle_supported_by_cybs_for_api, operation_ids):

def check_is_mle_for_api(merchant_config, inbound_mle_status, operation_ids):
is_mle_for_api = False
if is_mle_supported_by_cybs_for_api and merchant_config.get_useMLEGlobally():
is_mle_supported_by_cybs_for_api = False

# Check if MLE is supported by Cybs for API
if inbound_mle_status and inbound_mle_status.lower() in ("optional", "mandatory"):
is_mle_supported_by_cybs_for_api = True

if is_mle_supported_by_cybs_for_api and merchant_config.get_useMLEGloballyForRequest():
is_mle_for_api = True

logger = LogFactory.setup_logger(__name__, merchant_config.log_config)

if inbound_mle_status and inbound_mle_status.lower() == "mandatory" and not merchant_config.get_useMLEGloballyForRequest():
is_mle_for_api = True
logger.warning(
"MLE is required for this operation (mandatory), but the global MLE flag is disabled. "
"Enabling MLE for this API call as required by CyberSource."
)

operation_array = [op_id.strip() for op_id in operation_ids.split(",")]
map_to_control_mle = merchant_config.get_mapToControlMLEonAPI()
if map_to_control_mle is not None and map_to_control_mle:
Expand Down
4 changes: 2 additions & 2 deletions generator/cybersource-python-template/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ class {{classname}}(object):
header_params['Content-Type'] = f"multipart/form-data; boundary={file_post_body_and_delimiter[1]}"
{{/bodyParam}}

is_mle_supported_by_cybs_for_api = {{#vendorExtensions.x-devcenter-metaData.isMLEsupported}}True{{/vendorExtensions.x-devcenter-metaData.isMLEsupported}}{{^vendorExtensions.x-devcenter-metaData.isMLEsupported}}False{{/vendorExtensions.x-devcenter-metaData.isMLEsupported}}
if MLEUtility.check_is_mle_for_api(self.api_client.mconfig, is_mle_supported_by_cybs_for_api, "{{operationId}},{{operationId}}_with_http_info"):
inbound_mle_status = "{{#vendorExtensions.x-devcenter-metaData.inboundMLEStatus}}{{vendorExtensions.x-devcenter-metaData.inboundMLEStatus}}{{/vendorExtensions.x-devcenter-metaData.inboundMLEStatus}}{{^vendorExtensions.x-devcenter-metaData.inboundMLEStatus}}false{{/vendorExtensions.x-devcenter-metaData.inboundMLEStatus}}"
if MLEUtility.check_is_mle_for_api(self.api_client.mconfig, inbound_mle_status, "{{operationId}},{{operationId}}_with_http_info"):
body_params = MLEUtility.encrypt_request_payload(self.api_client.mconfig, body_params)

# Authentication setting
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy