Don't handle BadRequest explicitly
This commit is contained in:
parent
0605110050
commit
b64f9c2c9e
@ -10,6 +10,8 @@ from werkzeug.wrappers import Request, Response
|
||||
from werkzeug.wsgi import ClosingIterator
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
|
||||
from cryptography.exceptions import InvalidSignature
|
||||
|
||||
from . import VMMgr, CERT_PUB_FILE
|
||||
from . import tools
|
||||
from .actionqueue import ActionQueue
|
||||
@ -154,14 +156,16 @@ class WSGIApp(object):
|
||||
|
||||
def setup_apps_view(self, request):
|
||||
# Application manager view.
|
||||
repo_error = None
|
||||
try:
|
||||
self.appmgr.fetch_online_packages()
|
||||
except InvalidSignature:
|
||||
repo_error = request.session.lang.invalild_packages_signature()
|
||||
except:
|
||||
pass
|
||||
repo_reachable = bool(self.appmgr.online_packages)
|
||||
repo_error = request.session.lang.repo_unavailable()
|
||||
table = self.render_setup_apps_table(request)
|
||||
message = self.get_session_message(request)
|
||||
return self.render_html('setup-apps.html', request, repo_reachable=repo_reachable, table=table, message=message)
|
||||
return self.render_html('setup-apps.html', request, repo_error=repo_error, table=table, message=message)
|
||||
|
||||
def render_setup_apps_table(self, request):
|
||||
lang = request.session.lang
|
||||
@ -239,8 +243,6 @@ class WSGIApp(object):
|
||||
response = self.render_json({'ok': request.session.lang.host_updated(url, url)})
|
||||
response.call_on_close(tools.restart_nginx)
|
||||
return response
|
||||
except BadRequest:
|
||||
return self.render_json({'error': request.session.lang.malformed_request()})
|
||||
except InvalidValueException as e:
|
||||
if e.args[0] == 'domain':
|
||||
return self.render_json({'error': request.session.lang.invalid_domain(domain)})
|
||||
@ -299,8 +301,6 @@ class WSGIApp(object):
|
||||
self.vmmgr.install_manual_cert('/tmp/public.pem', '/tmp/private.pem')
|
||||
os.unlink('/tmp/public.pem')
|
||||
os.unlink('/tmp/private.pem')
|
||||
except BadRequest:
|
||||
return self.render_json({'error': request.session.lang.malformed_request()})
|
||||
except:
|
||||
return self.render_json({'error': request.session.lang.cert_request_error()})
|
||||
url = tools.compile_url(self.vmmgr.domain, self.vmmgr.port)
|
||||
@ -313,47 +313,29 @@ class WSGIApp(object):
|
||||
gmaps_api_key = request.form['gmaps-api-key']
|
||||
self.appmgr.update_common_settings(email, gmaps_api_key)
|
||||
request.session['msg'] = 'common:info:{}'.format(request.session.lang.common_updated())
|
||||
except BadRequest:
|
||||
return self.render_json({'error': request.session.lang.malformed_request()})
|
||||
except InvalidValueException:
|
||||
request.session['msg'] = 'common:error:{}'.format(request.session.lang.invalid_email(email))
|
||||
return redirect('/setup-apps')
|
||||
|
||||
def update_repo_action(self, request):
|
||||
# Update repository URL and credentials
|
||||
try:
|
||||
url = request.form['repourl']
|
||||
user = request.form['repousername']
|
||||
pwd = request.form['repopassword']
|
||||
self.appmgr.update_repo_settings(url, user, pwd)
|
||||
request.session['msg'] = 'repo:info:{}'.format(request.session.lang.repo_updated())
|
||||
except BadRequest:
|
||||
return self.render_json({'error': request.session.lang.malformed_request()})
|
||||
self.appmgr.update_repo_settings(request.form['repourl'], request.form['repousername'], request.form['repopassword'])
|
||||
request.session['msg'] = 'repo:info:{}'.format(request.session.lang.repo_updated())
|
||||
return redirect('/setup-apps')
|
||||
|
||||
def update_app_visibility_action(self, request):
|
||||
# Update application visibility on portal page
|
||||
try:
|
||||
self.appmgr.update_app_visibility(request.form['app'], request.form['value'] == 'true')
|
||||
except (BadRequest, InvalidValueException):
|
||||
return self.render_json({'error': request.session.lang.malformed_request()})
|
||||
self.appmgr.update_app_visibility(request.form['app'], request.form['value'] == 'true')
|
||||
return self.render_json({'ok': 'ok'})
|
||||
|
||||
def update_app_autostart_action(self, request):
|
||||
# Update value determining if the app should be automatically started after VM boot
|
||||
try:
|
||||
self.appmgr.update_app_autostart(request.form['app'], request.form['value'] == 'true')
|
||||
except (BadRequest, InvalidValueException):
|
||||
return self.render_json({'error': request.session.lang.malformed_request()})
|
||||
self.appmgr.update_app_autostart(request.form['app'], request.form['value'] == 'true')
|
||||
return self.render_json({'ok': 'ok'})
|
||||
|
||||
def enqueue_app_action(self, request, action):
|
||||
# Common method for enqueuing app actions
|
||||
try:
|
||||
app = request.form['app']
|
||||
except BadRequest:
|
||||
return self.render_json({'error': request.session.lang.malformed_request()})
|
||||
self.queue.enqueue_action(app, action)
|
||||
self.queue.enqueue_action(request.form['app'], action)
|
||||
response = self.render_json({'ok': self.render_setup_apps_table(request)})
|
||||
response.call_on_close(self.queue.process_actions)
|
||||
return response
|
||||
@ -380,11 +362,7 @@ class WSGIApp(object):
|
||||
|
||||
def clear_app_status_action(self, request):
|
||||
# Clears error status for an application
|
||||
try:
|
||||
app = request.form['app']
|
||||
except BadRequest:
|
||||
return self.render_json({'error': request.session.lang.malformed_request()})
|
||||
self.queue.clear_action(app)
|
||||
self.queue.clear_action(request.form['app'])
|
||||
return self.render_json({'ok': self.render_setup_apps_table(request)})
|
||||
|
||||
def update_password_action(self, request):
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
class WSGILang:
|
||||
lang = {
|
||||
'malformed_request': 'Byl zaslán chybný požadavek. Obnovte stránku a zkuste akci zopakovat.',
|
||||
'invalid_domain': 'Zadaný doménový název "{}" není platný.',
|
||||
'invalid_port': 'Zadaný port "{}" není platný.',
|
||||
'host_updated': 'Nastavení hostitele bylo úspěšně změněno. Přejděte na URL <a href="{}">{}</a> a pokračujte následujícími kroky.',
|
||||
@ -23,6 +22,8 @@ class WSGILang:
|
||||
'stop_start_error': 'Došlo k chybě při spouštění/zastavování. Zkuste akci opakovat nebo restartuje virtuální stroj.',
|
||||
'installation_in_progress': 'Probíhá instalace jiného balíku. Vyčkejte na její dokončení.',
|
||||
'package_manager_error': 'Došlo k chybě při instalaci aplikace. Zkuste akci opakovat nebo restartuje virtuální stroj.',
|
||||
'invalid_packages_signature': 'Digitální podpis seznamu balíků není platný. Kontaktujte správce distribučního serveru.',
|
||||
'repo_unavailable': 'Připojení k distribučnímu serveru se nezdařilo. Zkontrolujte přístupové údaje a připojení k síti.',
|
||||
'bad_password': 'Nesprávné heslo',
|
||||
'password_mismatch': 'Zadaná hesla se neshodují',
|
||||
'password_empty': 'Nové heslo nesmí být prázdné',
|
||||
|
@ -18,8 +18,8 @@
|
||||
{{ table|safe }}
|
||||
</tbody>
|
||||
</table>
|
||||
{% if not repo_reachable %}
|
||||
<p class="error">Připojení k distribučnímu serveru se nezdařilo. Zkontrolujte přístupové údaje a připojení k síti.</p>
|
||||
{% if repo_error %}
|
||||
<p class="error">{{ repo_error }}</p>
|
||||
{% endif %}
|
||||
<p><strong>Přístupové údaje k distribučnímu serveru:</strong></p>
|
||||
<form id="update-repo" action="/update-repo" method="post">
|
||||
|
Loading…
Reference in New Issue
Block a user