Make custom cert upload not hang and handle errors properly
This commit is contained in:
parent
76ab598587
commit
835acfc58e
2 changed files with 20 additions and 7 deletions
|
@ -3,7 +3,6 @@
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import string
|
import string
|
||||||
import subprocess
|
|
||||||
|
|
||||||
import pathvalidate
|
import pathvalidate
|
||||||
|
|
||||||
|
@ -900,21 +899,30 @@ class SuperUserCustomCertificate(ApiResource):
|
||||||
if not certpath.endswith('.crt'):
|
if not certpath.endswith('.crt'):
|
||||||
abort(400)
|
abort(400)
|
||||||
|
|
||||||
|
logger.debug('Saving custom certificate %s', certpath)
|
||||||
cert_full_path = os.path.join(EXTRA_CA_DIRECTORY, certpath)
|
cert_full_path = os.path.join(EXTRA_CA_DIRECTORY, certpath)
|
||||||
config_provider.save_volume_file(cert_full_path, uploaded_file)
|
config_provider.save_volume_file(cert_full_path, uploaded_file)
|
||||||
|
logger.debug('Saved custom certificate %s', certpath)
|
||||||
|
|
||||||
# Validate the certificate.
|
# Validate the certificate.
|
||||||
try:
|
try:
|
||||||
|
logger.debug('Loading custom certificate %s', certpath)
|
||||||
with config_provider.get_volume_file(cert_full_path) as f:
|
with config_provider.get_volume_file(cert_full_path) as f:
|
||||||
load_certificate(f.read())
|
load_certificate(f.read())
|
||||||
|
except CertInvalidException:
|
||||||
|
logger.exception('Got certificate invalid error for cert %s', certpath)
|
||||||
|
return '', 204
|
||||||
|
except IOError:
|
||||||
|
logger.exception('Got IO error for cert %s', certpath)
|
||||||
|
return '', 204
|
||||||
|
|
||||||
# Call the update script to install the certificate immediately.
|
# Call the update script to install the certificate immediately.
|
||||||
if not app.config['TESTING']:
|
if not app.config['TESTING']:
|
||||||
subprocess.check_call(['/conf/init/certs_install.sh'])
|
logger.debug('Calling certs_install.sh')
|
||||||
except CertInvalidException:
|
if os.system('/conf/init/certs_install.sh') != 0:
|
||||||
pass
|
abort(500)
|
||||||
except IOError:
|
|
||||||
pass
|
logger.debug('certs_install.sh completed')
|
||||||
|
|
||||||
return '', 204
|
return '', 204
|
||||||
|
|
||||||
|
|
|
@ -1348,6 +1348,11 @@ angular.module("core-config-setup", ['angularFileUpload'])
|
||||||
callback(true);
|
callback(true);
|
||||||
$scope.resetUpload++;
|
$scope.resetUpload++;
|
||||||
loadCertificates();
|
loadCertificates();
|
||||||
|
}).error(function(r) {
|
||||||
|
bootbox.alert('Could not upload certificate')
|
||||||
|
callback(false);
|
||||||
|
$scope.resetUpload++;
|
||||||
|
loadCertificates();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Reference in a new issue