Skip to content

Commit

Permalink
Merge pull request #4 from DUNE-DAQ/plasorak/update-to-latest
Browse files Browse the repository at this point in the history
Update to latest elisa_client_api
  • Loading branch information
plasorak authored Feb 8, 2024
2 parents aff1cab + cfee82d commit 741648c
Show file tree
Hide file tree
Showing 23 changed files with 420 additions and 382 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ unittest
urllib
mimetypes
xml
lxml==5.1.0
http
2 changes: 1 addition & 1 deletion src/elisa_client_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.2.0"
__version__ = "1.0.0"
20 changes: 8 additions & 12 deletions src/elisa_client_api/core/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
# 18/Dec/2012: created.
#--------------------------------------------------------------------------------------

from future import standard_library
standard_library.install_aliases()
from builtins import str
from builtins import object
from elisa_client_api.exception import ArgumentError


Expand Down Expand Up @@ -49,7 +53,8 @@ def __init__(self, username=None, password=None, ssocookie=None):
cj = http.cookiejar.MozillaCookieJar()
cj.load(filename=ssocookie, ignore_discard=True, ignore_expires=True)
for cookie in cj:
if cookie.name.startswith('_shibsession'):
# if True == cookie.name.startswith('_shibsession'):
if cookie.name.startswith('_shibsession') or cookie.name == 'mod_auth_openidc_session':
self.__ssocookie = cookie.name + '=' + cookie.value

# ------------------
Expand All @@ -63,23 +68,14 @@ def addAuthentication(self, req):
else:
req.add_header("Authorization", "Basic %s" % self._getEncodedCredentials().decode())

def addAuthenticationPy3(self, req):
def addAuthenticationPy3(self,req):
""" Adds the appropriate authentication header in the http request.
"""
if self.__ssocookie != None:
req.headers['Cookie'] = self.__ssocookie
else:
req.headers['Authorization'] = "Basic %s" % self._getEncodedCredentials().decode()

def addAuthenticationToDict(self, d):
""" Adds the appropriate authentication header in the http request.
"""

if self.__ssocookie != None:
d['Cookie'] = self.__ssocookie
else:
d['Authorization'] = "Basic %s" % self._getEncodedCredentials().decode()


# -------------------
# - Private methods -
Expand All @@ -88,4 +84,4 @@ def _getEncodedCredentials(self):
""" Encodes the string username:password with basic 64
"""
import base64
return base64.encodestring(('%s:%s' % (self.__username, self.__password)).encode())[:-1]
return base64.encodebytes(('%s:%s' % (self.__username, self.__password)).encode())[:-1]
64 changes: 34 additions & 30 deletions src/elisa_client_api/core/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
# 05/Dec/2012: created.
#--------------------------------------------------------------------------------------

from __future__ import absolute_import
from builtins import str
from builtins import object
import string

from .messageField import SimpleField, AttachmentField, SystemsAffectedField, OptionField

class Status(object):
Expand All @@ -28,7 +33,7 @@ class Status(object):

class Message(object):
""" Class with all the fields of a logbook message.
Accessors will be provided as needed in derived classes.
"""
# ------------------
Expand All @@ -39,14 +44,14 @@ def __init__(self, id):
# - Private data attributes -
# ---------------------------

# The field name parameter is the same as those use in the ELisA server.
# This schema allows for generic code when serializing, deserializing
# The field name parameter is the same as those use in the ELisA server.
# This schema allows for generic code when serializing, deserializing
# and printing the fields.
self._id = SimpleField('id', id)
self._logbook = SimpleField('logbook')
self._username = SimpleField('username')
self._author = SimpleField('author')
self._date = SimpleField('date')
self._date = SimpleField('date')
self._subject = SimpleField('subject')
self._message_type = SimpleField('message_type')
self._systems_affected = SystemsAffectedField('systems_affected')
Expand All @@ -61,27 +66,27 @@ def __init__(self, id):
self._thread_head = SimpleField('thread_head')
self._valid = SimpleField('valid')
self._encoding = SimpleField('encoding')


def __str__(self):
dump = ""
fields = self.getFieldNames()
for field in fields:
dump += str(getattr(self, field)) + '\n'
dump += str(getattr(self, field)) + '\n'
return dump


def getFieldNames(self):
return [attr for attr in dir(self) if getattr(self, attr).__class__.__name__ == "SimpleField" \
or getattr(self, attr).__class__.__name__ == "AttachmentField" \
or getattr(self, attr).__class__.__name__ == "OptionField" \
or getattr(self, attr).__class__.__name__ == "SystemsAffectedField"]


def getTag(self):
return "_"


# --------------------
# - Property methods -
# --------------------
Expand All @@ -94,37 +99,37 @@ def id(self):
def logbook(self):
""" Message logbook field. """
return self._logbook.value

@property
def userName(self):
""" Message user name field. """
return self._username.value

@property
def author(self):
""" Message author field. """
return self._author.value

@property
def date(self):
""" Message date field. """
return self._date.value

@property
def subject(self):
""" Message subject field. """
return self._subject.value

@property
def type(self):
""" Message type field. """
return self._message_type.value

@property
def options(self):
""" Message options field. """
return self._options .value
return self._options .value

@property
def systemsAffected(self):
""" Message systems affected field. """
Expand All @@ -139,45 +144,44 @@ def body(self):
def host(self):
""" Message host field. """
return self._host.value

@property
def hasReplies(self):
""" Message has replies field. """
return self._has_replies.value

@property
def replyTo(self):
""" Message reply to field. """
return self._reply_to.value

@property
def hasAttachments(self):
""" Message has attachments field. """
return self._has_attachments.value

@property
def attachments(self):
""" Message attachments field. """
return self._attachments.value

@property
def status(self):
""" Message status field. """
return self._status.value

@property
def threadHead(self):
""" Message thread head field. """
return self._thread_head.value

@property
def valid(self):
""" Message valid field. """
return self._valid.value

@property
def encoding(self):
""" Message encoding field. """
return self._encoding.value


Loading

0 comments on commit 741648c

Please sign in to comment.