From eec9fcf7f0327ee3471185d995965c3ce8cce163 Mon Sep 17 00:00:00 2001 From: Devin Buhl Date: Sun, 21 Jan 2024 13:47:08 -0500 Subject: [PATCH] fix: update cloudflare validation Signed-off-by: Devin Buhl --- bootstrap/scripts/validation.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/bootstrap/scripts/validation.py b/bootstrap/scripts/validation.py index eba12ef3..57a35978 100644 --- a/bootstrap/scripts/validation.py +++ b/bootstrap/scripts/validation.py @@ -4,6 +4,7 @@ from shutil import which from typing import Callable, Optional from zoneinfo import available_timezones import CloudFlare +import json import netaddr import re import requests @@ -157,6 +158,14 @@ def validate_cloudflare(domain: str, token: str, account_tag: str, tunnel_secret raise ValueError(f"Cloudflare domain {domain} not found or token does not have access to it") except CloudFlare.exceptions.CloudFlareAPIError as e: raise ValueError(f"Cloudflare domain {domain} not found or token does not have access to it") from e + try: + request = requests.get(f"https://api.cloudflare.com/client/v4/accounts/{account_tag}/cfd_tunnel/{tunnel_id}", headers={"Authorization": f"Bearer {token}"}) + if request.status_code != 200: + raise ValueError(f"Cloudflare tunnel for {account_tag} not found or token does not have access to it") + if not json.loads(request.text)["success"]: + raise ValueError(f"Cloudflare tunnel for {account_tag} not found or token does not have access to it") + except requests.exceptions.RequestException as e: + raise ValueError(f"Cloudflare tunnel for {account_tag} not found or token does not have access to it") from e @required("bootstrap_dns_server") def validate_bootstrap_dns_server(dns_server: str, **_) -> None: