Skip to content

Instantly share code, notes, and snippets.

@dbalan
Last active October 21, 2021 11:33
Show Gist options
  • Select an option

  • Save dbalan/af0a587c433458d969d41499dd941147 to your computer and use it in GitHub Desktop.

Select an option

Save dbalan/af0a587c433458d969d41499dd941147 to your computer and use it in GitHub Desktop.

Revisions

  1. dbalan revised this gist Oct 21, 2021. 1 changed file with 21 additions and 0 deletions.
    21 changes: 21 additions & 0 deletions foo.clj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    (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))
  2. dbalan created this gist Oct 21, 2021.
    17 changes: 17 additions & 0 deletions check-stage-match.clj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    !/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))))