52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
from flask import Blueprint, request
|
|
from zope import component
|
|
|
|
from .utils import requires_authentication_no_realm, authz_restrict_to_syscom, \
|
|
get_valid_member_or_throw
|
|
from ceo_common.interfaces import ICloudService
|
|
|
|
bp = Blueprint('cloud', __name__)
|
|
|
|
|
|
@bp.route('/accounts/create', methods=['POST'])
|
|
@requires_authentication_no_realm
|
|
def create_account(auth_user: str):
|
|
user = get_valid_member_or_throw(auth_user)
|
|
cloud_srv = component.getUtility(ICloudService)
|
|
cloud_srv.create_account(user)
|
|
return {'status': 'OK'}
|
|
|
|
|
|
@bp.route('/accounts/purge', methods=['POST'])
|
|
@authz_restrict_to_syscom
|
|
def purge_accounts():
|
|
cloud_srv = component.getUtility(ICloudService)
|
|
return cloud_srv.purge_accounts()
|
|
|
|
|
|
@bp.route('/vhosts/<domain>', methods=['PUT'])
|
|
@requires_authentication_no_realm
|
|
def create_vhost(auth_user: str, domain: str):
|
|
get_valid_member_or_throw(auth_user)
|
|
cloud_srv = component.getUtility(ICloudService)
|
|
body = request.get_json(force=True)
|
|
ip_address = body['ip_address']
|
|
cloud_srv.create_vhost(auth_user, domain, ip_address)
|
|
return {'status': 'OK'}
|
|
|
|
|
|
@bp.route('/vhosts/<domain>', methods=['DELETE'])
|
|
@requires_authentication_no_realm
|
|
def delete_vhost(auth_user: str, domain: str):
|
|
cloud_srv = component.getUtility(ICloudService)
|
|
cloud_srv.delete_vhost(auth_user, domain)
|
|
return {'status': 'OK'}
|
|
|
|
|
|
@bp.route('/vhosts', methods=['GET'])
|
|
@requires_authentication_no_realm
|
|
def get_vhosts(auth_user: str):
|
|
cloud_srv = component.getUtility(ICloudService)
|
|
vhosts = cloud_srv.get_vhosts(auth_user)
|
|
return {'vhosts': vhosts}
|