Commit 82bad6e9 authored by Łukasz Nowak's avatar Łukasz Nowak

Allow flexibility in headers.

parent a97747ed
...@@ -41,6 +41,7 @@ import json ...@@ -41,6 +41,7 @@ import json
import transaction import transaction
from App.Common import rfc1123_date from App.Common import rfc1123_date
from DateTime import DateTime from DateTime import DateTime
import re
class WrongRequest(Exception): class WrongRequest(Exception):
pass pass
...@@ -61,7 +62,7 @@ def requireHeader(header_dict): ...@@ -61,7 +62,7 @@ def requireHeader(header_dict):
def wrapperRequireHeader(self, *args, **kwargs): def wrapperRequireHeader(self, *args, **kwargs):
problem_dict = {} problem_dict = {}
for header, value in header_dict.iteritems(): for header, value in header_dict.iteritems():
if self.REQUEST.getHeader(header) != value: if not re.match(value, self.REQUEST.getHeader(header)):
problem_dict[header] = 'Header with value %r is required.' % value problem_dict[header] = 'Header with value %r is required.' % value
if not problem_dict: if not problem_dict:
return fn(self, *args, **kwargs) return fn(self, *args, **kwargs)
...@@ -249,7 +250,7 @@ class InstancePublisher(GenericPublisher): ...@@ -249,7 +250,7 @@ class InstancePublisher(GenericPublisher):
@responseSupport() @responseSupport()
@requireHeader({'Accept': 'application/json', @requireHeader({'Accept': 'application/json',
'Content-Type': 'application/json'}) 'Content-Type': '^application/json.*'})
@requireJson(dict( @requireJson(dict(
title=(unicode, encode_utf8), title=(unicode, encode_utf8),
connection=dict connection=dict
...@@ -285,7 +286,7 @@ class InstancePublisher(GenericPublisher): ...@@ -285,7 +286,7 @@ class InstancePublisher(GenericPublisher):
return self.REQUEST.response return self.REQUEST.response
@requireHeader({'Accept': 'application/json', @requireHeader({'Accept': 'application/json',
'Content-Type': 'application/json'}) 'Content-Type': '^application/json.*'})
@requireJson(dict(log=unicode)) @requireJson(dict(log=unicode))
@extractDocument(['Software Instance', 'Slave Instance']) @extractDocument(['Software Instance', 'Slave Instance'])
def __bang(self): def __bang(self):
...@@ -303,7 +304,7 @@ class InstancePublisher(GenericPublisher): ...@@ -303,7 +304,7 @@ class InstancePublisher(GenericPublisher):
return self.REQUEST.response return self.REQUEST.response
@requireHeader({'Accept': 'application/json', @requireHeader({'Accept': 'application/json',
'Content-Type': 'application/json'}) 'Content-Type': '^application/json.*'})
@requireJson(dict( @requireJson(dict(
slave=bool, slave=bool,
software_release=(unicode, encode_utf8), software_release=(unicode, encode_utf8),
...@@ -439,7 +440,7 @@ class InstancePublisher(GenericPublisher): ...@@ -439,7 +440,7 @@ class InstancePublisher(GenericPublisher):
class ComputerPublisher(GenericPublisher): class ComputerPublisher(GenericPublisher):
@responseSupport() @responseSupport()
@requireHeader({'Accept': 'application/json', @requireHeader({'Accept': 'application/json',
'Content-Type': 'application/json'}) 'Content-Type': '^application/json.*'})
@extractDocument('Computer') @extractDocument('Computer')
@requireJson(dict( @requireJson(dict(
partition=list, partition=list,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment