def enableService(request: 'ExtendedHttpRequestWithUser', idService: str, idTransport: str) -> typing.Mapping[str, typing.Any]: # Maybe we could even protect this even more by limiting referer to own server /? (just a meditation..) logger.debug('idService: %s, idTransport: %s', idService, idTransport) url = '' error = ugettext('Service not ready. Please, try again in a while.') # If meta service, process and rebuild idService & idTransport try: res = userServiceManager().getService(request.user, request.os, request.ip, idService, idTransport, doTest=False) scrambler = cryptoManager().randomString(32) password = cryptoManager().symCrypt(webPassword(request), scrambler) userService, trans = res[1], res[3] typeTrans = trans.getType() error = '' # No error if typeTrans.ownLink: url = reverse('TransportOwnLink', args=('A' + userService.uuid, trans.uuid)) else: data = { 'service': 'A' + userService.uuid, 'transport': trans.uuid, 'user': request.user.uuid, 'password': password } ticket = TicketStore.create(data) url = html.udsLink(request, ticket, scrambler) except ServiceNotReadyError as e: logger.debug('Service not ready') # Not ready, show message and return to this page in a while # error += ' (code {0:04X})'.format(e.code) error = ugettext( 'Your service is being created, please, wait for a few seconds while we complete it.)' ) + '({}%)'.format(int(e.code * 25)) except MaxServicesReachedError: logger.info('Number of service reached MAX for service pool "%s"', idService) error = errors.errorString(errors.MAX_SERVICES_REACHED) except ServiceAccessDeniedByCalendar: logger.info('Access tried to a calendar limited access pool "%s"', idService) error = errors.errorString(errors.SERVICE_CALENDAR_DENIED) except Exception as e: logger.exception('Error') error = str(e) return {'url': str(url), 'error': str(error)}
def userServiceEnabler(request, idService, idTransport): # Maybe we could even protect this even more by limiting referer to own server /? (just a meditation..) logger.debug('idService: {}, idTransport: {}'.format( idService, idTransport)) url = '' error = _('Service not ready. Please, try again in a while.') # If meta service, process and rebuild idService & idTransport try: res = userServiceManager().getService(request.user, request.os, request.ip, idService, idTransport, doTest=False) scrambler = cryptoManager().randomString(32) password = cryptoManager().symCrypt(webPassword(request), scrambler) _x, userService, _x, trans, _x = res data = { 'service': 'A' + userService.uuid, 'transport': trans.uuid, 'user': request.user.uuid, 'password': password } ticket = TicketStore.create(data) error = '' url = html.udsLink(request, ticket, scrambler) except ServiceNotReadyError as e: logger.debug('Service not ready') # Not ready, show message and return to this page in a while error += ' (code {0:04X})'.format(e.code) except MaxServicesReachedError: logger.info( 'Number of service reached MAX for service pool "{}"'.format( idService)) error = errors.errorString(errors.MAX_SERVICES_REACHED) except ServiceAccessDeniedByCalendar: logger.info( 'Access tried to a calendar limited access pool "{}"'.format( idService)) error = errors.errorString(errors.SERVICE_CALENDAR_DENIED) except Exception as e: logger.exception('Error') error = str(e) return HttpResponse(json.dumps({ 'url': str(url), 'error': str(error) }), content_type='application/json')
def result(result: typing.Any = None, error: typing.Optional[typing.Union[str, int]] = None, errorCode: int = 0, retryable: bool = False) -> typing.Dict[str, typing.Any]: """ Helper method to create a "result" set for actor response :param result: Result value to return (can be None, in which case it is converted to empty string '') :param error: If present, This response represents an error. Result will contain an "Explanation" and error contains the error code :param errorCode: Code of the error to return, if error is not None :param retryable: If True, this operation can (and must) be retryed :return: A dictionary, suitable for response to Caller """ result = result if result is not None else '' res = {'result': result} if error is not None: if isinstance(error, int): error = errors.errorString(error) error = str(error) # Ensure error is an string if errorCode != 0: error += ' (code {0:04X})'.format(errorCode) res['error'] = error res['retryable'] = '1' if retryable else '0' logger.debug('Client Result: %s', res) return res
def result( result: typing.Any = None, error: typing.Optional[typing.Union[str, int]] = None, errorCode: int = 0, retryable: bool = False, ) -> typing.Dict[str, typing.Any]: """ Helper method to create a "result" set for connection response :param result: Result value to return (can be None, in which case it is converted to empty string '') :param error: If present, This response represents an error. Result will contain an "Explanation" and error contains the error code :return: A dictionary, suitable for response to Caller """ result = result if result is not None else '' res = {'result': result, 'date': datetime.datetime.now()} if error: if isinstance(error, int): error = errors.errorString(error) error = str(error) # Ensure error is an string if errorCode != 0: error += ' (code {0:04X})'.format(errorCode) res['error'] = error res['retryable'] = '1' if retryable else '0' return res
def userServiceEnabler(request, idService, idTransport): # Maybe we could even protect this even more by limiting referer to own server /? (just a meditation..) logger.debug('idService: {}, idTransport: {}'.format(idService, idTransport)) url = '' error = _('Service not ready. Please, try again in a while.') # If meta service, process and rebuild idService & idTransport try: res = userServiceManager().getService(request.user, request.os, request.ip, idService, idTransport, doTest=False) scrambler = cryptoManager().randomString(32) password = cryptoManager().symCrypt(webPassword(request), scrambler) _x, userService, _x, trans, _x = res data = { 'service': 'A' + userService.uuid, 'transport': trans.uuid, 'user': request.user.uuid, 'password': password } ticket = TicketStore.create(data) error = '' url = html.udsLink(request, ticket, scrambler) except ServiceNotReadyError as e: logger.debug('Service not ready') # Not ready, show message and return to this page in a while error += ' (code {0:04X})'.format(e.code) except MaxServicesReachedError: logger.info('Number of service reached MAX for service pool "{}"'.format(idService)) error = errors.errorString(errors.MAX_SERVICES_REACHED) except ServiceAccessDeniedByCalendar: logger.info('Access tried to a calendar limited access pool "{}"'.format(idService)) error = errors.errorString(errors.SERVICE_CALENDAR_DENIED) except Exception as e: logger.exception('Error') error = str(e) return HttpResponse( json.dumps({ 'url': str(url), 'error': str(error) }), content_type='application/json' )
def result(result=None, error=None, errorCode=0, retryable=False): """ Helper method to create a "result" set for connection response :param result: Result value to return (can be None, in which case it is converted to empty string '') :param error: If present, This response represents an error. Result will contain an "Explanation" and error contains the error code :return: A dictionary, suitable for response to Caller """ result = result if result is not None else '' res = {'result': result, 'date': datetime.datetime.now()} if error is not None: if isinstance(error, int): error = errors.errorString(error) if errorCode != 0: error += ' (code {0:04X})'.format(errorCode) res['error'] = error res['retryable'] = retryable and '1' or '0' return res
def result(result=None, error=None, errorCode=0, retryable=False): """ Helper method to create a "result" set for actor response :param result: Result value to return (can be None, in which case it is converted to empty string '') :param error: If present, This response represents an error. Result will contain an "Explanation" and error contains the error code :param errorCode: Code of the error to return, if error is not None :param retryable: If True, this operation can (and must) be retryed :return: A dictionary, suitable for response to Caller """ result = result if result is not None else '' res = {'result': result} if error is not None: if isinstance(error, int): error = errors.errorString(error) if errorCode != 0: error += ' (code {0:04X})'.format(errorCode) res['error'] = error res['retryable'] = retryable and '1' or '0' logger.debug('Client Result: {}'.format(res)) return res