Skip to content
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
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ tag_prefix = v
parentdir_prefix = openziti-

[openziti]
ziti_sdk_version = 1.8.3
ziti_sdk_version = 1.9.1
14 changes: 8 additions & 6 deletions src/openziti/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,19 @@ def bind(self, service, terminator=None, sock=None):
return sock

@classmethod
def from_path(cls, path) -> tuple["ZitiContext", int]:
def from_path(cls, path, timeout=0) -> tuple["ZitiContext", int]:
"""
Load Ziti Identity

:param path: path to Ziti Identity file
:param timeout: timeout in milliseconds for loading identity
:return: ZitiContext representing given identity
"""
if not isinstance(path, str):
raise TypeError("path must be a string")
if not (isfile(path) or isdir(path)):
raise ValueError(f"{path} is not a valid path")
zh, err = zitilib.load(path)
zh, err = zitilib.load(path, timeout)
if err != 0:
logging.warning("Failed to load Ziti Identity from %s: %s", path, zitilib.errorstr(err))
return cls(zh), err
Expand All @@ -98,20 +99,21 @@ def wait_for_auth(self, timeout=60):
return zitilib.wait_for_auth(self._ctx, timeout)


def load_identity(path) -> tuple[ZitiContext, int]:
def load_identity(path, timeout=0) -> tuple[ZitiContext, int]:
"""
Load Ziti Identity

:param path: path to Ziti Identity file
:param timeout: timeout in milliseconds for loading identity
:return: Ziti Context object representing Ziti Identity
"""
return ZitiContext.from_path(path)
return ZitiContext.from_path(path, timeout)


def get_context(ztx) -> ZitiContext:
def get_context(ztx, timeout=0) -> ZitiContext:
if isinstance(ztx, ZitiContext):
return ztx
if isinstance(ztx, str):
z, _ = ZitiContext.from_path(ztx)
z, _ = ZitiContext.from_path(ztx, timeout)
return z
raise TypeError(f'{ztx} is not a ZitiContext or str instance')
7 changes: 4 additions & 3 deletions src/openziti/zitilib.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,11 @@ def __repr__(self):
_ziti_errorstr.argtypes = [ctypes.c_int]
_ziti_errorstr.restype = ctypes.c_char_p

_load_ctx = ziti.Ziti_load_context
_load_ctx = ziti.Ziti_load_context_with_timeout
_load_ctx.argtypes = [
ctypes.POINTER(ctypes.c_int32), # ziti context handle
ctypes.POINTER(ctypes.c_char), # ziti identity path or json
ctypes.c_int, # ziti timeout in ms
]
_load_ctx.restype = ctypes.c_int

Expand Down Expand Up @@ -270,12 +271,12 @@ def shutdown():
ziti.Ziti_lib_shutdown()


def load(path) -> tuple[int, int]:
def load(path, timeout=0) -> tuple[int, int]:
init()
b_obj = bytes(path, encoding="utf-8")
hp = ctypes.c_int32()

err = _load_ctx(ctypes.pointer(hp), b_obj)
err = _load_ctx(ctypes.pointer(hp), b_obj, ctypes.c_int(timeout))
return hp.value, err

def login_external(ziti_ctx: int, name: str) -> str:
Expand Down
2 changes: 1 addition & 1 deletion src/openziti/zitisock.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def bind(self, addr) -> None:
h, p = addr
cfg = self._ziti_bindings.get((h, int(p)))
if cfg is not None:
ztx = context.get_context(cfg['ztx'])
ztx = context.get_context(cfg['ztx'], timeout=cfg.get('timeout', 0))
service = cfg['service']
terminator = None
if isinstance(service, tuple):
Expand Down