示例#1
0
def make_link_headers(pagination, endpoint):
    links = [
        Link(url_for(endpoint, page=pagination.page, limit=pagination.per_page), rel='self'),
    ]
    if pagination.pages > 1:
        links.append(Link(url_for(endpoint, page=1, limit=pagination.per_page), rel='first'))
    if pagination.has_prev:
        links.append(Link(url_for(endpoint, page=pagination.prev_num, limit=pagination.per_page), rel='previous'))
    if pagination.has_next:
        links.append(Link(url_for(endpoint, page=pagination.next_num, limit=pagination.per_page), rel='next'))
    if pagination.pages > 1:
        links.append(Link(url_for(endpoint, page=pagination.pages, limit=pagination.per_page), rel='last'))
    return str(LinkHeader(links))
示例#2
0
    def put(self, ipv4):
        """Updates a DHCP recordd"""
        args = parser.parse_args(request)

        if not validation.is_ipv4(ipv4):
            return {'message': 'please provide a valid ipv4 address'}, 406

        if not dhcp.DhcpConfig.exists_ipv4(ipv4):
            return abort(404)

        dhcp_config = dhcp.DhcpConfig.get_by_ip(ipv4)

        dhcp_config.set_settings(False, args.mac, args.ip_address,
                                 args.gateway, args.networkmask)

        for args_item in parser.args:
            if not args_item.required and args_item.name in args and args[args_item.name] is not None and \
                    args_item.name is not 'gateway' and args_item.name is not 'networkmask':
                dhcp_config.add_additional_statement(args_item.name,
                                                     args[args_item.name])

        dhcp_config.remove_by_ipv4()

        dhcp_config.create_isc_ldap()

        location = url_for('dhcpipv4object',
                           _method='GET',
                           ipv4=dhcp_config.ip_address)
        return vars(dhcp_config), 201, {'Location': location}
示例#3
0
 def _handle_view(self, name, **kwargs):
     """ Override builtin _handle_view to redirect users """
     if not self.is_accessible():
         if current_user.is_authenticated:
             abort(hcodes.HTTP_BAD_FORBIDDEN)  # permission denied
         else:  # login
             return redirect(url_for('security.login', next=request.url))
示例#4
0
文件: pxe.py 项目: virtapi/marmoset
    def post(self):
        """
        Accepts a new PXE entry

        Add a PXE entry for the given ip_address. Password, uuid, script and
        IPv6 parameteres are optional parameters. The IPv6 parameters are used
        only when all of them are provided. Missing password or uuid will
        be auto generated by ClientConfig.
        """
        args = parser.parse_args()
        client_config = pxe.ClientConfig(
            args.ip_address,
            args.password,
            args.script,
            args.uuid,
            args.ipv6_address,
            args.ipv6_gateway,
            args.ipv6_prefix
        )

        try:
            client_config.create(pxe.Label.find(args.label))
            location = url_for(
                'pxeobject',
                _method='GET',
                ip_address=client_config.ip_address)
            return vars(client_config), 201, {'Location': location}
        except pxe.exceptions.InputError as exception:
            abort(400, message=str(exception))
        except Exception as exception:
            abort(500, message=str(exception))
示例#5
0
 def test_todos_post(self):
     response = self.client.post(url_for('resources.todos.todos'),
                                 data={'name': 'Go jogging at 10am',
                                       'user': self.user
                                       }, headers=self.headers)
     myresponse = json.loads(response.get_data())
     self.assertEqual('Go jogging at 10am', myresponse.get('name'))
示例#6
0
 def put(self, id):
     args = self.reqparse.parse_args()
     query = models.Todo.update(**args).where(models.Todo.id == id)
     query.execute()
     return (models.Todo.get(models.Todo.id == id), 200, {
         'location': url_for('resources.todos.todo', id=id)
     })
