Skip to content

Instantly share code, notes, and snippets.

@hhutch
Created January 16, 2012 21:19
Show Gist options
  • Save hhutch/1623097 to your computer and use it in GitHub Desktop.
Save hhutch/1623097 to your computer and use it in GitHub Desktop.
example of using the default override in Pallet's automated-admin-user crate
;(require '[pallet.crate.automated-admin-user :as automated-admin-user])
;; ## Set Admin User with Assumptions(tm)
;; * assume that /home/USERNAME/.pallet exists
;; * keyfiles of the format ADMIN-USER_rsa and ADMIN-USER_rsa.pub are put in /home/USERNAME/.pallet
(defn set-admin-user
[admin-user]
(let [home-pallet-dir "/home/USERNAME/.pallet"]
(core/admin-user admin-user
:private-key-path (str home-pallet-dir "/" admin-user "_rsa")
:public-key-path (str home-pallet-dir "/" admin-user "_rsa.pub"))))
;; *admin-user* is a global VAR that the automated-admin-user crate will use by default if it is set
(def *admin-user* (set-admin-user "myadmin"))
;; this is pretty standard, just call automated-admin-user without any parameters in your bootstrap
(def with-webserver
(core/server-spec
:phases { :bootstrap (phase/phase-fn (automated-admin-user/automated-admin-user ))
:configure (phase/phase-fn (web-server-config)) }))
;; Instead of manually setting home-pallet-dir above, you could call this instead
(defn local-pallet-dir
"Get the .pallet dir of the user currently running pallet"
[]
(.getAbsolutePath
(doto (if-let [pallet-home (System/getenv "PALLET_HOME")]
(java.io.File. pallet-home)
(java.io.File. (System/getProperty "user.home") ".pallet"))
.mkdirs)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment