Merge pull request #2490 from coreos-inc/upload-cert-blocker

Make custom cert upload not hang and handle errors properly
This commit is contained in:
josephschorr 2017-03-29 16:11:13 -04:00 committed by GitHub
commit b4e79206a0
2 changed files with 20 additions and 7 deletions

View file

@ -3,7 +3,6 @@
import logging
import os
import string
import subprocess
import pathvalidate
@ -900,21 +899,30 @@ class SuperUserCustomCertificate(ApiResource):
if not certpath.endswith('.crt'):
abort(400)
logger.debug('Saving custom certificate %s', certpath)
cert_full_path = os.path.join(EXTRA_CA_DIRECTORY, certpath)
config_provider.save_volume_file(cert_full_path, uploaded_file)
logger.debug('Saved custom certificate %s', certpath)
# Validate the certificate.
try:
logger.debug('Loading custom certificate %s', certpath)
with config_provider.get_volume_file(cert_full_path) as f:
load_certificate(f.read())
# Call the update script to install the certificate immediately.
if not app.config['TESTING']:
subprocess.check_call(['/conf/init/certs_install.sh'])
except CertInvalidException:
pass
logger.exception('Got certificate invalid error for cert %s', certpath)
return '', 204
except IOError:
pass
logger.exception('Got IO error for cert %s', certpath)
return '', 204
# Call the update script to install the certificate immediately.
if not app.config['TESTING']:
logger.debug('Calling certs_install.sh')
if os.system('/conf/init/certs_install.sh') != 0:
abort(500)
logger.debug('certs_install.sh completed')
return '', 204

View file

@ -1348,6 +1348,11 @@ angular.module("core-config-setup", ['angularFileUpload'])
callback(true);
$scope.resetUpload++;
loadCertificates();
}).error(function(r) {
bootbox.alert('Could not upload certificate')
callback(false);
$scope.resetUpload++;
loadCertificates();
});
};