2018-05-21 21:02:38 +00:00
|
|
|
import logging
|
|
|
|
|
2018-05-23 20:57:26 +00:00
|
|
|
from config_app.config_endpoints.api import resource, ApiResource, verify_not_prod, nickname
|
|
|
|
from config_app.c_app import app, config_provider
|
2018-05-21 21:02:38 +00:00
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
@resource('/v1/superuser/config')
|
|
|
|
class SuperUserConfig(ApiResource):
|
|
|
|
""" Resource for fetching and updating the current configuration, if any. """
|
|
|
|
schemas = {
|
|
|
|
'UpdateConfig': {
|
|
|
|
'type': 'object',
|
|
|
|
'description': 'Updates the YAML config file',
|
|
|
|
'required': [
|
|
|
|
'config',
|
|
|
|
'hostname'
|
|
|
|
],
|
|
|
|
'properties': {
|
|
|
|
'config': {
|
|
|
|
'type': 'object'
|
|
|
|
},
|
|
|
|
'hostname': {
|
|
|
|
'type': 'string'
|
|
|
|
},
|
|
|
|
'password': {
|
|
|
|
'type': 'string'
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
@verify_not_prod
|
|
|
|
@nickname('scGetConfig')
|
|
|
|
def get(self):
|
|
|
|
""" Returns the currently defined configuration, if any. """
|
|
|
|
config_object = config_provider.get_config()
|
|
|
|
logger.debug(config_object)
|
|
|
|
logger.debug(config_provider)
|
|
|
|
# Todo: do we even need this endpoint? Since we'll be loading the config in browser
|
|
|
|
return {
|
|
|
|
'config': config_object
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@resource('/v1/superuser/registrystatus')
|
|
|
|
class SuperUserRegistryStatus(ApiResource):
|
|
|
|
""" Resource for determining the status of the registry, such as if config exists,
|
|
|
|
if a database is configured, and if it has any defined users.
|
|
|
|
"""
|
|
|
|
@nickname('scRegistryStatus')
|
|
|
|
@verify_not_prod
|
|
|
|
def get(self):
|
|
|
|
""" Returns the status of the registry. """
|
|
|
|
|
|
|
|
# If we have SETUP_COMPLETE, then we're ready to go!
|
|
|
|
if app.config.get('SETUP_COMPLETE', False):
|
|
|
|
return {
|
|
|
|
'provider_id': config_provider.provider_id,
|
|
|
|
'requires_restart': config_provider.requires_restart(app.config),
|
|
|
|
'status': 'ready'
|
|
|
|
}
|
|
|
|
|
|
|
|
# If there is no conf/stack volume, then report that status.
|
|
|
|
if not config_provider.volume_exists():
|
|
|
|
return {
|
|
|
|
'status': 'missing-config-dir'
|
|
|
|
}
|
|
|
|
|
|
|
|
# If there is no config file, we need to setup the database.
|
|
|
|
if not config_provider.config_exists():
|
|
|
|
return {
|
|
|
|
'status': 'config-db'
|
|
|
|
}
|
|
|
|
|
|
|
|
# If the database isn't yet valid, then we need to set it up.
|
|
|
|
# if not database_is_valid():
|
|
|
|
# return {
|
|
|
|
# 'status': 'setup-db'
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
# return {
|
|
|
|
# 'status': 'create-superuser' if not database_has_users() else 'config'
|
|
|
|
# }
|
|
|
|
|
|
|
|
return {}
|