summaryrefslogtreecommitdiff
path: root/src/server/rz_api_common.py
diff options
context:
space:
mode:
authorLV-426 <lv-426@taproot.org.il>2015-01-04 17:16:12 +0200
committerLV-426 <lv-426@taproot.org.il>2015-01-04 17:16:12 +0200
commitf5494d9233d6f9967c614eef23dee1f29af056c9 (patch)
tree763da6c98efe56acb342aa09d8c4866624c6f32a /src/server/rz_api_common.py
parentf1dd537689307329dfe42c88ee2e8fda3355eb84 (diff)
rhizi_api breakup: common, rest & websocket files
Diffstat (limited to 'src/server/rz_api_common.py')
-rw-r--r--src/server/rz_api_common.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/server/rz_api_common.py b/src/server/rz_api_common.py
new file mode 100644
index 00000000..68d9008d
--- /dev/null
+++ b/src/server/rz_api_common.py
@@ -0,0 +1,47 @@
+"""
+Common public API logic:
+ - object sanitization for inbound data
+ - object validation for inbound data
+ - sanitize_input__XXX: concerned with sanitizing potential currupt data arriving
+ from external sources.
+ - validae_object__XXX: concerned with validating the logical state of an object
+
+"""
+def __sanitize_input(*args, **kw_args):
+ pass
+
+def sanitize_input__node(n):
+ """
+ provide a control point as to which node fields are persisted
+ """
+ assert None != n.get('id'), 'invalid input: node: missing id'
+
+def sanitize_input__link(l):
+ """
+ provide a control point as to which link fields are persisted
+ """
+
+ # expected prop assertions
+ assert None != l.get('id'), 'invalid input: link: missing id'
+ assert None != l.get('__src_id'), 'invalid input: link: missing src id'
+ assert None != l.get('__dst_id'), 'invalid input: link: missing dst id'
+
+ # unexpected prop assertions
+ assert None == l.get('__type'), 'client is sending us __type link property, it should not'
+ assert None == l.get('name'), 'client is sending us name link property, it should not'
+
+def sanitize_input__topo_diff(topo_diff):
+ for n in topo_diff.node_set_add:
+ sanitize_input__node(n)
+ for l in topo_diff.link_set_add:
+ sanitize_input__link(l)
+
+def sanitize_input__attr_diff(attr_diff):
+ pass # TODO: impl
+
+def validate_obj__attr_diff(ad):
+ # check for name attr changes, which are currently forbidden
+ for n_id, node_attr_diff_set in ad['__type_node'].items():
+ for attr_name in node_attr_diff_set['__attr_write'].keys():
+ if 'id' == attr_name:
+ raise Exception('validation error: Attr_Diff: forbidden attribute change: \'id\', n_id: ' + n_id)