unitlab 2.3.16__py3-none-any.whl → 2.3.17__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.
- unitlab/cloudflare_api_tunnel.py +46 -23
- {unitlab-2.3.16.dist-info → unitlab-2.3.17.dist-info}/METADATA +1 -1
- {unitlab-2.3.16.dist-info → unitlab-2.3.17.dist-info}/RECORD +7 -7
- {unitlab-2.3.16.dist-info → unitlab-2.3.17.dist-info}/LICENSE.md +0 -0
- {unitlab-2.3.16.dist-info → unitlab-2.3.17.dist-info}/WHEEL +0 -0
- {unitlab-2.3.16.dist-info → unitlab-2.3.17.dist-info}/entry_points.txt +0 -0
- {unitlab-2.3.16.dist-info → unitlab-2.3.17.dist-info}/top_level.txt +0 -0
unitlab/cloudflare_api_tunnel.py
CHANGED
@@ -142,12 +142,12 @@ class CloudflareAPITunnel:
|
|
142
142
|
print(f"🔧 Configuring tunnel routes...")
|
143
143
|
|
144
144
|
# Get current tunnel config first
|
145
|
-
get_url = f"{self.api_base}/accounts/{self.account_id}/
|
145
|
+
get_url = f"{self.api_base}/accounts/{self.account_id}/tunnels/{self.tunnel_id}/configurations"
|
146
146
|
|
147
147
|
try:
|
148
148
|
# Get existing config
|
149
149
|
response = requests.get(get_url, headers=self.headers)
|
150
|
-
current_config = response.json()
|
150
|
+
current_config = response.json() if response.status_code == 200 else {}
|
151
151
|
|
152
152
|
# Build new ingress rules
|
153
153
|
new_ingress = [
|
@@ -190,7 +190,7 @@ class CloudflareAPITunnel:
|
|
190
190
|
}
|
191
191
|
}
|
192
192
|
|
193
|
-
put_url = f"{self.api_base}/accounts/{self.account_id}/
|
193
|
+
put_url = f"{self.api_base}/accounts/{self.account_id}/tunnels/{self.tunnel_id}/configurations"
|
194
194
|
response = requests.put(put_url, headers=self.headers, json=config_data)
|
195
195
|
|
196
196
|
if response.status_code == 200:
|
@@ -260,8 +260,13 @@ class CloudflareAPITunnel:
|
|
260
260
|
print(f"❌ Failed to create tunnel: {create_response.text}")
|
261
261
|
return None
|
262
262
|
else:
|
263
|
-
# Tunnel exists -
|
264
|
-
print(f"♻️
|
263
|
+
# Tunnel exists - but we need to ensure it can be used
|
264
|
+
print(f"♻️ Found existing tunnel, setting up for use")
|
265
|
+
|
266
|
+
# Store tunnel info for later use
|
267
|
+
existing_tunnel['needs_token'] = True # Mark that we'll need to use token
|
268
|
+
|
269
|
+
# Configure tunnel routes (creates config file)
|
265
270
|
self._configure_tunnel_routes(existing_tunnel['id'])
|
266
271
|
|
267
272
|
# Ensure DNS records exist
|
@@ -353,11 +358,6 @@ class CloudflareAPITunnel:
|
|
353
358
|
try:
|
354
359
|
print("🚀 Starting Cloudflare tunnel...")
|
355
360
|
|
356
|
-
# First, try to set up DNS and routes via API
|
357
|
-
if self.api_token:
|
358
|
-
self.create_dns_records()
|
359
|
-
self.update_tunnel_config()
|
360
|
-
|
361
361
|
# Ensure cloudflared is available
|
362
362
|
cloudflared_path = self._ensure_cloudflared()
|
363
363
|
if not cloudflared_path:
|
@@ -366,6 +366,12 @@ class CloudflareAPITunnel:
|
|
366
366
|
# Create or get existing tunnel for this device
|
367
367
|
device_tunnel = self.create_device_tunnel()
|
368
368
|
|
369
|
+
# Now set up DNS and routes via API after tunnel is created/found
|
370
|
+
if self.api_token and device_tunnel:
|
371
|
+
self.tunnel_id = device_tunnel['id'] # Ensure tunnel_id is set
|
372
|
+
self.create_dns_records()
|
373
|
+
self.update_tunnel_config()
|
374
|
+
|
369
375
|
if not device_tunnel:
|
370
376
|
print("❌ Could not create/find device tunnel")
|
371
377
|
# Fallback to shared tunnel if API fails
|
@@ -387,34 +393,51 @@ class CloudflareAPITunnel:
|
|
387
393
|
|
388
394
|
# Check if credentials file exists
|
389
395
|
creds_file = Path.home() / '.cloudflared' / f"{tunnel_id}.json"
|
396
|
+
config_file = Path.home() / '.cloudflared' / f'config-{tunnel_id}.yml'
|
397
|
+
cmd = None # Initialize cmd
|
390
398
|
|
391
|
-
if not creds_file.exists():
|
399
|
+
if not creds_file.exists() or device_tunnel.get('needs_token'):
|
392
400
|
# Try to recreate credentials from stored secret
|
393
401
|
if device_tunnel.get('tunnel_secret'):
|
394
402
|
self._save_tunnel_credentials(device_tunnel)
|
403
|
+
# Continue to use credentials below
|
395
404
|
else:
|
396
|
-
print("⚠️ No credentials
|
405
|
+
print("⚠️ No stored credentials, using tunnel token...")
|
397
406
|
# Get token for this tunnel
|
398
407
|
token_url = f"{self.api_base}/accounts/{self.account_id}/tunnels/{tunnel_id}/token"
|
399
408
|
token_response = requests.get(token_url, headers=self.headers)
|
400
409
|
if token_response.status_code == 200:
|
401
410
|
token = token_response.json()['result']
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
"
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
+
|
412
|
+
# Check if config file exists with ingress rules
|
413
|
+
if config_file.exists():
|
414
|
+
# Use token with config file for ingress rules
|
415
|
+
print(f" Using token with config file: {config_file}")
|
416
|
+
cmd = [
|
417
|
+
cloudflared_path,
|
418
|
+
"tunnel",
|
419
|
+
"--no-autoupdate",
|
420
|
+
"--config", str(config_file),
|
421
|
+
"run",
|
422
|
+
"--token", token
|
423
|
+
]
|
424
|
+
else:
|
425
|
+
# Use token directly
|
426
|
+
print(f" Using token directly (no config file)")
|
427
|
+
cmd = [
|
428
|
+
cloudflared_path,
|
429
|
+
"tunnel",
|
430
|
+
"--no-autoupdate",
|
431
|
+
"run",
|
432
|
+
"--token", token
|
433
|
+
]
|
411
434
|
else:
|
412
435
|
print("❌ Could not get tunnel token")
|
413
436
|
return None
|
414
437
|
|
415
|
-
if
|
438
|
+
# Only use credentials if we haven't already set cmd with token
|
439
|
+
if cmd is None and creds_file.exists():
|
416
440
|
# Check if config file exists
|
417
|
-
config_file = Path.home() / '.cloudflared' / f'config-{tunnel_id}.yml'
|
418
441
|
if config_file.exists():
|
419
442
|
# Run tunnel with config file (includes routes)
|
420
443
|
cmd = [
|
@@ -2,15 +2,15 @@ unitlab/__init__.py,sha256=Wtk5kQ_MTlxtd3mxJIn2qHVK5URrVcasMMPjD3BtrVM,214
|
|
2
2
|
unitlab/__main__.py,sha256=6Hs2PV7EYc5Tid4g4OtcLXhqVHiNYTGzSBdoOnW2HXA,29
|
3
3
|
unitlab/binary_manager.py,sha256=Q1v2Odm0hk_3g7jfDUJQfkjEbUbSjtuyo2JDUyWjDrk,5468
|
4
4
|
unitlab/client.py,sha256=V5fTgbprmMsnMwD_FPn7oZh0KK6hdnqB4BYuY4D-JRw,24558
|
5
|
-
unitlab/cloudflare_api_tunnel.py,sha256=
|
5
|
+
unitlab/cloudflare_api_tunnel.py,sha256=yVovEvLsjNFOv02pv9KU76Q8kZSf-IGe_G9ghkF2n64,25495
|
6
6
|
unitlab/exceptions.py,sha256=68Tr6LreEzjQ3Vns8HAaWdtewtkNUJOvPazbf6NSnXU,950
|
7
7
|
unitlab/main.py,sha256=7gPZ_2n90sxDnq9oGZVKOkuifr-k7w2Tq3ZIldAUE8I,5877
|
8
8
|
unitlab/tunnel_config.py,sha256=7CiAqasfg26YQfJYXapCBQPSoqw4jIx6yR64saybLLo,8312
|
9
9
|
unitlab/tunnel_service_token.py,sha256=ji96a4s4W2cFJrHZle0zBD85Ac_T862-gCKzBUomrxM,3125
|
10
10
|
unitlab/utils.py,sha256=83ekAxxfXecFTg76Z62BGDybC_skKJHYoLyawCD9wGM,1920
|
11
|
-
unitlab-2.3.
|
12
|
-
unitlab-2.3.
|
13
|
-
unitlab-2.3.
|
14
|
-
unitlab-2.3.
|
15
|
-
unitlab-2.3.
|
16
|
-
unitlab-2.3.
|
11
|
+
unitlab-2.3.17.dist-info/LICENSE.md,sha256=Gn7RRvByorAcAaM-WbyUpsgi5ED1-bKFFshbWfYYz2Y,1069
|
12
|
+
unitlab-2.3.17.dist-info/METADATA,sha256=vwinORqbWDCEvNcS-fekSwMoly9rnyhzcKK2OWdAYDA,844
|
13
|
+
unitlab-2.3.17.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
|
14
|
+
unitlab-2.3.17.dist-info/entry_points.txt,sha256=ig-PjKEqSCj3UTdyANgEi4tsAU84DyXdaOJ02NHX4bY,45
|
15
|
+
unitlab-2.3.17.dist-info/top_level.txt,sha256=Al4ZlTYE3fTJK2o6YLCDMH5_DjuQkffRBMxgmWbKaqQ,8
|
16
|
+
unitlab-2.3.17.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|