Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Epiphyte synprop req #409

Merged
merged 17 commits into from
Aug 27, 2017
Merged

Conversation

vEpiphyte
Copy link
Contributor

Enforce req=1 on node properties during node creation.

@@ -8,6 +14,19 @@

class CryptoMod(CoreModule):

@modelrev('crypto', 201708231712)
def _revModl201708231712(self):
node = self.core.formTufoByProp('syn:prop', 'rsa:key:mod')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wont this always create it?

@@ -411,6 +411,18 @@ def _revModl201708141516(self):
if 'syn:type:fields' not in node[1]:
self.core.addRows([(node[0], 'syn:type:fields', 'url=inet:url,file=file:bytes', s_common.now())])

@modelrev('inet', 201708231646)
def _revModl201708231646(self):
node = self.core.formTufoByProp('syn:prop', 'inet:ipv4:type')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here as well...

@vEpiphyte
Copy link
Contributor Author

This has been tested against the content of #400 and it does work there.

@codecov
Copy link

codecov bot commented Aug 24, 2017

Codecov Report

Merging #409 into master will increase coverage by 0.56%.
The diff coverage is 95.45%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #409      +/-   ##
==========================================
+ Coverage   89.93%   90.49%   +0.56%     
==========================================
  Files         127      127              
  Lines       14312    14336      +24     
==========================================
+ Hits        12871    12974     +103     
+ Misses       1441     1362      -79
Impacted Files Coverage Δ
synapse/exc.py 93.96% <100%> (ø) ⬆️
synapse/datamodel.py 97.65% <100%> (+0.07%) ⬆️
synapse/models/crypto.py 100% <100%> (ø) ⬆️
synapse/models/inet.py 98.47% <100%> (+1.88%) ⬆️
synapse/lib/ingest.py 88.05% <85.71%> (-0.1%) ⬇️
synapse/cores/common.py 93.34% <92.85%> (-0.02%) ⬇️
synapse/lib/types.py 87.9% <0%> (+0.2%) ⬆️
synapse/cores/lmdb.py 92.09% <0%> (+0.21%) ⬆️
synapse/lib/socket.py 84.13% <0%> (+0.28%) ⬆️
synapse/lib/persist.py 90.42% <0%> (+0.53%) ⬆️
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ba0193b...9732028. Read the comment docs.

@@ -1878,6 +1881,21 @@ def _runAutoAdd(self, toadd):
continue
self.formTufoByProp(form, valu)

def _reqProps(self, form, fulls):
if not self.enforce:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if enforce mode is off, required props are not required. (thinking aloud)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vertexmc this is per @invisig0th

# despite the model requiring a ptype to be present.
props.pop('syn:prop:ptype', None)

for prop in props:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to avoid the loops in python ( and make them be in C ) you could probably do something like

propset = set(props)
fullset = set(fulls)

missing = propset - fullset
if missing:
    etc etc etc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fixed; along with a early return if there are no req'd props on the form.

@@ -100,6 +100,7 @@ def __init__(self, load=True):
self.props = {}
self.forms = set()

self.reqprops = collections.defaultdict(list)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call on keeping these in an optimized lookup

@@ -121,7 +121,7 @@ class NoInitCore(Exception): pass # API disabled because no cortex
class NoCurrSess(Exception): pass # API requires a current session

class SidNotFound(Exception): pass
class PropNotFound(Exception): pass
class PropNotFound(SynErr): pass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should create a story to make all of these Exceptions SynErrs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vertexmc we do have one in our backlog

self.eq(pdef[1].get('syn:prop:ptype'), 'str')

# Now make a node
tufo = core.formTufoByProp('inet:ipv4', '192.168.1.1', type='uni')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically type for this ipv4 would be priv ;)

def _revModl201708231712(self):
node = self.core.getTufoByProp('syn:prop', 'rsa:key:mod')
if not node: # pragma: no cover
# Its possible someone deleted their syn:prop=inet:ipv4:type node :(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong prop in comment

@@ -125,10 +126,11 @@ def __init__(self, load=True):
self.addTufoProp('syn:form', 'ptype', ptype='syn:type', req=1, doc='Synapse type for this form')

self.addTufoForm('syn:prop', ptype='syn:prop')
self.addTufoProp('syn:prop', 'doc', ptype='str', req=1, doc='Description of the property definition')
# TODO - Re-enable syn:prop:doc req = 1 after cleaning up property docstrings.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add another story to track adding docstrings for all props and enabling this. We should inform users before enabling this to avoid private models breaking.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@therealsilence has a story for doing all these docs already.

Copy link
Contributor

@vertexmc vertexmc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. I had one change and agree with @invisig0th 's request changes though.

@vEpiphyte vEpiphyte added the bug label Aug 24, 2017
@vEpiphyte vEpiphyte added this to the v0.0.22 milestone Aug 24, 2017
Copy link
Contributor

@vertexmc vertexmc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great now! 👍 to merge after rebased

@vEpiphyte vEpiphyte merged commit 47a75a1 into vertexproject:master Aug 27, 2017
@vEpiphyte vEpiphyte deleted the epiphyte_synprop_req branch August 30, 2017 23:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants