-
Notifications
You must be signed in to change notification settings - Fork 212
Adding uniqueId to get static references for findings #186
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
Adding uniqueId to get static references for findings #186
Conversation
CodeSee Review Map:Review in an interactive map View more CodeSee Maps Legend |
per-oestergaard
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoiding changes to irrelevant parts of the file owing to auto-format and a line deletion
|
Hey, thanks for the addition! A suggestion on tests would be that the uniqueId stays constant between runs. You could create an external file with a set of uniqueIds, run a TM and see that the newly generated ones match with the ones in the file. About the global variable, we are trying to stay away from those as much as possible. What was it you weren't able to access on Elements? Let's see if we can fix that. |
…per-oestergaard/pytm into per-oestergaard-adding-uniqueId
I added test test_uniqueid_two_runs |
I definitely also want to avoid global contexts ;) The problem seems to stem from the "weird" (to be at least) way variables in TM are handled. Settings and getters seems to be used and the getter does not work globally. If I break in init of Class Element - def __init__(self, name, **kwargs):
for key, value in kwargs.items():
setattr(self, key, value)
self.name = nameUniqueIdFormat_shadow.format(name, self.uniqueId)
self.controls = Controls()
self.uuid = uuid.UUID(int=random.getrandbits(128))
self._is_drawn = False
TM._elements.append(self)at the I cannot make it return the value If I instead break in say check of class TM, I get the same error for the TM (static) reference; however, it works using self - Any ideas? |
|
If there's any confusion or error in the way varStrings works, it is probably due to my own mistake. It seems to be working everywhere else, what makes it unique to your case? I mean, not to be all "it works on my machine", which I am not, I just want to try and understand better the uniqueness of this case. I will try to run it later today (or this week) and see if I can figure something out. Perhaps varStrings needs an explicit get ? |
|
The "only" special I see is that I try to access the value from another class. I do not see that anywhere else in the code. |
|
If I subclass Element of TM: class Element(TM):I can access the values. However that have side-effects (like including too much in json dumps), so tests fails. TM.nameUniqueIdFormat.__get__(TM.nameUniqueIdFormat, TM.nameUniqueIdFormat.default)But that seems only to get the default value. Last, I tried adding self.value = valueto the class Any ideas? |
|
Well that goes beyond my Python-fu. @nineinchnick some insight perhaps? |
|
There's an Can you check if that would solve your issue? |
Hi @nineinchnick, pleased to meet your. Do understand you question, you suggest that I use the order instead of adding the unique id? Perhaps that could be a solution to the uniqueness issue. However, I would still like to add the number to the drawings etc. so I would end up with the python issue anyway :'( |
The finding holds a reference to both the threat and the element it was matched against, so you can access the threat id and the element id (order). You should be able to extend pytm to change the way it renders things. I'd be happy to help you with that, ping me on our Slack. |
|
A way (around the Python issue, but perhaps also generic) could be to update |
|
I have PR'ed another method #190 and thus closing this |
In my use case, I want to synchronize the findings with an external risk system. To be able to do so, I added these features -
I apologize upfront for these things -