From b1188a7679a099599638b134bd459899da88ee8c Mon Sep 17 00:00:00 2001 From: Mateusz Russak Date: Wed, 19 Jun 2024 15:26:50 +0200 Subject: [PATCH] feat: added warning if app already deployed --- src/writer/deploy.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/writer/deploy.py b/src/writer/deploy.py index 1f746328c..d09bdf654 100644 --- a/src/writer/deploy.py +++ b/src/writer/deploy.py @@ -15,6 +15,7 @@ WRITER_DEPLOY_URL = os.getenv("WRITER_DEPLOY_URL", "https://api.writer.com/v1/deployment/apps") def deploy(path, token, env): + check_app(token) tar = pack_project(path) upload_package(tar, token, env) @@ -90,6 +91,27 @@ def match(file_path) -> bool: return False return f + +def check_app(token): + url = get_app_url(token) + if url: + print("[WARNING] This token was already used to deploy a different app") + print(f"[WARNING] URL: {url}") + print("[WARNING] If looking to deploy to a different URL, use a different API key. ") + if input("[WARNING] Are you sure you want to overwrite? (y/N)").lower() != "y": + sys.exit(1) + +def get_app_url(token): + with requests.get(WRITER_DEPLOY_URL, params={"lineLimit": 1}, headers={"Authorization": f"Bearer {token}"}) as resp: + try: + resp.raise_for_status() + except Exception as e: + print(e) + print(resp.json()) + return None + data = resp.json() + return data['status']['url'] + def get_logs(token, params): with requests.get(WRITER_DEPLOY_URL, params = params, headers={"Authorization": f"Bearer {token}"}) as resp: try: