Repository: vertexproject/synapse

Issue:
Ability to lift by tufo guid in storm
thesilence [12:29 PM] 
There may be cases when working at the CLI where "lift by GUID" may be useful, mostly from a copypasta standpoint / repr limitations.

thesilence [12:30 PM] 
I haven't run across this specifically, but (again, "theoretically") there may be node type(s) where properties are too lengthy / complex to type or copy, so the easiest thing to copypasta would be the GUID.

epiphyte 
[12:30 PM] 
yeah - and there is also the use-case @7.389 mentioned for sharing

epiphyte 
[12:31 PM] 
"Hey guys, checkout 'iden=12345 totags()' - its a real doozy"

Discussion:

Patch:
diff --git a/synapse/lib/storm.py b/synapse/lib/storm.py
index f462aa012..a1dfde286 100644
--- a/synapse/lib/storm.py
+++ b/synapse/lib/storm.py
@@ -406,6 +406,7 @@ class Runtime(Configable):
         self.setOperFunc('load', self._stormOperLoad)
         self.setOperFunc('clear', self._stormOperClear)
 
+        self.setOperFunc('guid', self._stormOperGuid)
         self.setOperFunc('join', self._stormOperJoin)
         self.setOperFunc('lift', self._stormOperLift)
         self.setOperFunc('refs', self._stormOperRefs)
@@ -1101,7 +1102,7 @@ class Runtime(Configable):
         core = self.getStormCore()
 
         props = {}
-        for k,v in kwlist:
+        for k, v in kwlist:
 
             if not k[0] == ':':
                 raise s_common.BadSyntaxError(mesg='addnode() expects relative props with : prefix')
@@ -1319,3 +1320,9 @@ class Runtime(Configable):
                 [query.add(n) for n in nodes]
 
         return
+
+    def _stormOperGuid(self, query, oper):
+        args = oper[1].get('args')
+        core = self.getStormCore()
+
+        [query.add(node) for node in core.getTufosByIdens(args)]


Test patch:
diff --git a/synapse/tests/test_lib_storm.py b/synapse/tests/test_lib_storm.py
index 3f6b77989..07a5e269e 100644
--- a/synapse/tests/test_lib_storm.py
+++ b/synapse/tests/test_lib_storm.py
@@ -563,6 +563,29 @@ class StormTest(SynTest):
                 ['1.2.3.4', 'vv', '#foo.bar'],
             ])
 
+    def test_storm_guid(self):
+
+        with s_cortex.openurl('ram:///') as core:
+
+            node0 = core.formTufoByProp('inet:ipv4', '1.2.3.4')
+            node1 = core.formTufoByProp('inet:ipv4', '4.5.6.7')
+
+            nodes = core.eval('guid()')
+            self.eq(len(nodes), 0)
+
+            nodes = core.eval('guid(%s)' % node0[0])
+            self.eq(nodes[0][1].get('inet:ipv4'), 0x01020304)
+
+            nodes = core.eval('guid(%s,%s)' % (node0[0], node1[0]))
+            vals = list(sorted(v[1].get('inet:ipv4') for v in nodes))
+            self.eq(vals, [0x01020304, 0x04050607])
+
+            # We can lift dark rows using guid() but kind of an easter egg.
+            core.addTufoDark(node0, 'foo:bar', 'duck:knight')
+            nodes = core.eval('guid(%s)' % node0[0][::-1])
+            self.eq(len(nodes), 1)
+            self.eq(node0[0], nodes[0][0][::-1])
+
 class LimitTest(SynTest):
 
     def test_limit_default(self):