implement fail if object_id starts with /

Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
Steven Armstrong 2011-10-14 11:25:39 +02:00
parent 9640c3a098
commit 3e3919d15f
2 changed files with 11 additions and 0 deletions

View file

@ -21,6 +21,7 @@
from cdist.core.type import Type
from cdist.core.object import Object
from cdist.core.object import IllegalObjectIdError
from cdist.core.explorer import Explorer
from cdist.core.manifest import Manifest
from cdist.core.code import Code

View file

@ -33,6 +33,14 @@ log = logging.getLogger(__name__)
DOT_CDIST = '.cdist'
class IllegalObjectIdError(cdist.Error):
def __init__(self, object_id):
self.object_id = object_id
def __str__(self):
return 'Illegal object id: %s' % self.object_id
class Object(object):
"""Represents a cdist object.
@ -79,6 +87,8 @@ class Object(object):
return self.__class__(self.type.__class__(type_path, type_name), object_path, object_id=object_id)
def __init__(self, cdist_type, base_path, object_id=None):
if object_id and object_id.startswith('/'):
raise IllegalObjectIdError(object_id)
self.type = cdist_type # instance of Type
self.base_path = base_path
self.object_id = object_id