Skip to content

Client Module

This is the main thing you should be instantiating, it mixes in a bunch of other classes which make it a little easier to build the class.

pfSense API client

PFSenseAPIClient

Bases: FirewallMixin, ServiceMixin, StatusMixin, SystemMixin, BasePFSenseAPIClient

pfSense API Client

Source code in pfsense_api_client/__init__.py
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
class PFSenseAPIClient(
    FirewallMixin,
    ServiceMixin,
    StatusMixin,
    SystemMixin,
    BasePFSenseAPIClient,
    ):
    """pfSense API Client"""

    def request_access_token(self) -> requests.Response:
        """gets a temporary access token
        https://github.com/jaredhendrickson13/pfsense-api/blob/master/README.md#1-request-access-token
        """
        url = "/api/v1/access_token"
        return self.call(url=url, method="POST")

    def execute_shell_command(self, shell_cmd: str) -> requests.Response:
        """execute a shell command on the firewall
        https://github.com/jaredhendrickson13/pfsense-api/blob/master/README.md#1-execute-shell-command
        """
        url = "/api/v1/diagnostics/command_prompt"
        method = "POST"

        return self.call(
            url=url,
            method=method,
            payload={"shell_cmd": shell_cmd},
        )

execute_shell_command(shell_cmd)

execute a shell command on the firewall https://github.com/jaredhendrickson13/pfsense-api/blob/master/README.md#1-execute-shell-command

Source code in pfsense_api_client/__init__.py
43
44
45
46
47
48
49
50
51
52
53
54
def execute_shell_command(self, shell_cmd: str) -> requests.Response:
    """execute a shell command on the firewall
    https://github.com/jaredhendrickson13/pfsense-api/blob/master/README.md#1-execute-shell-command
    """
    url = "/api/v1/diagnostics/command_prompt"
    method = "POST"

    return self.call(
        url=url,
        method=method,
        payload={"shell_cmd": shell_cmd},
    )

request_access_token()

gets a temporary access token https://github.com/jaredhendrickson13/pfsense-api/blob/master/README.md#1-request-access-token

Source code in pfsense_api_client/__init__.py
36
37
38
39
40
41
def request_access_token(self) -> requests.Response:
    """gets a temporary access token
    https://github.com/jaredhendrickson13/pfsense-api/blob/master/README.md#1-request-access-token
    """
    url = "/api/v1/access_token"
    return self.call(url=url, method="POST")