From 778f60367092e92e1ba664aeeaca7e33683e9819 Mon Sep 17 00:00:00 2001 From: d10s <79284025+D10S0VSkY-OSS@users.noreply.github.com> Date: Sun, 19 Nov 2023 14:06:23 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5feat:=20add=20plan=20deploy=20butto?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sld-dashboard/app/home/routes.py | 42 +++++++++++++++++++ .../app/home/templates/deploys-list.html | 35 ++++++++-------- 2 files changed, 60 insertions(+), 17 deletions(-) diff --git a/sld-dashboard/app/home/routes.py b/sld-dashboard/app/home/routes.py index 37653ad8..289f192d 100644 --- a/sld-dashboard/app/home/routes.py +++ b/sld-dashboard/app/home/routes.py @@ -435,6 +435,48 @@ def get_plan(deploy_id): except ValueError: return redirect(url_for("base_blueprint.logout")) +@blueprint.route("/plan/redeploy/") +@login_required +def relaunch_plan(deploy_id): + try: + token = decrypt(r.get(current_user.id)) + # Check if token no expired + check_unauthorized_token(token) + endpoint = f"deploy/{deploy_id}" + + response = request_url( + verb="GET", uri=f"{endpoint}", headers={"Authorization": f"Bearer {token}"} + ) + content = response.get("json") + data = { + "start_time": content["start_time"], + "destroy_time": content["destroy_time"], + "stack_branch": content["stack_branch"], + "tfvar_file": content["tfvar_file"], + "project_path": content["project_path"], + "variables": content["variables"], + } + endpoint = f"plan/{deploy_id}" + response = request_url( + verb="PATCH", + uri=f"{endpoint}", + headers={"Authorization": f"Bearer {token}"}, + json=data, + ) + + if response.get("status_code") == 202: + flash(f"planning deploy") + else: + flash(response["json"]["detail"], "error") + return redirect( + url_for("home_blueprint.route_template", template="deploys-list") + ) + except TemplateNotFound: + return render_template("page-404.html"), 404 + except TypeError: + return redirect(url_for("base_blueprint.logout")) + except Exception: + return render_template("page-500.html"), 500 @blueprint.route( "/edit-schedule", methods=["GET", "POST"], defaults={"deploy_id": None} diff --git a/sld-dashboard/app/home/templates/deploys-list.html b/sld-dashboard/app/home/templates/deploys-list.html index a621f5d0..8fecd188 100644 --- a/sld-dashboard/app/home/templates/deploys-list.html +++ b/sld-dashboard/app/home/templates/deploys-list.html @@ -173,10 +173,12 @@

All Deploys

{% else %} - - + +