Skip to content

Commit

Permalink
Added missing header values
Browse files Browse the repository at this point in the history
  • Loading branch information
malinowskikam committed Aug 26, 2024
1 parent 110473d commit d403d94
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
11 changes: 8 additions & 3 deletions msystems/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
"mpass_key_dob": "BirthDate",
"mpass_key_roles": "Role",
"mpass_key_legal_entities": "OrganizationAdministrator",
#"mpass_key_legal_entities": "AdministeredLegalEntity",

# "mpass_key_legal_entities": "AdministeredLegalEntity",

# Mpass configurations
"mpass_config": {
Expand Down Expand Up @@ -97,7 +96,13 @@
# The same as mpass private key
"service_private_key": "",
# Mconnect certificate, PEM string format
"mconnect_certificate": ""
"mconnect_certificate": "",

# Get Person Soap Header default values
"get_person_calling_user": "", # len 13
"get_person_calling_entity": "", # len 13
"get_person_call_basis": "", # max len 256
"get_person_call_reason": "", # max len 512
}
}

Expand Down
26 changes: 24 additions & 2 deletions msystems/client/mconnect.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import logging

from zeep import Client, Settings

from core.models import User
from msystems.apps import MsystemsConfig
from msystems.client.utils import SoapWssePlugin, SoapClientError
from policyholder.models import PolicyHolder

logger = logging.getLogger(__name__)


class MconnectClient:
Expand All @@ -16,8 +22,24 @@ def __init__(self):
MsystemsConfig.mconnect_config['service_certificate'],
MsystemsConfig.mconnect_config['mconnect_certificate'])])

def get_person(self, idnp):
def get_person(self, idnp: str, user: User = None, economic_unit: PolicyHolder = None):
service_handle = self.client.service['GetPerson']
if not service_handle:
raise SoapClientError("Service GetPerson not found")
return service_handle(IDNP=idnp)

# Bounds for headers and idnp from Mconnect documentation, should not be exceeded in normal operation
# Added for extra protection

headers = {
"CallingUser": user.username[:13] or MsystemsConfig.mconnect_config['get_person_calling_user'][:13],
"CallingEntity": economic_unit.trade_name[:13]
or MsystemsConfig.mconnect_config['get_person_calling_entity'][:13],
"CallBasis": MsystemsConfig.mconnect_config['get_person_call_basis'][:256],
"CallReason": MsystemsConfig.mconnect_config['get_person_call_reason'][:512]
}

try:
return service_handle(IDNP=idnp[:13], _soapheaders=headers)
except Exception as e:
logger.error("Error during Mconnect request", exc_info=e)
raise SoapClientError(str(e))

0 comments on commit d403d94

Please sign in to comment.