cleaning for 3.0

This commit is contained in:
Adolfo Gómez García 2019-11-19 11:16:32 +01:00
parent 7e034a9de1
commit ef7bbebec8
4 changed files with 10 additions and 119 deletions

View File

@ -467,19 +467,9 @@ class XenLinkedDeployment(UserDeployment):
return self.__executeQueue()
def reasonOfError(self) -> str:
"""
Returns the reason of the error.
Remember that the class is responsible of returning this whenever asked
for it, and it will be asked everytime it's needed to be shown to the
user (when the administation asks for it).
"""
return self._reason
def destroy(self) -> str:
"""
Invoked for destroying a deployed service
"""
self.__debug('destroy')
# If executing something, wait until finished to remove it
# We simply replace the execution queue
@ -497,15 +487,6 @@ class XenLinkedDeployment(UserDeployment):
return State.RUNNING
def cancel(self) -> str:
"""
This is a task method. As that, the excepted return values are
State values RUNNING, FINISHED or ERROR.
This can be invoked directly by an administration or by the clean up
of the deployed service (indirectly).
When administrator requests it, the cancel is "delayed" and not
invoked directly.
"""
return self.destroy()
@staticmethod

View File

@ -30,15 +30,14 @@
"""
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
"""
from __future__ import unicode_literals
# DEPRECATED AND NOT USED. TO BE REMOVED! (avoid this)
import re
import logging
from django import template
from django.conf import settings
from django.utils import safestring
from uds.REST import AUTH_TOKEN_HEADER
import re
import logging
logger = logging.getLogger(__name__)
@ -83,5 +82,5 @@ def js_template_jade(context, template_name, template_id=None):
context.flatten())
# Clean tmpl
if not settings.DEBUG:
tmpl = re.sub('\s+', ' ', tmpl)
tmpl = re.sub(r'\s+', ' ', tmpl)
return safestring.mark_safe('<script id="{0}" type="template/uds">{1}</script>'.format(template_id, tmpl))

View File

@ -30,21 +30,17 @@
"""
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
"""
from __future__ import unicode_literals
# Note: DEPRECATED, module will be removed
import logging
from django import template
from django.utils.translation import ugettext as _
from django.templatetags.static import static
from django.utils.html import mark_safe
from uds.core.util import html
from uds.core.auths.auth import ROOT_ID
from uds.core.util.config import GlobalConfig
from uds.models.image import Image
from uds.core.managers.user_preferences import UserPrefsManager
from uds.REST.methods.client import CLIENT_VERSION
import logging
logger = logging.getLogger(__name__)
@ -107,10 +103,9 @@ def ifbrowser(parser, token):
def osName(os):
if os == 'windows':
return 'Windows'
elif os == 'linux':
if os == 'linux':
return 'Linux'
else:
return 'Mac OS X'
return 'Mac OS X'
@register.filter(name='pluginDownloadUrl')
@ -119,7 +114,7 @@ def pluginDownloadUrl(os):
if os == 'windows':
return tmpl.format(url=static('clients/UDSClientSetup-{version}.exe'.format(version=CLIENT_VERSION)), os='Windows')
elif os == 'linux':
if os == 'linux':
linux_packages = (
('udsclient_{version}_all.deb'.format(version=CLIENT_VERSION), _('Debian based Linux') + ' ' + _('(requires Python-2.7)')),
('udsclient-{version}-1.noarch.rpm'.format(version=CLIENT_VERSION), _('Red Hat based Linux (RH, Fedora, Centos, ...)') + ' ' + _('(requires Python-2.7)')),
@ -130,5 +125,4 @@ def pluginDownloadUrl(os):
for v in linux_packages:
res += '<p class="text-center">' + tmpl.format(url=static('clients/' + v[0]), os=v[1]) + '</p>'
return res
else:
return tmpl.format(url=static('clients/UDSClient-{version}.pkg'.format(version=CLIENT_VERSION)), os='Mac OSX')
return tmpl.format(url=static('clients/UDSClient-{version}.pkg'.format(version=CLIENT_VERSION)), os='Mac OSX')

View File

@ -1,83 +0,0 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2012 Virtual Cable S.L.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# * Neither the name of Virtual Cable S.L. nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""
@author: Adolfo Gómez, dkmaster at dkmon dot com
"""
from __future__ import unicode_literals
from functools import wraps
from uds.core.managers import cryptoManager
from uds.core.util import encoders
import logging
logger = logging.getLogger(__name__)
SCRAMBLE_SES = 'scrSid'
SCRAMBLE_LEN = 10
# Decorator to make easier protect pages
def transformId(view_func):
"""
Decorator to untransform id used in a function. Its generates a hash of it
To use this decorator, the view must receive 'response' and 'id' and (optionaly) 'id2', 'id3'
example: def view(response, id)
"""
@wraps(view_func)
def _wrapped_view(request, *args, **kwargs):
from uds.web.util import errors
for k in kwargs.keys():
if k[:2] == 'id':
try:
kwargs[k] = unscrambleId(request, kwargs[k])
except Exception:
return errors.errorView(request, errors.INVALID_REQUEST)
return view_func(request, *args, **kwargs)
return _wrapped_view
def scrambleId(request, id_):
if SCRAMBLE_SES not in request.session:
request.session[SCRAMBLE_SES] = cryptoManager().randomString(SCRAMBLE_LEN)
id_ = str(id_)
if len(id_) < SCRAMBLE_LEN:
id_ = (id_ + '~' + cryptoManager().randomString(SCRAMBLE_LEN))[:SCRAMBLE_LEN]
scrambled = cryptoManager().xor(id_, request.session[SCRAMBLE_SES])
return encoders.encode(scrambled, 'base64', asText=True)[:-3]
def unscrambleId(request, id_):
idd = cryptoManager().xor(encoders.decode(id_ + '==\n', 'base64', asText=False), request.session[SCRAMBLE_SES])
return idd.decode('utf8').split('~')[0]