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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions commis/cookbooks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,21 @@ def from_dict(self, data):
cookbook.recipes.create(name=name, description=description)
for type, label in CookbookFile.TYPES:
for file_info in data.get(type, []):
new_content = False
try:
cookbook_file = cookbook.files.get(type=type, file__checksum=file_info['checksum'])
cookbook_file = cookbook.files.get(type=type, path=file_info["path"])
except CookbookFile.DoesNotExist:
cookbook_file = cookbook.files.create(type=type, path=file_info["path"])
new_content = True
else:
if cookbook_file.file.checksum != file_info["checksum"]:
new_content = True
if new_content:
try:
file = SandboxFile.objects.get(checksum=file_info['checksum'])
cookbook_file.file = SandboxFile.objects.get(checksum=file_info['checksum'], uploaded=True)
except SandboxFile.DoesNotExist:
raise ChefAPIError(500, 'Checksum %s does not match any uploaded file', file_info['checksum'])
if not file.uploaded:
raise ChefAPIError(500, 'Checksum %s does not match any uploaded file', file_info['checksum'])
cookbook_file = cookbook.files.create(type=type, file=file)
cookbook_file.name = file_info['name']
cookbook_file.path = file_info['path']
cookbook_file.specificity = file_info['specificity']
cookbook_file.save()
cookbook.save()
Expand Down
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))
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)