Better config defaults and remove some unneeded code

This commit is contained in:
Joseph Schorr 2015-01-05 13:01:32 -05:00
parent 40d2b1748f
commit 219730c341
6 changed files with 657 additions and 649 deletions

View file

@ -67,11 +67,15 @@ class SuperUserGetConfig(ApiResource):
'type': 'object',
'description': 'Updates the YAML config file',
'required': [
'config'
'config',
'hostname'
],
'properties': {
'config': {
'type': 'object'
},
'hostname': {
'type': 'string'
}
},
},
@ -102,9 +106,10 @@ class SuperUserGetConfig(ApiResource):
# so we also allow it to be called if there is no valid registry configuration setup.
if not os.path.exists(OVERRIDE_CONFIG_YAML_FILENAME) or SuperUserPermission().can():
config_object = request.get_json()['config']
hostname = request.get_json()['hostname']
# Add any enterprise defaults missing from the config.
add_enterprise_config_defaults(config_object, app.config['SECRET_KEY'])
add_enterprise_config_defaults(config_object, app.config['SECRET_KEY'], hostname)
# Write the configuration changes to the YAML file.
export_yaml(config_object, OVERRIDE_CONFIG_YAML_FILENAME)

File diff suppressed because it is too large Load diff

View file

@ -3118,7 +3118,8 @@ function SuperUserAdminCtrl($scope, $timeout, ApiService, Features, UserService,
var data = {
'config': {
'DB_URI': $scope.databaseUri
}
},
'hostname': window.location.host
};
var params = {

View file

@ -7,25 +7,10 @@ angular.module("core-config-setup", ['angularFileUpload'])
transclude: true,
restrict: 'C',
scope: {
'isActive': '=isActive'
},
controller: function($rootScope, $scope, $element, $timeout) {
$scope.config = {
'DB_URI': 'mysql+pymysql://jschorr:somepassword@mymysql.server.somewhere:768/mydb',
'PREFERRED_URL_SCHEME': 'https',
'FEATURE_USER_CREATION': true,
'DISTRIBUTED_STORAGE_CONFIG': {'local': ['LocalStorage', {'storage_path': '/datastorage/registry'}]},
'AUTHENTICATION_TYPE': 'Database'
}
$scope.generateKey = function() {
var d = new Date().getTime();
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = (d + Math.random()*16)%16 | 0;
d = Math.floor(d/16);
return (c=='x' ? r : (r&0x3|0x8)).toString(16);
});
$scope.config['SECRET_KEY'] = uuid;
};
controller: function($rootScope, $scope, $element, $timeout, ApiService) {
$scope.config = null;
$scope.parseDbUri = function(value) {
if (!value) { return null; }
@ -55,6 +40,14 @@ angular.module("core-config-setup", ['angularFileUpload'])
uri = uri && uri.toString();
return uri;
};
$scope.$watch('isActive', function(value) {
if (!value) { return; }
ApiService.scGetConfig().then(function(resp) {
$scope.config = resp['config'];
});
});
}
};

View file

@ -29,7 +29,7 @@
<div class="cor-tab-content">
<!-- Setup tab -->
<div id="setup" class="tab-pane active">
<div class="config-setup-tool"></div>
<div class="config-setup-tool" is-active="configStatus.ready"></div>
</div>
<!-- Debugging tab -->

View file

@ -36,7 +36,7 @@ def set_config_value(config_file, config_key, value):
export_yaml(config_obj, config_file)
def add_enterprise_config_defaults(config_obj, current_secret_key):
def add_enterprise_config_defaults(config_obj, current_secret_key, hostname):
""" Adds/Sets the config defaults for enterprise registry config. """
# These have to be false.
config_obj['TESTING'] = False
@ -50,6 +50,10 @@ def add_enterprise_config_defaults(config_obj, current_secret_key):
config_obj['FEATURE_MAILING'] = config_obj.get('FEATURE_MAILING', False)
config_obj['FEATURE_BUILD_SUPPORT'] = config_obj.get('FEATURE_BUILD_SUPPORT', False)
# Default auth type.
if not 'AUTHENTICATION_TYPE' in config_obj:
config_obj['AUTHENTICATION_TYPE'] = 'Database'
# Default secret key.
if not 'SECRET_KEY' in config_obj:
config_obj['SECRET_KEY'] = current_secret_key
@ -58,12 +62,15 @@ def add_enterprise_config_defaults(config_obj, current_secret_key):
if not 'DISTRIBUTED_STORAGE_CONFIG' in config_obj:
config_obj['DISTRIBUTED_STORAGE_PREFERENCE'] = ['local']
config_obj['DISTRIBUTED_STORAGE_CONFIG'] = {
'local': ['LocalStorage', { 'storage_path': '/datastorage/registry' }]
'local': ['LocalStorage', {'storage_path': '/datastorage/registry'}]
}
config_obj['USERFILES_LOCATION'] = 'local'
config_obj['USERFILES_PATH'] = 'userfiles/'
if not 'SERVER_HOSTNAME' in config_obj:
config_obj['SERVER_HOSTNAME'] = hostname
# Misc configuration.
config_obj['PREFERRED_URL_SCHEME'] = config_obj.get('PREFERRED_URL_SCHEME', 'http')
config_obj['ENTERPRISE_LOGO_URL'] = config_obj.get('ENTERPRISE_LOGO_URL',