diff --git a/action.yml b/action.yml index 551434c..85a08b6 100644 --- a/action.yml +++ b/action.yml @@ -1,9 +1,6 @@ name: 'Hetzner Cloud API Action' description: 'Interact with the Hetzner Cloud API from a GitHub' inputs: - verbose: - description: 'Whether to output verbose logs' - required: false api-token: description: 'The Hetzner Cloud API token' required: true @@ -31,6 +28,9 @@ inputs: server-start-after-create: description: 'Whether to start the server after creating it' required: false + server-id: + description: 'The ID of the server to perform the action on' + required: false runs: using: 'node20' main: 'dist/index.js' diff --git a/dist/index.js b/dist/index.js index b1b663a..cd6580c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -26700,6 +26700,16 @@ class HetznerCloudApiClient { 'Content-Type': 'application/json', }); } + + /** + * Delete a server. + * + * @param {string} serverId - Server ID. + * @returns {Promise} - Promise representing the request. + */ + deleteServer(serverId) { + return this.#request('DELETE', `/servers/${serverId}`, null); + } } ;// CONCATENATED MODULE: ./src/hetzner-cloud.js @@ -26712,18 +26722,17 @@ class HetznerCloudApiClient { async function run() { try { const inputs = { - verbose: core.getInput('verbose') === 'true', apiToken: core.getInput('api-token'), action: core.getInput('action'), }; - const logger = (message, verboseMessage) => { - if (inputs.verbose) { - core.info(verboseMessage || message); - } else { - core.info(message); + const logger = (message, debugMessage) => { + core.info(message); + + if (debugMessage) { + core.debug(debugMessage); } - } + }; const client = new HetznerCloudApiClient(inputs.apiToken); @@ -26752,6 +26761,12 @@ async function run() { logger('Server created', JSON.stringify(await response.json())); } + if (inputs.action === 'delete-server') { + const serverId = core.getInput('server-id'); + logger(`Deleting server ${serverId} from Hetzner Cloud API...`); + const response = await client.deleteServer(serverId); + logger('Server deleted', JSON.stringify(await response.json())); + } } catch (error) { core.setFailed(error.message); } diff --git a/src/hetzner-api-client.js b/src/hetzner-api-client.js index a9554ac..b80e3d4 100644 --- a/src/hetzner-api-client.js +++ b/src/hetzner-api-client.js @@ -46,4 +46,14 @@ export class HetznerCloudApiClient { 'Content-Type': 'application/json', }); } + + /** + * Delete a server. + * + * @param {string} serverId - Server ID. + * @returns {Promise} - Promise representing the request. + */ + deleteServer(serverId) { + return this.#request('DELETE', `/servers/${serverId}`, null); + } } diff --git a/src/hetzner-cloud.js b/src/hetzner-cloud.js index 68c0f82..1ccea2d 100644 --- a/src/hetzner-cloud.js +++ b/src/hetzner-cloud.js @@ -7,18 +7,17 @@ import { HetznerCloudApiClient } from './hetzner-api-client.js'; export async function run() { try { const inputs = { - verbose: core.getInput('verbose') === 'true', apiToken: core.getInput('api-token'), action: core.getInput('action'), }; - const logger = (message, verboseMessage) => { - if (inputs.verbose) { - core.info(verboseMessage || message); - } else { - core.info(message); + const logger = (message, debugMessage) => { + core.info(message); + + if (debugMessage) { + core.debug(debugMessage); } - } + }; const client = new HetznerCloudApiClient(inputs.apiToken); @@ -47,6 +46,12 @@ export async function run() { logger('Server created', JSON.stringify(await response.json())); } + if (inputs.action === 'delete-server') { + const serverId = core.getInput('server-id'); + logger(`Deleting server ${serverId} from Hetzner Cloud API...`); + const response = await client.deleteServer(serverId); + logger('Server deleted', JSON.stringify(await response.json())); + } } catch (error) { core.setFailed(error.message); }