示例#7
0
 def put(self, id):
     args = self.reqparse.parse_args()
     query = models.Course.update(**args).where(models.Course.id == id)
     query.execute()
     return (add_reviews(models.Course.get(models.Course.id == id)), 200, {
         'Location': url_for('resources.courses.course', id=id)
     })
示例#8
0
文件: dhcp.py 项目: virtapi/marmoset
    def put(self, ipv4):
        """Updates a DHCP recordd"""
        args = parser.parse_args(request)

        if not validation.is_ipv4(ipv4):
            return {'message': 'please provide a valid ipv4 address'}, 406

        if not dhcp.DhcpConfig.exists_ipv4(ipv4):
            return abort(404)

        dhcp_config = dhcp.DhcpConfig.get_by_ip(ipv4)

        dhcp_config.set_settings(
            False,
            args.mac,
            args.ip_address,
            args.gateway,
            args.networkmask)

        for args_item in parser.args:
            if not args_item.required and args_item.name in args and args[args_item.name] is not None and \
                    args_item.name is not 'gateway' and args_item.name is not 'networkmask':
                dhcp_config.add_additional_statement(
                    args_item.name, args[args_item.name])

        dhcp_config.remove_by_ipv4()

        dhcp_config.create_isc_ldap()

        location = url_for(
            'dhcpipv4object',
            _method='GET',
            ipv4=dhcp_config.ip_address)
        return vars(dhcp_config), 201, {'Location': location}
示例#9
0
 def test_todos_put(self):
     response = self.client.put(url_for('resources.todos.todos'),
                                data={'id': self.todo.id,
                                      'name': 'Go jogging at 10am',
                                      'user': self.user
                                      }, headers=self.headers)
     self.assertNotEqual(response.status_code, 404)
示例#10
0
    def post(self):
        """
        Accepts a new PXE entry

        Add a PXE entry for the given ip_address. Password, uuid, script and
        IPv6 parameteres are optional parameters. The IPv6 parameters are used
        only when all of them are provided. Missing password or uuid will
        be auto generated by ClientConfig.
        """
        args = parser.parse_args()

        if args.persistent in ['true', 'True']:
            persistent = True
        else:
            persistent = False
        print(args)
        client_config = pxe.ClientConfig(args.ip_address, args.password,
                                         args.script, args.uuid,
                                         args.ipv6_address, args.ipv6_gateway,
                                         args.ipv6_prefix, persistent)

        try:
            client_config.create(pxe.Label.find(args.label))
            location = url_for('pxeobject',
                               _method='GET',
                               ip_address=client_config.ip_address)
            return vars(client_config), 201, {'Location': location}
        except pxe.exceptions.InputError as exception:
            abort(400, message=str(exception))
        except Exception as exception:
            abort(500, message=str(exception))
示例#11
0
 def put(self, id):
     args = self.reqparse.parse_args()
     query = models.Todo.update(**args).where(models.Todo.id == id)
     query.execute()
     return (models.Todo.get(models.Todo.id == id), 200, {
         'Location': url_for('resources.todos.todo', id=id)
     })
示例#12
0
	def put(self, id):
		args = self.reqparse.parse_args() # reqprase - parses arguments for us out of request
		query = models.Marina.update(**args).where(models.Marina.id==id)
		query.execute()
		#jsonify - turns what's in the parenthesis into a json response
		return (add_marinas(models.Marina.get(models.Marina.id==id)), 200, 
				{'Location': url_for('resources.marinas.marina', id=id)})
示例#13
0
 def _handle_view(self, name, **kwargs):
     """ Override builtin _handle_view to redirect users """
     if not self.is_accessible():
         if current_user.is_authenticated:
             abort(hcodes.HTTP_BAD_FORBIDDEN)  # permission denied
         else:  # login
             return redirect(url_for('security.login', next=request.url))
示例#14
0
 def delete(self, id):
     try:
         query = models.Todo.delete().where(models.Todo.id == id)
         query.execute()
     except models.DoesNotExist:
         abort(404)
     else:
         return ('', 201, {'Location': url_for('resources.todos.todos')})
