Skip to content
This repository has been archived by the owner on Dec 30, 2020. It is now read-only.

Fix databag item update for recent versions of chef (>10) and add commis/wsgi.py #14

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
8 changes: 6 additions & 2 deletions commis/data_bags/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from commis.data_bags.forms import DataBagForm, DataBagItemForm
from commis.data_bags.models import DataBag, DataBagItem
from commis.db import update
from commis.utils import json

class DataBagAPIView(CommisAPIView):
model = DataBag
Expand Down Expand Up @@ -49,10 +50,13 @@ def item_get(self, request, bag_name, name):
def item_update(self, request, bag_name, name):
if not request.json:
raise ChefAPIError(500, 'No data sent')
if request.json.get('id') != name:
data = request.json.get('raw_data')
if not isinstance(data, dict):
data = request.json
if not isinstance(data, dict) or data.get('id') != name:
raise ChefAPIError(500, 'Name mismatch in data bag item')
item = self.get_item_or_404(bag_name, name)
update(item, data=request.raw_post_data)
update(item, data=json.dumps(data, indent=4))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the indent? Might as well make it smaller in the DB :)

return HttpResponse(item.data, status=200, content_type='application/json')

@api('DELETE', admin=True)
Expand Down
32 changes: 32 additions & 0 deletions commis/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
WSGI config for commis project.

This module contains the WSGI application used by Django's development server
and any production WSGI deployments. It should expose a module-level variable
named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
this application via the ``WSGI_APPLICATION`` setting.

Usually you will have the standard Django WSGI application here, but it also
might make sense to replace the whole Django WSGI application with a custom one
that later delegates to the Django one. For example, you could introduce WSGI
middleware here, or combine a Django application with an application of another
framework.

"""
import os

# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
# if running multiple sites in the same mod_wsgi process. To fix this, use
# mod_wsgi daemon mode with each site in its own daemon process, or use
# os.environ["DJANGO_SETTINGS_MODULE"] = "commis.settings"
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")

# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)