Skip to content

Commit

Permalink
1. Extended auth support, you can now pass in any request.auth method…
Browse files Browse the repository at this point in the history
… to auth.

2. Added class docstring.
3. Renamed class to Client and kept old create_client as deprecated.
  • Loading branch information
kristjan.vilgo committed Jan 2, 2024
1 parent 6188ddb commit dda04c3
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 11 deletions.
71 changes: 62 additions & 9 deletions EDX/MADES_SOAP_API.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,68 @@

# TODO - add logging

class create_client():

def __init__(self, server, username="", password="", debug=False):
class Client:
"""
This class is designed to create a client for interacting with an EDX MADES SOAP web service.
The client is initialized with a server address and optional parameters for authentication,
debugging, and SSL verification. It sets up a session with the server and configures
the client for the specified web service using WSDL (Web Services Description Language).
Attributes:
service: The raw SOAP service object which can be used to make requests to the web service.
history: If debugging is enabled, this attribute stores the history of transactions.
debug: Boolean flag to enable or disable debugging.
Args:
server (str): The server address or IP where the web service is hosted.
This parameter is mandatory.
username (str, optional): The username for HTTP basic authentication.
Defaults to None.
password (str, optional): The password for HTTP basic authentication.
Defaults to None.
debug (bool, optional): Flag to enable or disable debugging features.
Defaults to False.
verify (bool, optional): Flag to enable or disable SSL verification.
Defaults to False.
auth (requests.auth.AuthBase, optional): Custom authentication mechanism. Any auth supported by "requests.auth" can be used.
Defaults to None.
Methods:
_print_last_message_exchange: Prints the last sent and received SOAP messages.
Works only if debug mode is enabled.
connectivity_test: Performs a connectivity test with the given receiver EIC and business type.
Returns a message ID.
send_message: Sends a message to the specified receiver with given parameters.
Returns a message ID.
check_message_status: Checks the status of a message using its message ID.
Returns the status of the message.
receive_message: Receives a message of a specified business type.
Returns the received message and the remaining message count.
confirm_received_message: Confirms the receipt of a message using its message ID.
Returns the same message ID as confirmation.
Notes:
- If 'username' is provided, HTTP basic authentication is set up with 'username' and 'password' and will perform preemptive auth.
- If 'auth' is provided, it is used as the authentication mechanism.
- Enabling 'debug' logs detailed information about the raw SOAP requests and responses.
"""

def __init__(self, server, username=None, password=None, debug=False, verify=False, auth=None):

"""At minimum server address or IP must be provided"""

wsdl = '{}/ws/madesInWSInterface.wsdl'.format(server)

session = Session()
session.verify = False
session.auth = HTTPBasicAuth(username, password)
session.get(server) # Preemptive auth, needed for keycloak
session = Session()
session.verify = verify

if username:
session.auth = HTTPBasicAuth(username, password)
session.get(server) # Preemptive auth, needed for keycloak

if auth:
session.auth = auth

transport = Transport(session=session)
self.history = HistoryPlugin()
Expand Down Expand Up @@ -112,16 +162,19 @@ def confirm_received_message(self, message_id):
return message_id


# TEST
# Deprecated class name
create_client = Client


# TEST

if __name__ == '__main__':

server = "https://er-opde-acceptance.elering.sise"
username = input("UserName")
password = input("PassWord")

service = create_client(server, username, password)
service = Client(server, username, password)

# Send message example

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ or
### Initialise
import EDX

service = EDX.create_client("https://edx.elering.sise")
service = EDX.Client("https://edx.elering.sise")
*create_client is depricated*

### Send message
with open("message.xml", "rb") as loaded_file:
Expand All @@ -35,7 +36,7 @@ or
service.confirm_received_message(message.receivedMessage.messageID)

### Save message on drive
*in case of excel use .xlsx and in case of PDF use .pdf and etc*
*in case of Excel use .xlsx and in case of PDF use .pdf and etc*

with open("report.xml", 'wb') as report_file:
report_file.write(message.receivedMessage.content)
Expand Down

0 comments on commit dda04c3

Please sign in to comment.