示例#15
0
 def put(self, id):
     args = self.reqparse.parse_args()
     query = models.Course.update(**args).where(models.Course.id == id)
     query.execute()
     # Return tuple of Body, Status Code, Dictionary of Headers
     return (add_reviews(models.Course.get(models.Course.id == id)), 200, {
         'Location': url_for('resources.courses.course', id=id)
     })
示例#16
0
 def post(self):
     args = self.reqparse.parse_args()
     course = models.Course.create(**args)
     print(args["title"])
     print(args['url'])
     return (add_reviews(course), 201, {
         'Location': url_for('resources.courses.course', id=course.id)
     })
示例#17
0
	def post(self):
		args = self.reqparse.parse_args()
		company = models.Company.create(
			created_by = g.user,
			**args
		)
		return add_marinas(company), 201, {'Location': url_for
				('resources.companies.company', id=company.id)}
示例#18
0
 def post(self):
     args = self.reqparse.parse_args()
     review = models.Review.create(
         created_by=g.user,
         **args
     )
     return (add_course(review), 201, {
             'Location': url_for('resources.reviews.review', id=review.id)
            })
示例#19
0
 def post(self) -> Device:
     device = Device()
     session.add(device)
     self.update(device)
     session.flush()
     session.commit()
     return device, 201, {
         'Location': url_for('device', device_id=device.id)
     }
示例#20
0
 def post(self) -> Device:
     device = Device()
     session.add(device)
     self.update(device)
     session.flush()
     session.commit()
     return device, 201, {
         'Location': url_for('device', device_id=device.id)
     }
示例#21
0
 def put(self, id):
     args = self.reqparse.parse_args()
     review = review_or_404(id)
     query = review.update(**args)
     query.execute()
     review = add_course(review_or_404(id))
     return (review, 200, {
         'Location': url_for('resources.reviews.review', id=id)
     })
示例#22
0
    def test_user_token_auth(self):
        """this method will test that the token work
        when used as a auth method"""

        token_header = {'Authorization': 'token '+self.token}
        response = self.client.get(
                                url_for('resources.todos.todos'),
                                headers=token_header
                                )
        self.assertTrue(response, 200)
示例#23
0
 def put(self, id):
     args = self.reqparse.parse_args()
     try:
         query = models.Todo.update(**args).where(models.Todo.id == id)
         query.execute()
     except models.Todo.DoesNotExist:
         abort(404)
     else:
         return (todo_or_404(id), 201, {
             'Location': url_for('resources.todos.todo', id=id)
         })
示例#24
0
    def post(self, mac):
        args = parser.parse_args(request)

        installimage_config = InstallimageConfig(mac)

        for key in args:
            installimage_config.add_or_set(key, args[key])

        installimage_config.create()

        location = url_for('installimageobject', _method='GET', mac=installimage_config.mac)
        return vars(installimage_config), 201, {'Location': location}
示例#25
0
文件: user.py 项目: cbrand/vpnchooser
 def post(self) -> User:
     args = parser.parse_args()
     user = self._get_by_username(args.name)
     if user is not None:
         abort(409, message='User already exists')
     user = User()
     self.update(user)
     session.add(user)
     session.commit()
     return user, 201, {
         'Location': url_for('user', user_name=user.name)
     }
示例#26
0
文件: vpn.py 项目: cbrand/vpnchooser
 def post(self) -> Vpn:
     """
     Creates the vpn with the given data.
     """
     vpn = Vpn()
     session.add(vpn)
     self.update(vpn)
     session.flush()
     session.commit()
     return vpn, 201, {
         'Location': url_for('vpn', vpn_id=vpn.id)
     }
示例#27
0
文件: pxe.py 项目: aibor/marmoset
    def post(self):
        '''Add a PXE entry for the given ip_address with a given password.'''
        args = parser.parse_args()
        re = pxe.ClientConfig(args.ip_address, args.password, args.script)

        try:
            re.create(pxe.Label.find(args.label))
            location = url_for('pxeobject', _method='GET', ip_address=re.ip_address)
            return vars(re), 201, {'Location': location}
        except pxe.exceptions.InputError as e:
            abort(400, message=str(e))
        except Exception as e:
            abort(500, message=str(e))
示例#28
0
 def delete(self, id):
     try:
         review = models.Review.select().where(
             models.Review.created_by == g.user,
             models.Review.id == id).get()
     except models.Review.DoesNotExist:
         return make_response(
             json.dumps(
                 {'error':
                  'That review does not exist or is not editable'}), 403)
     query = review.delete()
     query.execute()
     return '', 204, {'Location': url_for('resources.reviews.reviews')}
示例#29
0
 def delete(self, id):
     try:
         review = models.Review.select().where(
             models.Review.created_by==g.user,
             models.Review.id==id
         ).get()
     except models.Review.DoesNotExist:
         return make_response(json.dumps(
                 {'error': 'That review does not exist or is not editable'}
             ), 403)
     query = review.delete()
     query.execute()
     return '', 204, {'Location': url_for('resources.reviews.reviews')}
示例#30
0
 def put(self, id):
     args = self.reqparse.parse_args()
     try:
         review = models.Review.select().where(
             models.Review.created_by == g.user,
             models.Review.id == id).get()
     except models.Review.DoesNotExist:
         return make_response(
             json.dumps({'error': 'That review does not exist'}), 403)
     query = review.update(**args)
     query.execute()
     review = add_course(review_or_404(id))
     return (review, 200, {
         'Location': url_for('resources.reviews.review', id=id)
     })
示例#31
0
    def post(self):
        """Creates a new PXE record"""
        args = parser.parse_args()

        if ((args.gateway is None
             and config['DHCPConfig'].getboolean('force_gateway'))
                or args.networkmask is None) and not validation.is_cidr(
                    args.ip_address):
            return {
                'message':
                'missing parameter gateway and networkmask or give an ip address in CIDR notation'
            }, 406

        if not validation.is_ipv4(args.ip_address) and not validation.is_cidr(
                args.ip_address):
            return {'message': 'please provide a valid ipv4 address'}, 406

        if not validation.is_mac(args.mac):
            return {'message': 'please provide a valid mac address'}, 406

        if dhcp.DhcpConfig.exists_ipv4(args.ip_address):
            return {
                'message':
                'dhcp record for ip address %s already exists' %
                args.ip_address
            }, 409

        if dhcp.DhcpConfig.exists_mac(args.mac):
            return {
                'message':
                'dhcp record for mac address %s already exists' % args.mac
            }, 409

        dhcp_config = dhcp.DhcpConfig(args.mac, args.ip_address, args.gateway,
                                      args.networkmask)

        for args_item in parser.args:
            if not args_item.required and args_item.name in args and args[args_item.name] is not None and \
                    args_item.name is not 'gateway' and args_item.name is not 'networkmask':
                dhcp_config.add_additional_statement(args_item.name,
                                                     args[args_item.name])

        dhcp_config.create_isc_ldap()

        location = url_for('dhcpipv4object',
                           _method='GET',
                           ipv4=dhcp_config.ip_address)
        return vars(dhcp_config), 201, {'Location': location}
示例#32
0
	def put(self, id):
		args = self.reqparse.parse_args() # reqprase - parses arguments for us out of request
		try:
			company = models.Company.select().where(
				models.Company.created_by == g.user,
				models.Company.id == id
			).get()
		except models.Company.DoesNotExist:
			return make_response(json.dumps(
				{'error': 'That company doesnt exist or isnt editable' }
			), 403)

		query = models.Company.update(**args).where(models.Company.id==id)
		query.execute()
		return (add_marinas(models.Company.get(models.Company.id==id)), 200, 
				{'Location': url_for('resources.companies.company', id=id)})
示例#33
0
def change_email(user, email):
    serial = base64.b64encode(timestamp_sign(user.username.encode('utf-8'),
                                             current_app.config['SECRET_KEY'],
                                             salt='change_email')).decode('utf-8')
    redis.set('change_email:{}'.format(serial), email, 172800)
    activation_url = urllib.parse.urljoin(
        project_config['HOST'], url_for('authentication.change_email', serial=serial))
    content = render_template('change_email.html',
                              host=project_config['HOST'],
                              corporation=project_config['CORPORATION'],
                              user=user,
                              activation_url=activation_url,
                              current_time=datetime.datetime.now())
    soup = BeautifulSoup(content)
    title = soup.title.string
    send_email.delay(title, content, to_email=email)
示例#34
0
 def put(self, id):
     args = self.reqparse.parse_args()
     try:
         review = models.Review.select().where(
             models.Review.created_by==g.user,
             models.Review.id==id
         ).get()
     except models.Review.DoesNotExist:
         return make_response(json.dumps(
                 {'error': 'That review does not exist or is not editable'}
             ), 403)
     query = review.update(**args)
     query.execute()
     review = add_course(review_or_404(id))
     return (review, 200, {
             'Location': url_for('resources.reviews.review', id=id)
            })
示例#35
0
    def post(self, mac):
        """Creates or updates a config based on the provided MAC"""
        args = parser.parse_args(request)

        installimage_config = InstallimageConfig(mac)
        installimage_config.clear_variables()

        for key in args:
            for value in args.getlist(key):
                installimage_config.add_or_set(key, value)

        installimage_config.create()

        location = url_for('installimageobject',
                           _method='GET',
                           mac=installimage_config.mac)
        return vars(installimage_config), 201, {'Location': location}
示例#36
0
文件: dhcp.py 项目: virtapi/marmoset
    def post(self):
        """Creates a new PXE record"""
        args = parser.parse_args()

        if ((args.gateway is None and config['DHCPConfig'].getboolean(
                'force_gateway')) or args.networkmask is None) and not validation.is_cidr(args.ip_address):
            return {
                'message': 'missing parameter gateway and networkmask or give an ip address in CIDR notation'}, 406

        if not validation.is_ipv4(
                args.ip_address) and not validation.is_cidr(
                args.ip_address):
            return {'message': 'please provide a valid ipv4 address'}, 406

        if not validation.is_mac(args.mac):
            return {'message': 'please provide a valid mac address'}, 406

        if dhcp.DhcpConfig.exists_ipv4(args.ip_address):
            return {'message': 'dhcp record for ip address %s already exists' %
                    args.ip_address}, 409

        if dhcp.DhcpConfig.exists_mac(args.mac):
            return {'message': 'dhcp record for mac address %s already exists' %
                    args.mac}, 409

        dhcp_config = dhcp.DhcpConfig(
            args.mac,
            args.ip_address,
            args.gateway,
            args.networkmask)

        for args_item in parser.args:
            if not args_item.required and args_item.name in args and args[args_item.name] is not None and \
                    args_item.name is not 'gateway' and args_item.name is not 'networkmask':
                dhcp_config.add_additional_statement(
                    args_item.name, args[args_item.name])

        dhcp_config.create_isc_ldap()

        location = url_for(
            'dhcpipv4object',
            _method='GET',
            ipv4=dhcp_config.ip_address)
        return vars(dhcp_config), 201, {'Location': location}
示例#37
0
	def delete(self, id):
		query = models.Company.delete().where(models.Company.id==id)
		query.execute()
		#jsonify - turns what's in the parenthesis into a json response
		return ('', 204, {'Location': url_for('resources.companies.companies')})
示例#38
0
def add_marinas(company):
	company.marinas = [url_for('resources.marinas.marina', id=marina.id)
						for marina in company.marinas]
	return company
