|
|
|
@ -3,7 +3,7 @@ from zope import component |
|
|
|
|
from ceod.api.utils import authz_restrict_to_staff, authz_restrict_to_syscom, \ |
|
|
|
|
user_is_in_group, requires_authentication_no_realm, \ |
|
|
|
|
create_streaming_response, development_only |
|
|
|
|
from ceo_common.errors import UserNotFoundError, DatabaseConnectionError, DatabasePermissionError |
|
|
|
|
from ceo_common.errors import UserNotFoundError, DatabaseConnectionError, DatabasePermissionError, InvalidUsernameError |
|
|
|
|
from ceo_common.interfaces import ILDAPService, IDatabaseService |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -13,7 +13,7 @@ bp = Blueprint('db', __name__) |
|
|
|
|
def create_db_from_type(db_type: str, username: str): |
|
|
|
|
try: |
|
|
|
|
if not username.isalnum(): # username should not contain symbols |
|
|
|
|
raise UserNotFoundError |
|
|
|
|
raise InvalidUsernameError() |
|
|
|
|
ldap_srv = component.getUtility(ILDAPService) |
|
|
|
|
ldap_srv.get_user(username) # make sure user exists |
|
|
|
|
db_srv = component.getUtility(IDatabaseService, db_type) |
|
|
|
@ -21,30 +21,30 @@ def create_db_from_type(db_type: str, username: str): |
|
|
|
|
return {'password': password} |
|
|
|
|
except UserNotFoundError: |
|
|
|
|
return {'error': 'user not found'}, 404 |
|
|
|
|
except InvalidUsernameError: |
|
|
|
|
return {'error': 'username contains invalid characters'}, 400 |
|
|
|
|
except DatabaseConnectionError: |
|
|
|
|
return {'error': 'unable to connect or authenticate to sql server'}, 400 |
|
|
|
|
return {'error': 'unable to connect or authenticate to sql server'}, 500 |
|
|
|
|
except DatabasePermissionError: |
|
|
|
|
return {'error': 'unable to perform action due to permissions'}, 502 |
|
|
|
|
except: |
|
|
|
|
return {'error': 'Unexpected error'}, 500 |
|
|
|
|
return {'error': 'unable to perform action due to permissions'}, 500 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def delete_db_from_type(db_type: str, username: str): |
|
|
|
|
try: |
|
|
|
|
if not username.isalnum(): # username should not contain symbols |
|
|
|
|
raise UserNotFoundError |
|
|
|
|
raise InvalidUsernameError() |
|
|
|
|
ldap_srv = component.getUtility(ILDAPService) |
|
|
|
|
ldap_srv.get_user(username) # make sure user exists |
|
|
|
|
db_srv = component.getUtility(IDatabaseService, db_type) |
|
|
|
|
db_srv.delete_db(username) |
|
|
|
|
except UserNotFoundError: |
|
|
|
|
return {'error': 'user not found'}, 404 |
|
|
|
|
except InvalidUsernameError: |
|
|
|
|
return {'error': 'username contains invalid characters'}, 400 |
|
|
|
|
except DatabaseConnectionError: |
|
|
|
|
return {'error': 'unable to connect or authenticate to sql server'}, 400 |
|
|
|
|
return {'error': 'unable to connect or authenticate to sql server'}, 500 |
|
|
|
|
except DatabasePermissionError: |
|
|
|
|
return {'error': 'unable to perform action due to permissions'}, 502 |
|
|
|
|
except: |
|
|
|
|
return {'error': 'Unexpected error'}, 500 |
|
|
|
|
return {'error': 'unable to perform action due to permissions'}, 500 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route('/mysql/<username>', methods=['POST']) |
|
|
|
|