| Conditions | 1 |
| Total Lines | 99 |
| Code Lines | 69 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | # -*- coding: utf-8 -*- |
||
| 170 | def _add_subparsers(self): |
||
| 171 | parser_ssh = self._subparsers.add_parser( |
||
| 172 | 'ssh', |
||
| 173 | help='Use SSH to connect to service', |
||
| 174 | # parents=[self._root_parser], |
||
| 175 | ) |
||
| 176 | |||
| 177 | parser_ssh.add_argument( |
||
| 178 | '--hostname', required=True, help='Hostname or IP address' |
||
| 179 | ) |
||
| 180 | parser_ssh.add_argument( |
||
| 181 | '--port', |
||
| 182 | required=False, |
||
| 183 | help='SSH port (default: %(default)s)', |
||
| 184 | type=int, |
||
| 185 | ) |
||
| 186 | parser_ssh.add_argument( |
||
| 187 | '--ssh-username', help='SSH username (default: %(default)r)' |
||
| 188 | ) |
||
| 189 | parser_ssh.add_argument( |
||
| 190 | '--ssh-password', help='SSH password (default: %(default)r)' |
||
| 191 | ) |
||
| 192 | |||
| 193 | parser_ssh.set_defaults( |
||
| 194 | port=int(self._config.get('ssh', 'port', fallback=22)), |
||
| 195 | ssh_username=self._config.get('ssh', 'username', fallback='gmp'), |
||
| 196 | ssh_password=self._config.get('ssh', 'password', fallback='gmp'), |
||
| 197 | ) |
||
| 198 | |||
| 199 | parser_tls = self._subparsers.add_parser( |
||
| 200 | 'tls', |
||
| 201 | help='Use TLS secured connection to connect to service', |
||
| 202 | # parents=[self._root_parser], |
||
| 203 | ) |
||
| 204 | parser_tls.add_argument( |
||
| 205 | '--hostname', required=True, help='Hostname or IP address' |
||
| 206 | ) |
||
| 207 | parser_tls.add_argument( |
||
| 208 | '--port', |
||
| 209 | required=False, |
||
| 210 | help='GMP/OSP port (default: %(default)s)', |
||
| 211 | type=int, |
||
| 212 | ) |
||
| 213 | parser_tls.add_argument( |
||
| 214 | '--certfile', |
||
| 215 | required=False, |
||
| 216 | help='Path to the certificate file for client authentication. ' |
||
| 217 | '(default: %(default)s)', |
||
| 218 | ) |
||
| 219 | parser_tls.add_argument( |
||
| 220 | '--keyfile', |
||
| 221 | required=False, |
||
| 222 | help='Path to key file for client authentication. ' |
||
| 223 | '(default: %(default)s)', |
||
| 224 | ) |
||
| 225 | parser_tls.add_argument( |
||
| 226 | '--cafile', |
||
| 227 | required=False, |
||
| 228 | help='Path to CA certificate for server authentication. ' |
||
| 229 | '(default: %(default)s)', |
||
| 230 | ) |
||
| 231 | parser_tls.add_argument( |
||
| 232 | '--no-credentials', |
||
| 233 | required=False, |
||
| 234 | default=False, |
||
| 235 | action='store_true', |
||
| 236 | help='Use only certificates for authentication', |
||
| 237 | ) |
||
| 238 | parser_tls.set_defaults( |
||
| 239 | port=int( |
||
| 240 | self._config.get('tls', 'port', fallback=DEFAULT_GVM_PORT) |
||
| 241 | ), |
||
| 242 | certfile=self._config.get('tls', 'certfile', fallback=None), |
||
| 243 | keyfile=self._config.get('tls', 'keyfile', fallback=None), |
||
| 244 | cafile=self._config.get('tls', 'cafile', fallback=None), |
||
| 245 | ) |
||
| 246 | |||
| 247 | parser_socket = self._subparsers.add_parser( |
||
| 248 | 'socket', |
||
| 249 | help='Use UNIX Domain socket to connect to service', |
||
| 250 | # parents=[self._root_parser], |
||
| 251 | ) |
||
| 252 | |||
| 253 | socketpath_group = parser_socket.add_mutually_exclusive_group() |
||
| 254 | socketpath_group.add_argument( |
||
| 255 | '--sockpath', |
||
| 256 | nargs='?', |
||
| 257 | default=None, |
||
| 258 | help='Deprecated, use --socketpath instead', |
||
| 259 | ) |
||
| 260 | socketpath_group.add_argument( |
||
| 261 | '--socketpath', |
||
| 262 | nargs='?', |
||
| 263 | help='Path to UNIX Domain socket (default: %(default)s)', |
||
| 264 | ) |
||
| 265 | |||
| 266 | parser_socket.set_defaults( |
||
| 267 | socketpath=self._config.get( |
||
| 268 | 'unixsocket', 'socketpath', fallback=DEFAULT_UNIX_SOCKET_PATH |
||
| 269 | ) |
||
| 319 |