Skip to content

Commit

Permalink
feat: added warning if app already deployed
Browse files Browse the repository at this point in the history
  • Loading branch information
raaymax committed Jun 19, 2024
1 parent 67e7f31 commit b1188a7
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/writer/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit b1188a7

Please sign in to comment.