From 3e3919d15f00c62c670b3ab901d7274e43a2b770 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 14 Oct 2011 11:25:39 +0200 Subject: [PATCH] implement fail if object_id starts with / Signed-off-by: Steven Armstrong --- lib/cdist/core/__init__.py | 1 + lib/cdist/core/object.py | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/cdist/core/__init__.py b/lib/cdist/core/__init__.py index 1dec9e8f..507082a3 100644 --- a/lib/cdist/core/__init__.py +++ b/lib/cdist/core/__init__.py @@ -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 diff --git a/lib/cdist/core/object.py b/lib/cdist/core/object.py index 282e8be5..c447f243 100644 --- a/lib/cdist/core/object.py +++ b/lib/cdist/core/object.py @@ -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