Skip to content

Commit

Permalink
Merge pull request #786 from greenbone/updates
Browse files Browse the repository at this point in the history
Updates
  • Loading branch information
bjoernricks authored Jul 27, 2022
2 parents 18304c2 + 395f855 commit c85fc5c
Show file tree
Hide file tree
Showing 481 changed files with 6,531 additions and 6,720 deletions.
Binary file modified docs/_static/greenbone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 35 additions & 35 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@
import os
import sys

sys.path.insert(0, os.path.abspath('..'))
sys.path.insert(0, os.path.abspath(".."))

import gvm

# -- Project information -----------------------------------------------------

project = 'python-gvm'
copyright = '2018 - 2022, Greenbone Networks GmbH'
author = 'Greenbone Networks GmbH'
project = "python-gvm"
copyright = "2018 - 2022, Greenbone Networks GmbH"
author = "Greenbone Networks GmbH"

# The short X.Y version

version = f'{gvm.__version__[0]}.{gvm.__version__[1]}'
version = f"{gvm.__version__[0]}.{gvm.__version__[1]}"
# The full version, including alpha/beta/rc tags
release = gvm.get_version()

Expand All @@ -44,23 +44,23 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.githubpages',
'sphinx.ext.napoleon',
'sphinx_autodoc_typehints',
"sphinx.ext.autodoc",
"sphinx.ext.githubpages",
"sphinx.ext.napoleon",
"sphinx_autodoc_typehints",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ".rst"

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand All @@ -72,7 +72,7 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['build']
exclude_patterns = ["build", "dist", ".venv"]

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = None
Expand All @@ -83,25 +83,25 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'
html_theme = "alabaster"

html_favicon = 'favicon.gif'
html_favicon = "favicon.png"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#
html_theme_options = {
'github_user': 'greenbone',
'github_repo': 'python-gvm',
'github_banner': True,
'show_powered_by': False,
"github_user": "greenbone",
"github_repo": "python-gvm",
"github_banner": True,
"show_powered_by": False,
}

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
Expand All @@ -113,11 +113,11 @@
#
# html_sidebars = {}
html_sidebars = {
'**': [
'sidebarlogo.html',
'localtoc.html',
'relations.html',
'searchbox.html',
"**": [
"sidebarlogo.html",
"localtoc.html",
"relations.html",
"searchbox.html",
]
}

Expand All @@ -127,7 +127,7 @@
# -- Options for HTMLHelp output ---------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = project + '-doc'
htmlhelp_basename = project + "-doc"


# -- Options for LaTeX output ------------------------------------------------
Expand All @@ -153,10 +153,10 @@
latex_documents = [
(
master_doc,
project + '.tex',
project + ' Documentation',
'Greenbone Networks GmbH',
'manual',
project + ".tex",
project + " Documentation",
"Greenbone Networks GmbH",
"manual",
)
]

Expand All @@ -165,7 +165,7 @@

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [(master_doc, project, project + ' Documentation', [author], 1)]
man_pages = [(master_doc, project, project + " Documentation", [author], 1)]


# -- Options for Texinfo output ----------------------------------------------
Expand All @@ -177,11 +177,11 @@
(
master_doc,
project,
project + ' Documentation',
project + " Documentation",
author,
project,
'One line description of project.',
'Miscellaneous',
"One line description of project.",
"Miscellaneous",
)
]

Expand All @@ -201,7 +201,7 @@
# epub_uid = ''

# A list of files that should not be packed into the epub file.
epub_exclude_files = ['search.html']
epub_exclude_files = ["search.html"]


