Skip to content

Instantly share code, notes, and snippets.

@joshuaquek
Created November 18, 2022 05:49
Show Gist options
  • Select an option

  • Save joshuaquek/18a3c0b42da28f750c36a1283ae4bccc to your computer and use it in GitHub Desktop.

Select an option

Save joshuaquek/18a3c0b42da28f750c36a1283ae4bccc to your computer and use it in GitHub Desktop.

Revisions

  1. joshuaquek revised this gist Nov 18, 2022. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion delete_all_deployments.js
    Original file line number Diff line number Diff line change
    @@ -39,4 +39,5 @@ async function deleteSearchAndStreamDeployments () {
    }
    }

    deleteSearchAndStreamDeployments()
    deleteSearchAndStreamDeployments()

  2. joshuaquek created this gist Nov 18, 2022.
    1 change: 1 addition & 0 deletions .Search_And_Stream_Delete_All_Deployments
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    Description: Deletes all deployment in case the CTQ bash script somehow fails
    42 changes: 42 additions & 0 deletions delete_all_deployments.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    // Run this on NodeJS

    const axios = require('axios')

    async function deleteSearchAndStreamDeployments () {
    const API_KEY = 'YOUR ELASTIC CLOUD API KEY GOES HERE'
    let deployments = []
    try {
    // Get all deployments from the Elastic Cloud Account
    const response = await axios({
    method: 'GET',
    url: 'https://api.elastic-cloud.com/api/v1/deployments',
    headers: { Authorization: `ApiKey ${API_KEY}` },
    data: {}
    })
    deployments = response.data.deployments
    console.log('>>> deployments', deployments)
    } catch (error) {
    console.log(error.data)
    }

    for (const deployment of deployments) {
    if (deployment.name.includes('capture-the-query')) {
    const deploymentId = deployment.id
    try {
    // Wipe all deployments with "capture-the-query" in the name
    const response = await axios({
    method: 'POST',
    url: `https://api.elastic-cloud.com/api/v1/deployments/${deploymentId}/_shutdown`,
    headers: { Authorization: `ApiKey ${API_KEY}` },
    data: {}
    })
    console.log('>>> Response: ', response.data)
    } catch (error) {
    console.log(error.data)
    }
    // Done, script will exit
    }
    }
    }

    deleteSearchAndStreamDeployments()