Skip to content

Commit

Permalink
private_methods
Browse files Browse the repository at this point in the history
  • Loading branch information
themylogin committed Dec 9, 2024
1 parent 66b567c commit 10a4111
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
19 changes: 13 additions & 6 deletions truenas_api_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,16 @@
class Client:
"""Implicit wrapper of either a `JSONRPCClient` or a `LegacyClient`."""

def __init__(self, uri: str | None=None, reserved_ports=False, py_exceptions=False, log_py_exceptions=False,
call_timeout: float | UndefinedType=undefined, verify_ssl=True):
def __init__(self, uri: str | None=None, reserved_ports=False, private_methods=False, py_exceptions=False,
log_py_exceptions=False, call_timeout: float | UndefinedType=undefined, verify_ssl=True):
"""Initialize either a `JSONRPCClient` or a `LegacyClient`.
Use `JSONRPCClient` unless `uri` ends with '/websocket'.
Args:
uri: The address to connect to. Defaults to the local middlewared socket.
reserved_ports: `True` if the local socket should use a reserved port.
private_methods: `True` if calling private methods should be allowed
py_exceptions: `True` if the server should include exception objects in
`message['error']['data']['py_exception']`.
log_py_exceptions: `True` if exception tracebacks from API calls should be logged.
Expand All @@ -90,7 +91,8 @@ def __init__(self, uri: str | None=None, reserved_ports=False, py_exceptions=Fal
else:
client_class = JSONRPCClient

self.__client = client_class(uri, reserved_ports, py_exceptions, log_py_exceptions, call_timeout, verify_ssl)
self.__client = client_class(uri, reserved_ports, private_methods, py_exceptions, log_py_exceptions,
call_timeout, verify_ssl)

def __getattr__(self, item):
return getattr(self.__client, item)
Expand Down Expand Up @@ -397,13 +399,14 @@ class JSONRPCClient:
Keeps track of the calls made, jobs submitted, and callbacks. Maintains a websocket connection using a `WSClient`.
"""
def __init__(self, uri: str | None=None, reserved_ports=False, py_exceptions=False, log_py_exceptions=False,
call_timeout: float | UndefinedType=undefined, verify_ssl=True):
def __init__(self, uri: str | None = None, reserved_ports=False, private_methods=False, py_exceptions=False,
log_py_exceptions=False, call_timeout: float | UndefinedType = undefined, verify_ssl=True):
"""Initialize a `JSONRPCClient`.
Args:
uri: The address to connect to. Defaults to the local middlewared socket.
reserved_ports: `True` if the local socket should use a reserved port.
private_methods: `True` if calling private methods should be allowed
py_exceptions: `True` if the server should include exception objects in
`message['error']['data']['py_exception']`.
log_py_exceptions: `True` if exception tracebacks from API calls should be logged.
Expand All @@ -425,6 +428,7 @@ def __init__(self, uri: str | None=None, reserved_ports=False, py_exceptions=Fal
self._jobs: defaultdict[str, _JobDict] = defaultdict(dict) # type: ignore
self._jobs_lock = Lock()
self._jobs_watching = False
self._private_methods = private_methods
self._py_exceptions = py_exceptions
self._log_py_exceptions = log_py_exceptions
self._call_timeout = call_timeout
Expand Down Expand Up @@ -583,7 +587,10 @@ def _run_callback(self, event: _Payload, args: Iterable[str], kwargs: Collection

def on_open(self):
"""Make an API call to `core.set_options` to configure how middlewared sends its responses."""
self._set_options_call = self.call("core.set_options", {"py_exceptions": self._py_exceptions}, background=True)
self._set_options_call = self.call("core.set_options", {
"private_methods": self._private_methods,
"py_exceptions": self._py_exceptions,
}, background=True)

def on_close(self, code: int, reason: str | None=None):
"""Close this `JSONRPCClient` in response to the `WebSocketApp` closing.
Expand Down
4 changes: 2 additions & 2 deletions truenas_api_client/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ def result(self):


class LegacyClient:
def __init__(self, uri=None, reserved_ports=False, py_exceptions=False, log_py_exceptions=False,
call_timeout: float | UndefinedType=undefined, verify_ssl=True):
def __init__(self, uri=None, reserved_ports=False, private_methods=False, py_exceptions=False,
log_py_exceptions=False, call_timeout: float | UndefinedType=undefined, verify_ssl=True):
"""
Arguments:
:reserved_ports(bool): should the local socket used a reserved port
Expand Down

0 comments on commit 10a4111

Please sign in to comment.