Skip to content

Commit

Permalink
Merge pull request #11 from jaredhendrickson13/fix_error_regression
Browse files Browse the repository at this point in the history
v2.1.0 Fixes & Features
  • Loading branch information
jaredhendrickson13 authored Jan 25, 2023
2 parents 940643a + 9709679 commit 6956ff4
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ jobs:
pip install .
- name: Analysing the code with pylint
run: |
pylint $(git ls-files '*.py')
pylint $(git ls-files '*.py') scripts/pfsense-vshell
42 changes: 0 additions & 42 deletions .github/workflows/test-pypi.yml

This file was deleted.

3 changes: 2 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ disable=raw-checker-failed,
suppressed-message,
useless-suppression,
deprecated-pragma,
use-symbolic-message-instead
use-symbolic-message-instead,
invalid-name

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ To uninstall:<br>

## Usage & Syntax
```
usage: pfsense-vshell [-h] --host HOST [--virtual_shell] [--command COMMAND] --username USERNAME --password PASSWORD [--scheme {http,https}] [--port PORT] [--timeout TIMEOUT] [--shell_timeout SHELL_TIMEOUT] [--no_verify] [--version] [--verbose]
usage: pfsense-vshell [-h] --host HOST [--virtual_shell] [--command COMMAND] --username USERNAME [--password PASSWORD] [--scheme {http,https}] [--port PORT] [--timeout TIMEOUT] [--shell_timeout SHELL_TIMEOUT] [--no_verify] [--version] [--verbose]
```

| Command | Shorthand | Required | Description | Example Usage |
Expand All @@ -31,7 +31,7 @@ usage: pfsense-vshell [-h] --host HOST [--virtual_shell] [--command COMMAND] --u
| --help | -h | No | Display the help page | --help |
| --version | -V | No | Display the current version | --version |
| --username | -u | Yes (except with --help or --version) | Set the username to login with | --username USERNAME |
| --password | -p | Yes (except with --help or --version) | Set the password to login with | --password PASSWORD |
| --password | -p | No | Set the password to login with. User will be prompted for a password if unspecified. | --password PASSWORD |
| --port | -P | No | Set the TCP port of pfSense's webConfigurator | --port PORT |
| --scheme | -w | No | Set the HTTP protocol scheme. `http` or `https` | --scheme SCHEME |
| --no_verify | -k | No | Disable SSL certificate verification | --no_verify |
Expand Down
15 changes: 12 additions & 3 deletions pfsense_vshell/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Defines the client object used to establish virtual pfSense shell connections."""
__version__ = "2.0.4"
__version__ = "2.1.0"

import datetime
import html
Expand Down Expand Up @@ -266,5 +266,14 @@ def __log__(self, event, msg):
self.log.append(",".join([str(datetime.datetime.utcnow()), self.url(), self.username, event, msg]))


class PFError(BaseException):
"""Error object used by the PFVShell class"""
class PFError(Exception):
"""
Error object used by the PFVShell class
"""
code = 1
message = "an unknown error has occurred"

def __init__(self, code, message):
self.code = code
self.message = message
super().__init__()
18 changes: 14 additions & 4 deletions scripts/pfsense-vshell
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""The command line interface for pfsense-vshell."""

# IMPORT MODULES #
import argparse
import sys
import time
import getpass
import pfsense_vshell
import pkg_resources


class PFCLI:
"""Class containing all methods necessary for CLI functionality."""
def __init__(self):
"""
Initializes the object at creation by converting arguments intto our PFClient object and running our CLI
Expand Down Expand Up @@ -165,6 +167,8 @@ class PFCLI:
Sets criteria for arguments and parses them into our args property
:return: (none) args property will be populated after running
"""
# Expressions can be better understood in this context as 'False if expression else True'
# pylint: disable=simplifiable-if-expression

def port(value_string):
"""
Expand All @@ -176,7 +180,7 @@ class PFCLI:

value = int(value_string)
if value not in range(1, 65535):
raise argparse.ArgumentTypeError("%s is out of range, choose from [1-65535]" % value)
raise argparse.ArgumentTypeError(f"{value} is out of range, choose from [1-65535]")
return value

def timeout(value_string):
Expand All @@ -189,7 +193,7 @@ class PFCLI:

value = int(value_string)
if value not in range(0, 120):
raise argparse.ArgumentTypeError("%s is out of range, choose from [0-120]" % value)
raise argparse.ArgumentTypeError(f"{value} is out of range, choose from [0-120]")
return value

# Setup parser and define arguments
Expand Down Expand Up @@ -222,7 +226,8 @@ class PFCLI:
parser.add_argument(
'--password', "-p",
dest="password",
required=False if "--version" in sys.argv or "-V" in sys.argv else True,
required=False,
default=None,
help='Set the password to use when authenticating',
)
parser.add_argument(
Expand Down Expand Up @@ -272,8 +277,13 @@ class PFCLI:
help="Print verbose data"
)

# Parse the arguments
self.args = parser.parse_args()

# Prompt for a password if one was not specified and the version flag was not used
if self.args.password is None and not self.args.version:
self.args.password = getpass.getpass(f"Enter pfSense password for '{self.args.username}': ")


# RUNTIME
# Run the CLI, allow user to trigger KeyboardInterrupt (ctl + c) or EOFError (ctl + d) to safely exit the script
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ def get_readme():
scripts=['scripts/pfsense-vshell'],
packages=["pfsense_vshell"],
install_requires=[
"requests~=2.28.1",
"urllib3~=1.26.10",
"pylint~=2.14.5"
"requests>=2.28.1",
"urllib3>=1.26.10",
"pylint>=2.14.5"
],
classifiers=[
"Programming Language :: Python :: 3",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_vshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def test_log(self):
def test_pferror_class(self):
"""Tests the PFError exception class."""
with self.assertRaises(pfsense_vshell.PFError):
raise pfsense_vshell.PFError
raise pfsense_vshell.PFError(1, "Test error message")


if __name__ == '__main__':
Expand Down

0 comments on commit 6956ff4

Please sign in to comment.