# -- Extension configuration -------------------------------------------------
Binary file removed docs/favicon.gif
Binary file not shown.
Binary file added docs/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 18 additions & 22 deletions gvm/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,21 @@
Module for connections to GVM server daemons like gvmd and ospd.
"""
import base64
import errno
import hashlib
import logging
import socket as socketlib
import ssl
import sys
import time
import errno


from pathlib import Path
from typing import Optional, Union

import paramiko

from lxml import etree

from gvm.errors import GvmError


logger = logging.getLogger(__name__)

BUF_SIZE = 16 * 1024
Expand All @@ -48,7 +44,7 @@
DEFAULT_SSH_PORT = 22
DEFAULT_SSH_USERNAME = "gmp"
DEFAULT_SSH_PASSWORD = ""
DEFAULT_HOSTNAME = '127.0.0.1'
DEFAULT_HOSTNAME = "127.0.0.1"
DEFAULT_KNOWN_HOSTS_FILE = ".ssh/known_hosts"
MAX_SSH_DATA_LENGTH = 4095

Expand Down Expand Up @@ -237,32 +233,32 @@ def _ssh_authentication_input_loop(
sha64_fingerprint = base64.b64encode(
hashlib.sha256(base64.b64decode(key.get_base64())).digest()
).decode("utf-8")[:-1]
key_type = key.get_name().replace('ssh-', '').upper()
key_type = key.get_name().replace("ssh-", "").upper()
print(
f"The authenticity of host '{self.hostname}' can't "
"be established."
)
print(f"{key_type} key fingerprint is {sha64_fingerprint}.")
print('Are you sure you want to continue connecting (yes/no)? ', end='')
print("Are you sure you want to continue connecting (yes/no)? ", end="")
add = input()
while True:
if add == 'yes':
if add == "yes":
hostkeys.add(self.hostname, key.get_name(), key)
# ask user if the key should be added permanently
print(
f'Do you want to add {self.hostname} '
'to known_hosts (yes/no)? ',
end='',
f"Do you want to add {self.hostname} "
"to known_hosts (yes/no)? ",
end="",
)
save = input()
while True:
if save == 'yes':
if save == "yes":
try:
hostkeys.save(filename=self.known_hosts_file)
except OSError as e:
raise GvmError(
'Something went wrong with writing '
f'the known_hosts file: {e}'
"Something went wrong with writing "
f"the known_hosts file: {e}"
) from None
logger.info(
"Warning: Permanently added '%s' (%s) to "
Expand All @@ -271,7 +267,7 @@ def _ssh_authentication_input_loop(
key_type,
)
break
elif save == 'no':
elif save == "no":
logger.info(
"Warning: Host '%s' (%s) not added to "
"the list of known hosts.",
Expand All @@ -280,15 +276,15 @@ def _ssh_authentication_input_loop(
)
break
else:
print("Please type 'yes' or 'no': ", end='')
print("Please type 'yes' or 'no': ", end="")
save = input()
break
elif add == 'no':
elif add == "no":
return sys.exit(
'User denied key. Host key verification failed.'
"User denied key. Host key verification failed."
)
else:
print("Please type 'yes' or 'no': ", end='')
print("Please type 'yes' or 'no': ", end="")
add = input()

def _get_remote_host_key(self):
Expand Down Expand Up @@ -331,8 +327,8 @@ def _ssh_authentication(self) -> None:
except OSError as e:
if e.errno != errno.ENOENT:
raise GvmError(
'Something went wrong with reading '
f'the known_hosts file: {e}'
"Something went wrong with reading "
f"the known_hosts file: {e}"
) from None
hostkeys = self._socket.get_host_keys()
if not hostkeys.lookup(self.hostname):
Expand Down
4 changes: 2 additions & 2 deletions gvm/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(self, status: str = None, message: str = None):
self.status = status

def __str__(self):
return f'Server Error {self.status}. {self.message}'
return f"Server Error {self.status}. {self.message}"

def __repr__(self):
return (
Expand All @@ -87,7 +87,7 @@ def __init__(self, status: str = None, message: str = None):
self.status = status

def __str__(self):
return f'Response Error {self.status}. {self.message}'
return f"Response Error {self.status}. {self.message}"

def __repr__(self):
return (
Expand Down
2 changes: 1 addition & 1 deletion gvm/protocols/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from typing import Optional, Callable, Any
from typing import Any, Callable, Optional

from gvm.connections import GvmConnection

Expand Down
20 changes: 8 additions & 12 deletions gvm/protocols/gmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,14 @@
Module for communication with gvmd
"""
from types import TracebackType
from typing import Any, Optional, Callable, Union, Type
from typing import Any, Callable, Optional, Type, Union

from gvm.errors import GvmError

from gvm.protocols.base import GvmProtocol, GvmConnection

from gvm.protocols.base import GvmConnection, GvmProtocol
from gvm.protocols.gmpv208 import Gmp as Gmpv208
from gvm.protocols.gmpv214 import Gmp as Gmpv214
from gvm.protocols.gmpv224 import Gmp as Gmpv224

from gvm.transforms import EtreeCheckCommandTransform

from gvm.xml import XmlCommand

SUPPORTED_GMP_VERSIONS = Union[ # pylint: disable=invalid-name
Expand Down Expand Up @@ -86,11 +82,11 @@ def determine_remote_gmp_version(self) -> str:
resp = self._send_xml_command(XmlCommand("get_version"))
self.disconnect()

version_el = resp.find('version')
version_el = resp.find("version")
if version_el is None:
raise GvmError(
'Invalid response from manager daemon while requesting the '
'version information.'
"Invalid response from manager daemon while requesting the "
"version information."
)

return version_el.text
Expand All @@ -99,7 +95,7 @@ def determine_supported_gmp(self) -> SUPPORTED_GMP_VERSIONS:
"""Determine supported GMP version of the remote daemon and return a
corresponding Gmp class instance
"""
version_str = self.determine_remote_gmp_version().split('.', 1)
version_str = self.determine_remote_gmp_version().split(".", 1)
major_version = int(version_str[0])
minor_version = int(version_str[1])
if major_version == 20:
Expand All @@ -110,8 +106,8 @@ def determine_supported_gmp(self) -> SUPPORTED_GMP_VERSIONS:
gmp_class = Gmpv224
else:
raise GvmError(
'Remote manager daemon uses an unsupported version of GMP. '
f'The GMP version was {major_version}.{minor_version}'
"Remote manager daemon uses an unsupported version of GMP. "
f"The GMP version was {major_version}.{minor_version}"
)

return gmp_class(self._connection, transform=self._gmp_transform)
Expand Down
Loading

0 comments on commit c85fc5c

Please sign in to comment.