Add validation of github to the config tool
This commit is contained in:
parent
7933bd44fd
commit
5e0ce4eea9
5 changed files with 80 additions and 24 deletions
|
@ -32,16 +32,19 @@ def validate_service_for_config(service, config):
|
|||
'reason': str(ex)
|
||||
}
|
||||
|
||||
|
||||
def _validate_database(config):
|
||||
""" Validates connecting to the database. """
|
||||
validate_database_url(config['DB_URI'])
|
||||
|
||||
|
||||
def _validate_redis(config):
|
||||
""" Validates connecting to redis. """
|
||||
redis_config = config['BUILDLOGS_REDIS']
|
||||
client = redis.StrictRedis(socket_connect_timeout=5, **redis_config)
|
||||
client.ping()
|
||||
|
||||
|
||||
def _validate_registry_storage(config):
|
||||
""" Validates registry storage. """
|
||||
parameters = config.get('DISTRIBUTED_STORAGE_CONFIG', {}).get('local', ['LocalStorage', {}])
|
||||
|
@ -54,6 +57,7 @@ def _validate_registry_storage(config):
|
|||
driver.put_content('_verify', 'testing 123')
|
||||
driver.remove('_verify')
|
||||
|
||||
|
||||
def _validate_mailing(config):
|
||||
""" Validates sending email. """
|
||||
test_app = Flask("mail-test-app")
|
||||
|
@ -68,12 +72,31 @@ def _validate_mailing(config):
|
|||
test_msg.add_recipient(get_authenticated_user().email)
|
||||
test_mail.send(test_msg)
|
||||
|
||||
def _validate_github_login(config):
|
||||
""" Validates the OAuth credentials and API endpoint for Github Login. """
|
||||
|
||||
def _validate_github(config_key):
|
||||
return lambda config: _validate_github_with_key(config_key, config)
|
||||
|
||||
|
||||
def _validate_github_with_key(config_key, config):
|
||||
""" Validates the OAuth credentials and API endpoint for a Github service. """
|
||||
endpoint = config[config_key].get('GITHUB_ENDPOINT')
|
||||
if not endpoint:
|
||||
raise Exception('Missing Github Endpoint')
|
||||
|
||||
if endpoint.find('http://') != 0 and endpoint.find('https://') != 0:
|
||||
raise Exception('Github Endpoint must start with http:// or https://')
|
||||
|
||||
if not config[config_key].get('CLIENT_ID'):
|
||||
raise Exception('Missing Client ID')
|
||||
|
||||
if not config[config_key].get('CLIENT_SECRET'):
|
||||
raise Exception('Missing Client Secret')
|
||||
|
||||
client = app.config['HTTPCLIENT']
|
||||
oauth = GithubOAuthConfig(config, 'GITHUB_LOGIN_CONFIG')
|
||||
endpoint = oauth.authorize_endpoint()
|
||||
# TODO: this
|
||||
oauth = GithubOAuthConfig(config, config_key)
|
||||
result = oauth.validate_client_id_and_secret(client)
|
||||
if not result:
|
||||
raise Exception('Invalid client id or client secret')
|
||||
|
||||
|
||||
def _validate_ssl(config):
|
||||
|
@ -116,7 +139,8 @@ _VALIDATORS = {
|
|||
'redis': _validate_redis,
|
||||
'registry-storage': _validate_registry_storage,
|
||||
'mail': _validate_mailing,
|
||||
'github-login': _validate_github_login,
|
||||
'github-login': _validate_github('GITHUB_LOGIN_CONFIG'),
|
||||
'github-trigger': _validate_github('GITHUB_TRIGGER_CONFIG'),
|
||||
'ssl': _validate_ssl,
|
||||
'ldap': _validate_ldap,
|
||||
}
|
Reference in a new issue