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

Add: Auto-allow host for SSH connection #965

Merged
merged 3 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions gvmtools/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def __str__(self):
return "\n".join(row_strings)


def yes_or_no(question):
def yes_or_no(question: str) -> bool:
"""Asks the user to proceed or not in a gvmtools script

Arguments:
Expand All @@ -104,7 +104,7 @@ def yes_or_no(question):
return yes_or_no("Please enter 'y' or 'n'")


def error_and_exit(msg):
def error_and_exit(msg: str) -> None:
"""Prints an error message and quits the gvmtools script

Arguments:
Expand Down Expand Up @@ -200,7 +200,7 @@ def authenticate(gmp, username=None, password=None):
raise e


def run_script(path, global_vars):
def run_script(path, global_vars) -> None:
"""Loads and executes a file as a python script

Arguments:
Expand Down
11 changes: 10 additions & 1 deletion gvmtools/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import argparse
import logging
from pathlib import Path
from typing import Optional

from gvm import get_version as get_gvm_version
from gvm.connections import (
Expand All @@ -48,7 +49,7 @@

class CliParser:
def __init__(
self, description, logfilename, *, prog=None, ignore_config=False
self, description: str, logfilename, *, prog=None, ignore_config=False
):
bootstrap_parser = argparse.ArgumentParser(
prog=prog,
Expand Down Expand Up @@ -211,6 +212,12 @@ def _add_subparsers(self):
parser_ssh.add_argument(
"--ssh-password", help="SSH password (default: %(default)r)"
)
parser_ssh.add_argument(
"-A",
"--auto-accept-host",
action="store_true",
help="When executed in e.g. CI, auto accept SSH host addition",
)

parser_tls = self._subparsers.add_parser(
"tls", help="Use TLS secured connection to connect to service"
Expand Down Expand Up @@ -314,6 +321,7 @@ def create_connection(
cafile=None,
ssh_username=None,
ssh_password=None,
auto_accept_host: Optional[bool] = None,
**kwargs, # pylint: disable=unused-argument
):
if "socket" in connection_type:
Expand All @@ -335,4 +343,5 @@ def create_connection(
port=port,
username=ssh_username,
password=ssh_password,
auto_accept_host=auto_accept_host,
)
30 changes: 15 additions & 15 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion tests/ssh_help.3.10.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
usage: gvm-test-cli ssh [-h] [--hostname HOSTNAME] [--port PORT]
[--ssh-username SSH_USERNAME]
[--ssh-password SSH_PASSWORD]
[--ssh-password SSH_PASSWORD] [-A]

options:
-h, --help show this help message and exit
Expand All @@ -10,3 +10,6 @@ options:
SSH username (default: 'gmp')
--ssh-password SSH_PASSWORD
SSH password (default: 'gmp')
-A, --auto-accept-host
When executed in e.g. CI, auto accept SSH host
addition
5 changes: 4 additions & 1 deletion tests/ssh_help.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
usage: gvm-test-cli ssh [-h] [--hostname HOSTNAME] [--port PORT]
[--ssh-username SSH_USERNAME]
[--ssh-password SSH_PASSWORD]
[--ssh-password SSH_PASSWORD] [-A]

optional arguments:
-h, --help show this help message and exit
Expand All @@ -10,3 +10,6 @@ optional arguments:
SSH username (default: 'gmp')
--ssh-password SSH_PASSWORD
SSH password (default: 'gmp')
-A, --auto-accept-host
When executed in e.g. CI, auto accept SSH host
addition