From f57f35fd7e7dae8f31dfc53621d92656ba005a19 Mon Sep 17 00:00:00 2001 From: "[Farbfox] Michael Schiller" Date: Thu, 30 Dec 2021 08:36:23 +0100 Subject: [PATCH] add missing getFloatingIP method --- dist/deploy/index.js | 31 +++++++++++++++++++++++++++++-- lib.js | 2 +- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/dist/deploy/index.js b/dist/deploy/index.js index 2a4f319..8c5c9c5 100644 --- a/dist/deploy/index.js +++ b/dist/deploy/index.js @@ -69,7 +69,7 @@ module.exports = /******/ (() => { imageIdentifier = imageId || options.image.name; core.info(`debug imageIdentifier: "${imageIdentifier}"`); - + res = await fetch(`${config.API}/servers`, { method: "POST", headers: { @@ -243,6 +243,33 @@ module.exports = /******/ (() => { return; } + async function getFloatingIP(id) { + const URI = `${config.API}/floating_ips/${id}`; + + try { + res = await fetch(URI, { + method: "GET", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${options.hcloudToken}`, + "User-Agent": config.USER_AGENT, + }, + }); + } catch (err) { + core.setFailed(err.message); + } + + if (res.status === 200) { + const body = await res.json(); + return body.floating_ip.ip; + } else { + core.setFailed( + `When trying to get a floating ip, an error occurred ${res.status}` + ); + return; + } + } + async function assignIP() { const floatingIPId = core.getInput("floating-ip-id"); if (!floatingIPId) { @@ -336,7 +363,7 @@ module.exports = /******/ (() => { assignIP, getAssignmentProgress, getImageId, - getFloatingIP, + getFloatingIP }; /***/ diff --git a/lib.js b/lib.js index 868b04c..b294ce5 100644 --- a/lib.js +++ b/lib.js @@ -326,5 +326,5 @@ module.exports = { assignIP, getAssignmentProgress, getImageId, - getFloatingIP, + getFloatingIP };