Add superuser config section for updating license

This commit is contained in:
Joseph Schorr 2016-10-11 15:16:28 -04:00
parent 5fee4d6d19
commit ee96693252
11 changed files with 370 additions and 34 deletions

View file

@ -102,22 +102,22 @@ class BaseProvider(object):
def _get_license_file(self):
""" Returns the contents of the license file. """
if not self.has_license_file():
msg = 'Could not find license file. Please make sure it is in your config volume.'
raise LicenseError(msg)
try:
return self.get_volume_file(LICENSE_FILENAME)
except IOError:
msg = 'Could not open license file. Please make sure it is in your config volume.'
raise LicenseError(msg)
def validate_license(self, config):
""" Validates that the configuration matches the license file (if any). """
if not config.get('SETUP_COMPLETE', False):
raise SetupIncompleteException()
def get_license(self):
""" Returns the decoded license, if any. """
with self._get_license_file() as f:
license_file_contents = f.read()
self.license = decode_license(license_file_contents)
self.license.validate(config)
return decode_license(license_file_contents)
def save_license(self, license_file_contents):
""" Saves the given contents as the license file. """

View file

@ -1,5 +1,5 @@
import json
from StringIO import StringIO
import io
from util.config.provider.baseprovider import BaseProvider
@ -53,7 +53,7 @@ class TestConfigProvider(BaseProvider):
if filename in REAL_FILES:
return open(filename, mode=mode)
return StringIO(self.files[filename])
return io.BytesIO(self.files[filename])
def requires_restart(self, app_config):
return False