Skip to content

Instantly share code, notes, and snippets.

@dbalan
Last active October 21, 2021 11:33
Show Gist options
  • Save dbalan/af0a587c433458d969d41499dd941147 to your computer and use it in GitHub Desktop.
Save dbalan/af0a587c433458d969d41499dd941147 to your computer and use it in GitHub Desktop.
!/usr/bin/env bb
(require '[clojure.java.shell :refer [sh]])
(def expected (get (System/getenv "STAGE")
{ "dev" "12345"
"prod" "123456"}))
(def curr-account
((json/parse-string
((sh "aws" "sts" "get-caller-identity") :out) true) :Account))
(if (= expected curr-account)
(println "stage matches account")
((fn [] (println (format "error: wrong stage for account %s" curr-account))
(System/exit -1))))
(require '[babashka.process :as p]
'[cheshire.core :as json])
(defn main
[]
(let [accounts {"dev" "12345"
"prod" "123456"}
expected (get (System/getenv "STAGE") accounts)
curr-account (-> (p/sh "aws sts get-caller-identity")
p/check ; aborts if non-zero exit
:out
(json/parse-string true)
:Account)]
(if (= expected curr-account)
(println "stage matches account")
(do
(println (str "error: wrong stage for account " curr-account))
(System/exit -1)))))
(when (= *file* (System/getProperty "babashka.file")) ; same as python's if __name__ == "__main__"
(main))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment