Updated Eve, Flask, and Werkzeug. Adjusted code to make Pillar work again.
Eve : 0.6.3 → 0.7.3 Flask : 0.10.1 → 0.12.2 Werkzeug: 0.11.10 → 0.11.15 Also updated some secondary requirements.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"""Pillar server."""
|
||||
|
||||
import collections
|
||||
import contextlib
|
||||
import copy
|
||||
import json
|
||||
import logging
|
||||
@@ -519,28 +520,32 @@ class PillarServer(Eve):
|
||||
"""Workaround for Eve issue https://github.com/nicolaiarocci/eve/issues/810"""
|
||||
from eve.methods.post import post_internal
|
||||
|
||||
with self.test_request_context(method='POST', path='%s/%s' % (self.api_prefix, resource)):
|
||||
return post_internal(resource, payl=payl, skip_validation=skip_validation)
|
||||
url = self.config['URLS'][resource]
|
||||
path = '%s/%s' % (self.api_prefix, url)
|
||||
with self.__fake_request_url_rule('POST', path):
|
||||
return post_internal(resource, payl=payl, skip_validation=skip_validation)[:4]
|
||||
|
||||
def put_internal(self, resource, payload=None, concurrency_check=False,
|
||||
skip_validation=False, **lookup):
|
||||
"""Workaround for Eve issue https://github.com/nicolaiarocci/eve/issues/810"""
|
||||
from eve.methods.put import put_internal
|
||||
|
||||
path = '%s/%s/%s' % (self.api_prefix, resource, lookup['_id'])
|
||||
with self.test_request_context(method='PUT', path=path):
|
||||
url = self.config['URLS'][resource]
|
||||
path = '%s/%s/%s' % (self.api_prefix, url, lookup['_id'])
|
||||
with self.__fake_request_url_rule('PUT', path):
|
||||
return put_internal(resource, payload=payload, concurrency_check=concurrency_check,
|
||||
skip_validation=skip_validation, **lookup)
|
||||
skip_validation=skip_validation, **lookup)[:4]
|
||||
|
||||
def patch_internal(self, resource, payload=None, concurrency_check=False,
|
||||
skip_validation=False, **lookup):
|
||||
"""Workaround for Eve issue https://github.com/nicolaiarocci/eve/issues/810"""
|
||||
from eve.methods.patch import patch_internal
|
||||
|
||||
path = '%s/%s/%s' % (self.api_prefix, resource, lookup['_id'])
|
||||
with self.test_request_context(method='PATCH', path=path):
|
||||
url = self.config['URLS'][resource]
|
||||
path = '%s/%s/%s' % (self.api_prefix, url, lookup['_id'])
|
||||
with self.__fake_request_url_rule('PATCH', path):
|
||||
return patch_internal(resource, payload=payload, concurrency_check=concurrency_check,
|
||||
skip_validation=skip_validation, **lookup)
|
||||
skip_validation=skip_validation, **lookup)[:4]
|
||||
|
||||
def _list_routes(self):
|
||||
from pprint import pprint
|
||||
@@ -558,11 +563,15 @@ class PillarServer(Eve):
|
||||
# and rules that require parameters
|
||||
if "GET" in rule.methods and has_no_empty_params(rule):
|
||||
url = url_for(rule.endpoint, **(rule.defaults or {}))
|
||||
links.append((url, rule.endpoint))
|
||||
links.append((url, rule.endpoint, rule.methods))
|
||||
if "PATCH" in rule.methods:
|
||||
args = {arg: arg for arg in rule.arguments}
|
||||
url = url_for(rule.endpoint, **args)
|
||||
links.append((url, rule.endpoint, rule.methods))
|
||||
|
||||
links.sort(key=lambda t: len(t[0]) + 100 * ('/api/' in t[0]))
|
||||
links.sort(key=lambda t: (('/api/' in t[0]), len(t[0])))
|
||||
|
||||
pprint(links)
|
||||
pprint(links, width=300)
|
||||
|
||||
def db(self, collection_name: str = None) \
|
||||
-> typing.Union[pymongo.collection.Collection, pymongo.database.Database]:
|
||||
@@ -583,3 +592,27 @@ class PillarServer(Eve):
|
||||
|
||||
return jinja2.Markup(''.join(ext.sidebar_links(project)
|
||||
for ext in self.pillar_extensions.values()))
|
||||
|
||||
@contextlib.contextmanager
|
||||
def __fake_request_url_rule(self, method: str, url_path: str):
|
||||
"""Tries to force-set the request URL rule.
|
||||
|
||||
This is required by Eve (since 0.70) to be able to construct a
|
||||
Location HTTP header that points to the resource item.
|
||||
|
||||
See post_internal, put_internal and patch_internal.
|
||||
"""
|
||||
|
||||
import werkzeug.exceptions as wz_exceptions
|
||||
|
||||
with self.test_request_context(method=method, path=url_path) as ctx:
|
||||
try:
|
||||
rule, _ = ctx.url_adapter.match(url_path, method=method, return_rule=True)
|
||||
except (wz_exceptions.MethodNotAllowed, wz_exceptions.NotFound):
|
||||
# We're POSTing things that we haven't told Eve are POSTable. Try again using the
|
||||
# GET method.
|
||||
rule, _ = ctx.url_adapter.match(url_path, method='GET', return_rule=True)
|
||||
current_request = request._get_current_object()
|
||||
current_request.url_rule = rule
|
||||
|
||||
yield ctx
|
||||
|
@@ -718,7 +718,7 @@ users = {
|
||||
'cache_expires': 10,
|
||||
|
||||
'resource_methods': ['GET'],
|
||||
'item_methods': ['GET', 'PUT', 'PATCH'],
|
||||
'item_methods': ['GET', 'PUT'],
|
||||
'public_item_methods': ['GET'],
|
||||
|
||||
'schema': users_schema
|
||||
|
@@ -2,7 +2,6 @@
|
||||
|
||||
import logging
|
||||
|
||||
from eve.methods.patch import patch_internal
|
||||
from flask import current_app
|
||||
import werkzeug.exceptions as wz_exceptions
|
||||
|
||||
@@ -145,13 +144,13 @@ def edit_comment(user_id, node_id, patch):
|
||||
raise wz_exceptions.Forbidden('You can only edit your own comments.')
|
||||
|
||||
# Use Eve to PATCH this node, as that also updates the etag.
|
||||
r, _, _, status = patch_internal('nodes',
|
||||
{'properties.content': patch['content'],
|
||||
'project': node['project'],
|
||||
'user': node['user'],
|
||||
'node_type': node['node_type']},
|
||||
concurrency_check=False,
|
||||
_id=node_id)
|
||||
r, _, _, status = current_app.patch_internal('nodes',
|
||||
{'properties.content': patch['content'],
|
||||
'project': node['project'],
|
||||
'user': node['user'],
|
||||
'node_type': node['node_type']},
|
||||
concurrency_check=False,
|
||||
_id=node_id)
|
||||
if status != 200:
|
||||
log.error('Error %i editing comment %s for user %s: %s',
|
||||
status, node_id, user_id, r)
|
||||
|
@@ -7,8 +7,6 @@ import copy
|
||||
import logging
|
||||
|
||||
from bson.objectid import ObjectId, InvalidId
|
||||
from eve.methods.put import put_internal
|
||||
from eve.methods.post import post_internal
|
||||
|
||||
from flask import current_app
|
||||
from flask_script import Manager
|
||||
@@ -565,7 +563,7 @@ def replace_pillar_node_type_schemas(proj_url=None, all_projects=False):
|
||||
|
||||
# Use Eve to PUT, so we have schema checking.
|
||||
db_proj = remove_private_keys(project)
|
||||
r, _, _, status = put_internal('projects', db_proj, _id=project['_id'])
|
||||
r, _, _, status = current_app.put_internal('projects', db_proj, _id=project['_id'])
|
||||
if status != 200:
|
||||
log.error('Error %i storing altered project %s %s', status, project['_id'], r)
|
||||
raise SystemExit('Error storing project, see log.')
|
||||
@@ -686,7 +684,7 @@ def upgrade_attachment_schema(proj_url=None, all_projects=False):
|
||||
|
||||
# Use Eve to PUT, so we have schema checking.
|
||||
db_proj = remove_private_keys(project)
|
||||
r, _, _, status = put_internal('projects', db_proj, _id=project['_id'])
|
||||
r, _, _, status = current_app.put_internal('projects', db_proj, _id=project['_id'])
|
||||
if status != 200:
|
||||
log.error('Error %i storing altered project %s %s', status, project['_id'], r)
|
||||
raise SystemExit('Error storing project, see log.')
|
||||
@@ -716,7 +714,7 @@ def upgrade_attachment_schema(proj_url=None, all_projects=False):
|
||||
|
||||
# Use Eve to PUT, so we have schema checking.
|
||||
db_node = remove_private_keys(node)
|
||||
r, _, _, status = put_internal('nodes', db_node, _id=node['_id'])
|
||||
r, _, _, status = current_app.put_internal('nodes', db_node, _id=node['_id'])
|
||||
if status != 200:
|
||||
log.error('Error %i storing altered node %s %s', status, node['_id'], r)
|
||||
raise SystemExit('Error storing node; see log.')
|
||||
@@ -760,7 +758,7 @@ def create_blog(proj_url):
|
||||
replace_existing=False)
|
||||
|
||||
proj_id = proj['_id']
|
||||
r, _, _, status = put_internal('projects', remove_private_keys(proj), _id=proj_id)
|
||||
r, _, _, status = current_app.put_internal('projects', remove_private_keys(proj), _id=proj_id)
|
||||
if status != 200:
|
||||
log.error('Error %i storing altered project %s %s', status, proj_id, r)
|
||||
return 4
|
||||
@@ -777,7 +775,7 @@ def create_blog(proj_url):
|
||||
'properties': {},
|
||||
'project': proj_id,
|
||||
}
|
||||
r, _, _, status = post_internal('nodes', blog)
|
||||
r, _, _, status = current_app.post_internal('nodes', blog)
|
||||
if status != 201:
|
||||
log.error('Error %i storing blog node: %s', status, r)
|
||||
return 4
|
||||
|
@@ -410,7 +410,7 @@ class AbstractPillarTest(TestMinimal):
|
||||
headers['Content-Type'] = 'application/json'
|
||||
|
||||
if etag is not None:
|
||||
if method == 'PUT':
|
||||
if method in {'PUT', 'PATCH', 'DELETE'}:
|
||||
headers['If-Match'] = etag
|
||||
elif method == 'GET':
|
||||
headers['If-None-Match'] = etag
|
||||
|
Reference in New Issue
Block a user