Skip to content

Commit e5e42b2

Browse files
authored
Merge pull request #88 from bdjilka/use_load_context_with_timeout
Use load context with timeout
2 parents d9a20c7 + 8f008ce commit e5e42b2

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ tag_prefix = v
3737
parentdir_prefix = openziti-
3838

3939
[openziti]
40-
ziti_sdk_version = 1.8.3
40+
ziti_sdk_version = 1.9.1

src/openziti/context.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,19 @@ def bind(self, service, terminator=None, sock=None):
6565
return sock
6666

6767
@classmethod
68-
def from_path(cls, path) -> tuple["ZitiContext", int]:
68+
def from_path(cls, path, timeout=0) -> tuple["ZitiContext", int]:
6969
"""
7070
Load Ziti Identity
7171
7272
:param path: path to Ziti Identity file
73+
:param timeout: timeout in milliseconds for loading identity
7374
:return: ZitiContext representing given identity
7475
"""
7576
if not isinstance(path, str):
7677
raise TypeError("path must be a string")
7778
if not (isfile(path) or isdir(path)):
7879
raise ValueError(f"{path} is not a valid path")
79-
zh, err = zitilib.load(path)
80+
zh, err = zitilib.load(path, timeout)
8081
if err != 0:
8182
logging.warning("Failed to load Ziti Identity from %s: %s", path, zitilib.errorstr(err))
8283
return cls(zh), err
@@ -98,20 +99,21 @@ def wait_for_auth(self, timeout=60):
9899
return zitilib.wait_for_auth(self._ctx, timeout)
99100

100101

101-
def load_identity(path) -> tuple[ZitiContext, int]:
102+
def load_identity(path, timeout=0) -> tuple[ZitiContext, int]:
102103
"""
103104
Load Ziti Identity
104105
105106
:param path: path to Ziti Identity file
107+
:param timeout: timeout in milliseconds for loading identity
106108
:return: Ziti Context object representing Ziti Identity
107109
"""
108-
return ZitiContext.from_path(path)
110+
return ZitiContext.from_path(path, timeout)
109111

110112

111-
def get_context(ztx) -> ZitiContext:
113+
def get_context(ztx, timeout=0) -> ZitiContext:
112114
if isinstance(ztx, ZitiContext):
113115
return ztx
114116
if isinstance(ztx, str):
115-
z, _ = ZitiContext.from_path(ztx)
117+
z, _ = ZitiContext.from_path(ztx, timeout)
116118
return z
117119
raise TypeError(f'{ztx} is not a ZitiContext or str instance')

src/openziti/zitilib.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,11 @@ def __repr__(self):
131131
_ziti_errorstr.argtypes = [ctypes.c_int]
132132
_ziti_errorstr.restype = ctypes.c_char_p
133133

134-
_load_ctx = ziti.Ziti_load_context
134+
_load_ctx = ziti.Ziti_load_context_with_timeout
135135
_load_ctx.argtypes = [
136136
ctypes.POINTER(ctypes.c_int32), # ziti context handle
137137
ctypes.POINTER(ctypes.c_char), # ziti identity path or json
138+
ctypes.c_int, # ziti timeout in ms
138139
]
139140
_load_ctx.restype = ctypes.c_int
140141

@@ -270,12 +271,12 @@ def shutdown():
270271
ziti.Ziti_lib_shutdown()
271272

272273

273-
def load(path) -> tuple[int, int]:
274+
def load(path, timeout=0) -> tuple[int, int]:
274275
init()
275276
b_obj = bytes(path, encoding="utf-8")
276277
hp = ctypes.c_int32()
277278

278-
err = _load_ctx(ctypes.pointer(hp), b_obj)
279+
err = _load_ctx(ctypes.pointer(hp), b_obj, ctypes.c_int(timeout))
279280
return hp.value, err
280281

281282
def login_external(ziti_ctx: int, name: str) -> str:

src/openziti/zitisock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def bind(self, addr) -> None:
9494
h, p = addr
9595
cfg = self._ziti_bindings.get((h, int(p)))
9696
if cfg is not None:
97-
ztx = context.get_context(cfg['ztx'])
97+
ztx = context.get_context(cfg['ztx'], timeout=cfg.get('timeout', 0))
9898
service = cfg['service']
9999
terminator = None
100100
if isinstance(service, tuple):

0 commit comments

Comments
 (0)