mirror of
https://github.com/lucaspalomodevelop/indico-plugins.git
synced 2026-03-13 07:29:39 +00:00
VC/Vidyo: use zeep instead of suds
suds' handling of Vidyo WSDL seems broken. zeep is kept up-to-date and much more pythonic/modern.
This commit is contained in:
parent
4ac9f4e6b9
commit
d0bb5b7b7c
@ -14,24 +14,21 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Indico; if not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from suds.cache import Cache
|
||||
from zeep.cache import Base
|
||||
from indico.legacy.common.cache import GenericCache
|
||||
|
||||
DEFAULT_CACHE_TTL = 24 * 3600
|
||||
|
||||
|
||||
class SudsCache(Cache):
|
||||
class ZeepCache(Base):
|
||||
_instance = None
|
||||
|
||||
def __init__(self, duration=DEFAULT_CACHE_TTL):
|
||||
self._cache = GenericCache("SudsCache")
|
||||
self._cache = GenericCache("ZeepCache")
|
||||
self._duration = duration
|
||||
|
||||
def get(self, key):
|
||||
self._cache.get(key)
|
||||
def get(self, url):
|
||||
self._cache.get(url)
|
||||
|
||||
def put(self, key, val):
|
||||
self._cache.set(key, val, self._duration)
|
||||
|
||||
def purge(self, key):
|
||||
self._cache.delete(key)
|
||||
def add(self, url, content):
|
||||
self._cache.set(url, content, self._duration)
|
||||
|
||||
@ -14,13 +14,13 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Indico; if not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import re
|
||||
from requests import Session
|
||||
from requests.auth import HTTPBasicAuth
|
||||
from zeep import Client
|
||||
from zeep.exceptions import Fault
|
||||
from zeep.transports import Transport
|
||||
|
||||
from suds import WebFault
|
||||
from suds.client import Client
|
||||
from suds.transport.https import HttpAuthenticated
|
||||
|
||||
from indico_vc_vidyo.api.cache import SudsCache
|
||||
from indico_vc_vidyo.api.cache import ZeepCache
|
||||
|
||||
DEFAULT_CLIENT_TIMEOUT = 30
|
||||
AUTOMUTE_API_PROFILE = "NoAudioAndVideo"
|
||||
@ -38,8 +38,8 @@ def raises_api_error(wrapped):
|
||||
def _wrapper(*args, **kwargs):
|
||||
try:
|
||||
return wrapped(*args, **kwargs)
|
||||
except WebFault as err:
|
||||
err_msg = err.fault.faultstring
|
||||
except Fault as err:
|
||||
err_msg = err.message
|
||||
if err_msg.startswith('Room not found for roomID') or 'Invalid roomID' in err_msg:
|
||||
raise RoomNotFoundAPIException()
|
||||
else:
|
||||
@ -49,9 +49,11 @@ def raises_api_error(wrapped):
|
||||
|
||||
class ClientBase(object):
|
||||
def __init__(self, wsdl, settings):
|
||||
transport = HttpAuthenticated(username=settings.get('username'), password=settings.get('password'),
|
||||
timeout=DEFAULT_CLIENT_TIMEOUT)
|
||||
self.client = Client(wsdl, cache=SudsCache(), transport=transport, location=re.sub(r'\?wsdl$', '', wsdl))
|
||||
session = Session()
|
||||
transport = Transport(session=session, cache=ZeepCache())
|
||||
session.auth = HTTPBasicAuth(settings.get('username'), settings.get('password'))
|
||||
self.client = Client(wsdl, transport=transport)
|
||||
self.factory = self.client.type_factory('ns0')
|
||||
|
||||
@property
|
||||
def soap(self):
|
||||
@ -68,25 +70,20 @@ class AdminClient(ClientBase):
|
||||
super(AdminClient, self).__init__(settings.get('admin_api_wsdl'), settings)
|
||||
|
||||
def create_room_object(self, **kwargs):
|
||||
room = self.client.factory.create('Room')
|
||||
|
||||
for key, value in kwargs.iteritems():
|
||||
setattr(room, key, value)
|
||||
|
||||
return room
|
||||
return self.factory.Room(**kwargs)
|
||||
|
||||
@raises_api_error
|
||||
def find_room(self, extension):
|
||||
from indico_vc_vidyo.plugin import VidyoPlugin
|
||||
filter_ = self.client.factory.create('Filter')
|
||||
filter_.query = extension
|
||||
filter_.limit = 40
|
||||
filter_.dir = 'DESC'
|
||||
|
||||
filter_ = {
|
||||
'query': extension,
|
||||
'limit': 40,
|
||||
'dir': 'DESC'
|
||||
}
|
||||
counter = 0
|
||||
|
||||
while True:
|
||||
filter_.start = counter * filter_.limit
|
||||
filter_['start'] = counter * filter_['limit']
|
||||
response = self.soap.getRooms(filter_)
|
||||
if not response.total:
|
||||
return None
|
||||
@ -100,23 +97,23 @@ class AdminClient(ClientBase):
|
||||
|
||||
@raises_api_error
|
||||
def get_room(self, vidyo_id):
|
||||
return self.soap.getRoom(vidyo_id)
|
||||
return self.soap.getRoom(roomID=vidyo_id)
|
||||
|
||||
@raises_api_error
|
||||
def add_room(self, room_obj):
|
||||
self.soap.addRoom(room_obj)
|
||||
self.soap.addRoom(room=room_obj)
|
||||
|
||||
@raises_api_error
|
||||
def update_room(self, room_id, room_obj):
|
||||
self.soap.updateRoom(room_id, room_obj)
|
||||
self.soap.updateRoom(roomID=room_id, room=room_obj)
|
||||
|
||||
@raises_api_error
|
||||
def delete_room(self, room_id):
|
||||
self.soap.deleteRoom(room_id)
|
||||
self.soap.deleteRoom(roomID=room_id)
|
||||
|
||||
@raises_api_error
|
||||
def get_automute(self, room_id):
|
||||
answer = self.soap.getRoomProfile(room_id)
|
||||
answer = self.soap.getRoomProfile(roomID=room_id)
|
||||
if answer:
|
||||
return answer.roomProfileName == AUTOMUTE_API_PROFILE
|
||||
else:
|
||||
@ -125,6 +122,6 @@ class AdminClient(ClientBase):
|
||||
@raises_api_error
|
||||
def set_automute(self, room_id, status):
|
||||
if status:
|
||||
self.soap.setRoomProfile(room_id, AUTOMUTE_API_PROFILE)
|
||||
self.soap.setRoomProfile(roomID=room_id, roomProfileName=AUTOMUTE_API_PROFILE)
|
||||
else:
|
||||
self.soap.removeRoomProfile(room_id)
|
||||
self.soap.removeRoomProfile(roomID=room_id)
|
||||
|
||||
@ -163,17 +163,24 @@ class VidyoPlugin(VCPluginMixin, IndicoPlugin):
|
||||
extension = next(extension_gen)
|
||||
|
||||
while True:
|
||||
room_mode = {
|
||||
'isLocked': False,
|
||||
'hasPIN': vc_room.data['room_pin'] != "",
|
||||
'hasModeratorPIN': vc_room.data['moderation_pin'] != ""
|
||||
}
|
||||
if room_mode['hasPIN']:
|
||||
room_mode['roomPIN'] = vc_room.data['room_pin']
|
||||
if room_mode['hasModeratorPIN']:
|
||||
room_mode['moderatorPIN'] = vc_room.data['moderation_pin']
|
||||
|
||||
room_obj = client.create_room_object(
|
||||
name=vc_room.name,
|
||||
RoomType='Public',
|
||||
ownerName=login,
|
||||
extension=extension,
|
||||
groupName=self.settings.get('room_group_name'),
|
||||
description=vc_room.data['description'])
|
||||
|
||||
room_obj.RoomMode.isLocked = False
|
||||
room_obj.RoomMode.hasPIN = vc_room.data['room_pin'] != ""
|
||||
room_obj.RoomMode.hasModeratorPIN = vc_room.data['moderation_pin'] != ""
|
||||
description=vc_room.data['description'],
|
||||
RoomMode=room_mode)
|
||||
|
||||
if room_obj.RoomMode.hasPIN:
|
||||
room_obj.RoomMode.roomPIN = vc_room.data['room_pin']
|
||||
|
||||
@ -32,7 +32,7 @@ setup(
|
||||
platforms='any',
|
||||
install_requires=[
|
||||
'indico>=1.9.10',
|
||||
'suds-jurko'
|
||||
'zeep'
|
||||
],
|
||||
classifiers=[
|
||||
'Environment :: Plugins',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user