Skip to content
This repository has been archived by the owner on Nov 29, 2021. It is now read-only.

Send the VTs by chunk as response for get_vts #215

Merged
merged 7 commits into from
Feb 28, 2020

Conversation

jjnicola
Copy link
Member

Since the VTs are not in the ospd cache anymore, they are get from a a generator to be sent to the client.

The generator must be implemented in the wrapper and should return a single vt dictionary to be converted in xml format and to be sent to the client.
Therefore, get_vt_xml() does not receive a vt id anymore, but the vt dictionary.

Since the VTs are not in the ospd cache anymore, the are get from a
a generator. The generator must be implemented in the wrapper and should
return a single vt dictionary to be converted in xml format and to be sent
to the client. Therefore, get_vt_xml() does not receive a vt id anymore,
but the vt dictionary.
Copy link
Contributor

@bjoernricks bjoernricks left a comment

Choose a reason for hiding this comment

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

Looks good!

Currently - because I just had such an issue in gvm-libs - i am thinking about escaping our xml element in the xmlhelper class. I know we didn't do that in master too and currently we are only passing correct element names but maybe it is a good idea to already support this to always create valid xml.

ospd/ospd.py Outdated

responses.append(vts_xml)
for vt in self.get_vt_generator():
Copy link
Contributor

Choose a reason for hiding this comment

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

Personally I would call this iterator because a generator is a special (the most common type) iterator.

Suggested change
for vt in self.get_vt_generator():
for vt in self.get_vt_iterator():

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. Also, I implemented the iterator in the class, in case it was not implemented in the wrapper, and it still can get the VTs in case there is a vts dictionary already loaded.

@codecov
Copy link

codecov bot commented Feb 27, 2020

Codecov Report

Merging #215 into ospd-2.0 will decrease coverage by 0.15%.
The diff coverage is 73.23%.

Impacted file tree graph

@@             Coverage Diff              @@
##           ospd-2.0     #215      +/-   ##
============================================
- Coverage     68.22%   68.07%   -0.16%     
============================================
  Files            12       12              
  Lines          1835     1873      +38     
============================================
+ Hits           1252     1275      +23     
- Misses          583      598      +15
Impacted Files Coverage Δ
ospd/xml.py 75.47% <60.6%> (-24.53%) ⬇️
ospd/ospd.py 72.25% <84.21%> (-0.08%) ⬇️

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 626f5d1...268662b. Read the comment docs.

Rename the generator to get_vt_iterator()
The iterator get the vts from the dictionary, if no get_vt_iterator() was
implemented in the wrapper.
@jjnicola jjnicola marked this pull request as ready for review February 27, 2020 12:10
@jjnicola
Copy link
Member Author

Looks good!

Currently - because I just had such an issue in gvm-libs - i am thinking about escaping our xml element in the xmlhelper class. I know we didn't do that in master too and currently we are only passing correct element names but maybe it is a good idea to already support this to always create valid xml.

I agree with that, but I would like to do it with a different PR.

@bjoernricks
Copy link
Contributor

I agree with that, but I would like to do it with a different PR.

Of course!

Copy link
Contributor

@bjoernricks bjoernricks left a comment

Choose a reason for hiding this comment

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

Only the list(vts.keys())[0] should be resolved.

ospd/ospd.py Outdated

responses.append(vts_xml)
for vt in self.get_vt_iterator():
if list(vt.keys())[0] not in filtered_vts:
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't look got to me. I am really nor sure what this is supposed to do.

If I understand the code correctly it returns the first key of a dict as the vt_id which wont work for Python 3.5 if the dict contains several keys.

It would be better to expect a specific shape of a dict always having a vt_id key like {'vt_id': ..., }

ospd/ospd.py Outdated
return Element('vt')

vt = self.vts.get(vt_id)

vt_id = list(single_vt.keys())[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above this isn't readable and confused me.

@@ -1466,16 +1476,19 @@ def get_severities_vt_as_xml_str(
"""
return ''

def get_vt_xml(self, vt_id):
def get_vt_iterator(self):
for vt_id, val in self.vts.items():
Copy link
Contributor

Choose a reason for hiding this comment

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

Technically it would also be possible to just use

return self.vts.items()

or

return iter(self.vts.items())

here

@jjnicola jjnicola merged commit f57137a into greenbone:ospd-2.0 Feb 28, 2020
@jjnicola jjnicola deleted the no-cache branch February 28, 2020 11:30
@jjnicola jjnicola restored the no-cache branch March 2, 2020 08:46
jjnicola added a commit to jjnicola/ospd that referenced this pull request Mar 4, 2020
Send the VTs by chunk as response for get_vts
@jjnicola jjnicola deleted the no-cache branch June 24, 2020 10:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants