unitlab 2.3.40__py3-none-any.whl → 2.3.41__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,7 +14,7 @@ from fastapi import FastAPI
14
14
  import uvicorn
15
15
  import threading
16
16
  import psutil
17
-
17
+ import secrets
18
18
 
19
19
  api = FastAPI()
20
20
 
@@ -67,23 +67,23 @@ class PersistentTunnel:
67
67
  "Content-Type": "application/json"
68
68
  }
69
69
 
70
- def get_or_create_tunnel(self):
71
- """Always create a new tunnel with unique name to avoid conflicts"""
72
- # Generate unique tunnel name to avoid conflicts
73
- import uuid
74
- unique_suffix = str(uuid.uuid4())[:8]
75
- self.tunnel_name = "agent-{}-{}".format(self.device_id, unique_suffix)
76
- print("🔧 Creating tunnel: {}...".format(self.tunnel_name))
77
-
78
- # Always create new tunnel
79
- return self.create_new_tunnel()
80
-
70
+ # def get_or_create_tunnel(self):
71
+ # """Always create a new tunnel with unique name to avoid conflicts"""
72
+ # # Generate unique tunnel name to avoid conflicts
73
+ # import uuid
74
+ # unique_suffix = str(uuid.uuid4())[:8]
75
+ # self.tunnel_name = "agent-{}-{}".format(self.device_id, unique_suffix)
76
+ # print("🔧 Creating tunnel: {}...".format(self.tunnel_name))
77
+
78
+ # # Always create new tunnel
79
+ # return self.create_new_tunnel()
80
+
81
+
81
82
  def create_new_tunnel(self):
82
- """Create a brand new tunnel"""
83
+ """Create a new tunnel via Cloudflare API"""
83
84
  print("🔧 Creating new tunnel: {}...".format(self.tunnel_name))
84
85
 
85
86
  # Generate random tunnel secret (32 bytes)
86
- import secrets
87
87
  tunnel_secret = base64.b64encode(secrets.token_bytes(32)).decode()
88
88
 
89
89
  url = "https://api.cloudflare.com/client/v4/accounts/{}/cfd_tunnel".format(self.cf_account_id)
@@ -107,12 +107,13 @@ class PersistentTunnel:
107
107
  "TunnelID": self.tunnel_id
108
108
  }
109
109
 
110
- # Save credentials to file with tunnel name (not ID) for consistency
110
+ # Save credentials to file
111
111
  cred_file = "/tmp/tunnel-{}.json".format(self.tunnel_name)
112
112
  with open(cred_file, 'w') as f:
113
113
  json.dump(self.tunnel_credentials, f)
114
114
 
115
115
  print("✅ Tunnel created: {}".format(self.tunnel_id))
116
+ print("✅ Credentials saved to: {}".format(cred_file))
116
117
  return cred_file
117
118
  else:
118
119
  print("❌ Failed to create tunnel: {}".format(response.text))
@@ -440,7 +441,7 @@ class PersistentTunnel:
440
441
  # API credentials are hardcoded, so we're ready to go
441
442
 
442
443
  # 1. Get existing or create new tunnel via API
443
- cred_file = self.get_or_create_tunnel()
444
+ cred_file = self.create_new_tunnel()
444
445
 
445
446
 
446
447
  # 2. Create DNS record
@@ -490,6 +491,12 @@ class PersistentTunnel:
490
491
  self.jupyter_process.terminate()
491
492
  if self.tunnel_process:
492
493
  self.tunnel_process.terminate()
494
+ try:
495
+ self.tunnel_process.wait(timeout=5)
496
+ except subprocess.TimeoutExpired:
497
+ self.tunnel_process.kill()
498
+ self.tunnel_process.wait()
499
+ print("✅ Tunnel stopped")
493
500
 
494
501
  # # Optionally delete tunnel when stopping
495
502
  # if self.tunnel_id:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: unitlab
3
- Version: 2.3.40
3
+ Version: 2.3.41
4
4
  Home-page: https://github.com/teamunitlab/unitlab-sdk
5
5
  Author: Unitlab Inc.
6
6
  Author-email: team@unitlab.ai
@@ -3,11 +3,11 @@ unitlab/__main__.py,sha256=6Hs2PV7EYc5Tid4g4OtcLXhqVHiNYTGzSBdoOnW2HXA,29
3
3
  unitlab/client.py,sha256=wqREtDuYc5ixeloPEGm0hp1sdUtB59sB1bIJjBcO1y0,25983
4
4
  unitlab/exceptions.py,sha256=68Tr6LreEzjQ3Vns8HAaWdtewtkNUJOvPazbf6NSnXU,950
5
5
  unitlab/main.py,sha256=RbuCUaExvOEoA33T9O0hnr94R-L70RXyMjQshxRWR-o,4421
6
- unitlab/persistent_tunnel.py,sha256=NkXoTK3yn2mVN3hHoUqSQI-8ph_yfBU_YgEFumynyvo,22313
6
+ unitlab/persistent_tunnel.py,sha256=Ed_hRCsRT1I7UfpcAKfyVInNLfupk_hpgzFAz1GDUe8,22596
7
7
  unitlab/utils.py,sha256=9gPRu-d6pbhSoVdll1GXe4eoz_uFYOSbYArFDQdlUZs,1922
8
- unitlab-2.3.40.dist-info/licenses/LICENSE.md,sha256=Gn7RRvByorAcAaM-WbyUpsgi5ED1-bKFFshbWfYYz2Y,1069
9
- unitlab-2.3.40.dist-info/METADATA,sha256=Wy1EHazXknuZ_jJYBjcKB_iXOvP3X4Rtt0MEUeeSKwc,1046
10
- unitlab-2.3.40.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
- unitlab-2.3.40.dist-info/entry_points.txt,sha256=ig-PjKEqSCj3UTdyANgEi4tsAU84DyXdaOJ02NHX4bY,45
12
- unitlab-2.3.40.dist-info/top_level.txt,sha256=Al4ZlTYE3fTJK2o6YLCDMH5_DjuQkffRBMxgmWbKaqQ,8
13
- unitlab-2.3.40.dist-info/RECORD,,
8
+ unitlab-2.3.41.dist-info/licenses/LICENSE.md,sha256=Gn7RRvByorAcAaM-WbyUpsgi5ED1-bKFFshbWfYYz2Y,1069
9
+ unitlab-2.3.41.dist-info/METADATA,sha256=DIzDm3lxsOVqI1STlrGcDf7pZybOCrqnCCyJ1BNVMoU,1046
10
+ unitlab-2.3.41.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
+ unitlab-2.3.41.dist-info/entry_points.txt,sha256=ig-PjKEqSCj3UTdyANgEi4tsAU84DyXdaOJ02NHX4bY,45
12
+ unitlab-2.3.41.dist-info/top_level.txt,sha256=Al4ZlTYE3fTJK2o6YLCDMH5_DjuQkffRBMxgmWbKaqQ,8
13
+ unitlab-2.3.41.dist-info/RECORD,,