Last active
October 21, 2021 11:33
-
-
Save dbalan/af0a587c433458d969d41499dd941147 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
!/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)))) |
This file contains hidden or 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
(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