Permalink
Browse files

New '/packager/update_params' endpoint

Update a package model 'defaultParams' property with the passed request
json. Clears the os-api cache for the package.
  • Loading branch information...
brew committed Apr 12, 2018
1 parent 36a75b0 commit 3f356588e67b775f298877d51aaeb9db8838d3fc
Showing with 43 additions and 0 deletions.
  1. +15 −0 conductor/blueprints/package/blueprint.py
  2. +27 −0 conductor/blueprints/package/controllers.py
  3. +1 −0 requirements.txt
@@ -105,6 +105,19 @@ def stats():
return jsonpify(controllers.stats())
def update_params():
jwt = request.values.get('jwt')
datapackage = request.values.get('id')
params = request.get_json()
if datapackage is None:
abort(400)
if jwt is None:
abort(403)
ret = controllers.update_params(datapackage, jwt, params)
return jsonpify(ret)
def create():
"""Create blueprint.
"""
@@ -128,6 +141,8 @@ def create():
'run-hooks', 'run-hooks', run_hooks, methods=['POST'])
blueprint.add_url_rule(
'stats', 'stats', stats, methods=['GET'])
blueprint.add_url_rule(
'update_params', 'update_params', update_params, methods=['POST'])
# Return blueprint
return blueprint
@@ -6,10 +6,12 @@
import requests
from six import StringIO
from os_api_cache import get_os_cache
from conductor.blueprints.user.controllers import PUBLIC_KEY
from .models import package_registry
os_api_url = os.environ.get('OS_API_URL')
api_cache = get_os_cache()
def upload(datapackage, callback, token, cache_set):
@@ -103,6 +105,31 @@ def toggle_publish(name, token, toggle=False, publish=False):
return {'success': True, 'published': not private}
def update_params(name, token, params):
'''
Update package.defaultParams for the passed `name`. Only the owner can
update.
'''
try:
token = jwt.decode(token.encode('ascii'),
PUBLIC_KEY,
algorithm='RS256')
userid = token['userid']
if name.split(':')[0] != userid:
logging.error('USERID=%r, name=%r', userid, name)
return None
except jwt.InvalidTokenError:
return None
_, _, datapackage, _, _, _, _, _ = package_registry.get_raw(name)
datapackage['defaultParams'] = params
package_registry.update_model(name, datapackage=datapackage)
# Clear the cached entry for this package
api_cache.clear(name)
return {'success': True}
def delete_package(name, token):
try:
token = jwt.decode(token.encode('ascii'),
View
@@ -13,6 +13,7 @@ psycopg2
cryptography
elasticsearch>=1.0.0,<2.0.0
os-package-registry>=0.0.12
os-api-cache>=0.0.6
blinker>=1.1
python-dotenv
gunicorn

0 comments on commit 3f35658

Please sign in to comment.