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

Unify config params #240

Merged
merged 6 commits into from
Jan 10, 2020
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
156 changes: 82 additions & 74 deletions Pipfile.lock

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

18 changes: 13 additions & 5 deletions gvmtools/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@
import configparser
import logging

from gvm.connections import DEFAULT_UNIX_SOCKET_PATH, DEFAULT_GVM_PORT
from gvm.connections import (
DEFAULT_UNIX_SOCKET_PATH,
DEFAULT_GVM_PORT,
DEFAULT_SSH_PORT,
DEFAULT_HOSTNAME,
)

logger = logging.getLogger(__name__)

DEFAULT_SSH_PORT = 22


class Config:
def __init__(self):
Expand All @@ -37,10 +40,15 @@ def __init__(self):

self._config['gmp'] = dict(username='', password='')
self._config['ssh'] = dict(
username='gmp', password='gmp', port=DEFAULT_SSH_PORT
username='gmp',
password='gmp',
port=DEFAULT_SSH_PORT,
hostname=DEFAULT_HOSTNAME,
)
self._config['unixsocket'] = dict(socketpath=DEFAULT_UNIX_SOCKET_PATH)
self._config['tls'] = dict(port=DEFAULT_GVM_PORT)
self._config['tls'] = dict(
port=DEFAULT_GVM_PORT, hostname=DEFAULT_HOSTNAME
)

self._defaults = dict()

Expand Down
9 changes: 2 additions & 7 deletions gvmtools/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
PROTOCOL_OSP = 'OSP'
PROTOCOL_GMP = 'GMP'
DEFAULT_PROTOCOL = PROTOCOL_GMP
DEFAULT_HOSTNAME = '127.0.0.1'


class CliParser:
Expand Down Expand Up @@ -198,9 +197,7 @@ def _add_subparsers(self):
)

parser_ssh.add_argument(
'--hostname',
help='Hostname or IP address (default: %(default)s)',
default=DEFAULT_HOSTNAME,
'--hostname', help='Hostname or IP address (default: %(default)s)',
)
parser_ssh.add_argument(
'--port',
Expand All @@ -219,9 +216,7 @@ def _add_subparsers(self):
'tls', help='Use TLS secured connection to connect to service'
)
parser_tls.add_argument(
'--hostname',
help='Hostname or IP address (default: %(default)s)',
default=DEFAULT_HOSTNAME,
'--hostname', help='Hostname or IP address (default: %(default)s)',
)
parser_tls.add_argument(
'--port',
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
],
},
install_requires=[
'python-gvm',
'python-gvm>=1.2.0',
],
python_requires='>=3.5',
classifiers=[
Expand Down
6 changes: 3 additions & 3 deletions tests/ssh_help.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ usage: gvm-test-cli ssh [-h] [--hostname HOSTNAME] [--port PORT]
optional arguments:
-h, --help show this help message and exit
--hostname HOSTNAME Hostname or IP address (default: 127.0.0.1)
--port PORT SSH port (default: None)
--port PORT SSH port (default: 22)
--ssh-username SSH_USERNAME
SSH username (default: None)
SSH username (default: 'gmp')
--ssh-password SSH_PASSWORD
SSH password (default: None)
SSH password (default: 'gmp')
2 changes: 2 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,11 @@ def test_socket_help(self):
self.assert_snapshot('socket_help', help_output)

def test_ssh_help(self):
self.parser._set_defaults(None)
help_output = self.parser._parser_ssh.format_help()
self.assert_snapshot('ssh_help', help_output)

def test_tls_help(self):
self.parser._set_defaults(None)
help_output = self.parser._parser_tls.format_help()
self.assert_snapshot('tls_help', help_output)
2 changes: 1 addition & 1 deletion tests/tls_help.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ usage: gvm-test-cli tls [-h] [--hostname HOSTNAME] [--port PORT]
optional arguments:
-h, --help show this help message and exit
--hostname HOSTNAME Hostname or IP address (default: 127.0.0.1)
--port PORT GMP/OSP port (default: None)
--port PORT GMP/OSP port (default: 9390)
--certfile CERTFILE Path to the certificate file for client authentication.
(default: None)
--keyfile KEYFILE Path to key file for client authentication. (default:
Expand Down