-
-
Save leifericf/2574d715a938b9fb0e98418ba4d77f36 to your computer and use it in GitHub Desktop.
Fetch Pulumi Stack data for an organization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{:paths ["src"] | |
:deps {http-kit/http-kit {:mvn/version "2.8.0-beta3"} | |
version-clj/version-clj {:mvn/version "2.0.2"}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Docs: https://www.pulumi.com/docs/pulumi-cloud/cloud-rest-api/#list-stacks | |
(ns pulumi | |
(:require [cheshire.core :as json] | |
[org.httpkit.client :as http-kit])) | |
(def pulumi-uri "https://api.pulumi.com") | |
; These environment variables must be set in your .bashrc or .zshrc | |
(def pulumi-access-token (System/getenv "PULUMI_ACCESS_TOKEN")) | |
(def pulumi-org (System/getenv "PULUMI_ORG")) | |
(def base-headers | |
{"Accept" "application/vnd.pulumi+8" | |
"Content-Type" "application/json" | |
"Authorization" (str "token " pulumi-access-token)}) | |
(defn fetch-stacks [request callback] | |
(http-kit/request (assoc request | |
:url (str pulumi-uri "/api/user/stacks") | |
:method :get) | |
callback)) | |
(def base-request | |
{:headers base-headers | |
:query-params {:organization pulumi-org}}) | |
(defn response-body->json [response] | |
(-> (:body response) | |
json/parse-string)) | |
(defn get-stack-names [stacks] | |
(for [stacks (get @stacks "stacks")] | |
(get-in stacks ["stackName"]))) | |
(comment | |
; Fetch all Stacks from Pulumi's API. | |
(def stacks (fetch-stacks base-request response-body->json)) | |
; Check if the response contains a continuation token. | |
(get @stacks "continuationToken") | |
; Which stack names did we get? | |
(-> stacks | |
get-stack-names | |
sort) | |
; How many stack names did we get? | |
(-> stacks | |
get-stack-names | |
count) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Like this?