示例#39
0
 def delete(self, id):
     query = models.Course.delete().where(models.Course.id == id)
     query.execute()
     return ('', 204, {'Location': url_for('resources.courses.courses')})
示例#40
0
 def delete(self, id):
     query = models.Course.delete().where(models.Course.id==id)
     query.execute()
     return '', 204, {'Location': url_for('resources.courses.courses')}
示例#41
0
 def delete(self, id):
     query = models.Todo.delete().where(models.Todo.id == id)
     query.execute()
     return '', 204, {'location': url_for('resources.todos.todos')}
示例#42
0
 def post(self):
     args = self.reqparse.parse_args()
     todo = models.Todo.create(**args)
     return (todo, 201,
             {'location': url_for('resources.todos.todo', id=todo.id)})
示例#43
0
 def post(self):
     args = self.reqparse.parse_args()
     review = models.Review.create(**args)
     return (add_course(review), 201, {
             'Location': url_for('resources.reviews.review', id=review.id)
            })
示例#44
0
def add_course(review):
    review.for_course = url_for('resources.courses.course', id=review.course.id)
    return review
示例#45
0
 def delete(self, id):
     review = review_or_404(id)
     query = review.delete()
     query.execute()
     return '', 204, {'Location': url_for('resources.reviews.reviews')}
示例#46
0
def add_course(review):
    review.for_course = url_for('resources.courses.course', id=review.course.id)
    return review
示例#47
0
 def put(self, id):
     args = self.reqparse.parse_args()
     query = models.Course.update(**args).where(models.Course.id==id)
     query.execute()
     return (add_reviews(models.Course.get(models.Course.id==id)), 200,
             {'Location': url_for('resources.courses.course', id=id)})
示例#48
0
 def test_users_get(self):
     response = self.client.get(url_for('resources.users.users'))
     myresponse = json.loads(response.get_data())
     self.assertTrue(self.check_username_in_json(myresponse))
示例#49
0
 def post(self):
     args = self.reqparse.parse_args()
     todo = models.Todo.create(**args)
     return todo, 201, {
         'Location': url_for('resources.todos.todo', id=todo.id)
     }
示例#50
0
 def get(self):
     print(g.user.id)
     todos = [marshal(todo, todo_fields) for todo in get_users_todos()]
     return (todos, 200, {'Location': url_for('resources.todos.todos')})
示例#51
0
 def delete(self, id):
     query = models.Todo.delete().where(models.Todo.id == id)
     query.execute()
     return ('', 204, {'Location': url_for('resources.todos.todos')})
示例#52
0
 def delete(self, id):
     query = models.Review.delete().where(models.Review.id == id)
     query.execute()
     return ('', 204, {'Location': url_for('resources.reviews.review')})
示例#53
0
	def post(self):
		args = self.reqparse.parse_args()
		marina = models.Marina.create(**args)
		return add_company(marina), 201, {'Location': url_for
				('resources.marinas.marina', id=marina.id)}
示例#54
0
 def post(self):
     args = self.reqparse.parse_args()
     course = models.Course.create(**args)
     return (add_reviews(course), 201, {
         'Location': url_for('resources.courses.course', id=course.id)})
示例#55
0
def add_company(marina):
	marina.for_company = [url_for('resources.companies.company', id=marina.company.id)]
	return marina
示例#56
0
def add_reviews(course):
    course.reviews = [url_for('resources.reviews.review', id=review.id)
        for review in course.review_set]
    return course
示例#57
0
 def test_todos_get(self):
     response = self.client.get(url_for('resources.todos.todos'),
                                headers=self.headers)
     myresponse = json.loads(response.get_data())
     self.assertTrue(self.check_id_in_json(myresponse, self.todo.id))
示例#58
0
def add_reviews(course):
    course.reviews = [
        url_for('resources.reviews.review', id=review.id)
        for review in course.review_set
    ]
    return course