Ejemplo n.º 1
0
class UserResource(UserBaseResource):
    parse_put = create_body_parser(UserSchema)

    @api_response()
    def get(self, address):
        return self._dump_obj(address)

    @api_response()
    def put(self, address):
        data, errors = self.parse_put()
        self._save_to_obj(address, data)
        return self._dump_obj(address)

    def delete(self, address):
        self.vmm.user_delete(address, True, force=True)
        return '', HTTPStatus.NO_CONTENT
Ejemplo n.º 2
0
class DomainResource(DomainBaseResource):
    parse_put = create_body_parser(DomainSchema)

    @api_response()
    def get(self, name):
        return self._dump_obj(name)

    @api_response()
    def put(self, name):
        data, errors = self.parse_put()
        self._save_to_obj(name, data)
        return self._dump_obj(name)

    def delete(self, name):
        self.vmm.domain_delete(name, True, force=True)
        return '', HTTPStatus.NO_CONTENT
Ejemplo n.º 3
0
class DomainCollectionResource(DomainBaseResource):
    parse_post = create_body_parser(DomainCreateSchema)

    @api_response('domains')
    def get(self):
        gids, gid_domains = self.vmm.domain_list()

        def _map(domains):
            return map(self._dump_obj, domains)

        return flatten(map(_map, gid_domains.values()))

    @api_response()
    def post(self):
        data, errors = self.parse_post()
        name, transport, note = pick(data, ['name', 'transport', 'note'])
        self.vmm.domain_add(name, transport, note)
        self._save_to_obj(name, data)
        return self._dump_obj(name)
Ejemplo n.º 4
0
class UserCollectionResource(UserBaseResource):
    parse_post = create_body_parser(UserCreateSchema)

    @api_response('users')
    def get(self):
        pattern = request.args.get('pattern', None)
        # TODO: audit address_list if it’s safe against sql injections
        gids, gid_addresses = self.vmm.address_list(TYPE_ACCOUNT, pattern)

        def _map(address_infos):
            return map(lambda ai: self._dump_obj(ai[0]), address_infos)
        return flatten(map(_map, gid_addresses.values()))

    @api_response()
    def post(self):
        data, errors = self.parse_post()
        address, password, note = pick(data, ['address', 'password', 'note'])
        self.vmm.user_add(address, password, note)
        self._save_to_obj(address, data)
        return self._dump_obj(address)
Ejemplo n.º 5
0
class AliasCollectionResource(AliasBaseResource):
    parse_post = create_body_parser(AliasCreateSchema)

    @api_response('aliases')
    def get(self):
        pattern = request.args.get('pattern', None)
        # TODO: audit address_list if it’s safe against sql injections
        gids, gid_addresses = self.vmm.address_list(TYPE_ALIAS, pattern)

        def _map(address_infos):
            return map(lambda ai: self._dump_obj(ai[0]), address_infos)

        return flatten(map(_map, gid_addresses.values()))

    @api_response()
    def post(self):
        data, errors = self.parse_post()
        address, destinations = pick(data, ['address', 'destinations'])
        self.vmm.alias_add(address, *destinations)
        return self._dump_obj(address)
Ejemplo n.º 6
0
class AliasResource(AliasBaseResource):
    parse_put = create_body_parser(AliasSchema)

    @api_response()
    def get(self, address):
        return self._dump_obj(address)

    @api_response()
    def put(self, address):
        # put would be able to create new aliases but that wouldn’t be
        # pure doctrine so we’re going to check if the alias exists first
        self.vmm.alias_info(address)

        # alias_info would have thrown an exception, so we’re good to go
        data, errors = self.parse_put()
        self.vmm.alias_add(address, *data.pop('destinations'))
        return self._dump_obj(address)

    def delete(self, address):
        self.vmm.alias_delete(address)
        return '', HTTPStatus.NO_CONTENT