From 1a87b41140c575358fdb511a517e9c5003675332 Mon Sep 17 00:00:00 2001 From: Daniel Ziltener Date: Mon, 9 Dec 2019 13:55:29 +0100 Subject: [PATCH] File permissions --- src/com/sompani/onboarding.clj | 71 ++++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 25 deletions(-) diff --git a/src/com/sompani/onboarding.clj b/src/com/sompani/onboarding.clj index f905010..7b78ea5 100644 --- a/src/com/sompani/onboarding.clj +++ b/src/com/sompani/onboarding.clj @@ -10,37 +10,58 @@ :refer [log trace debug info warn error fatal report logf tracef debugf infof warnf errorf fatalf reportf spy get-env]]) - (:import (java.nio.file Files))) + (:import (java.nio.file Files + LinkOption) + (java.nio.file.attribute PosixFileAttributeView))) (def vault-client (vault/new-client "http://127.0.0.1:8200")) ;; # Webserver configuration +(defn- set-owner [path owner] + (-> + (Files/getFileAttributeView path PosixFileAttributeView LinkOption/NOFOLLOW_LINKS) + (.setOwner owner))) + +(defn- set-group [path group] + (-> + (Files/getFileAttributeView path PosixFileAttributeView LinkOption/NOFOLLOW_LINKS) + (.setGroup group))) + (defn make-dirs! [{:keys [company-name]}] - (doseq [dir-str ["/srv/http/staging.%s.talent.careers-cache" - "/srv/http/staging.%s.talent.careers-logs" - "/srv/http/staging.%s.talent.careers-sessions" - "/srv/http/staging.%s.talent.careers-uploads" - "/srv/http/staging.%s.talent.careers.1234" - "/srv/http/%s.talent.careers-cache" - "/srv/http/%s.talent.careers-logs" - "/srv/http/%s.talent.careers-sessions" - "/srv/http/%s.talent.careers-uploads" - "/srv/http/%s.talent.careers.1234"] - :let [dir (.toPath (io/file dir-str))]] - (Files/createDirectory dir nil) - ;; (sh/sh "install" "-o" "http" "-g" "http" "-d" (format dir company-name) :dir "/srv/http") - ) - (Files/createSymbolicLink (.toPath (io/file (format "/srv/http/staging.%s.talent.careers"))) - (.toPath (io/file (format "/srv/http/staging.%s.talent.careers-1234"))) - nil) - (Files/createSymbolicLink (.toPath (io/file (format "/srv/http/%s.talent.careers"))) - (.toPath (io/file (format "/srv/http/%s.talent.careers-1234"))) - nil) - - ;; (debug (sh/sh "ln" "-s" "staging.%s.talent.careers.1234" "staging.%s.talent.careers" :dir "/srv/http")) - ;; (debug (sh/sh "ln" "-s" "%s.talent.careers.1234" "%s.talent.careers" :dir "/srv/http")) - ) + (let [attrs (Files/readAttributes (.toPath (io/file "srv/http/www.sompani.com")) + PosixFileAttributeView + LinkOption/NOFOLLOW_LINKS) + group (.group attrs) + owner (.owner attrs)] + (doseq [dir-str ["/srv/http/staging.%s.talent.careers-cache" + "/srv/http/staging.%s.talent.careers-logs" + "/srv/http/staging.%s.talent.careers-sessions" + "/srv/http/staging.%s.talent.careers-uploads" + "/srv/http/staging.%s.talent.careers.1234" + "/srv/http/%s.talent.careers-cache" + "/srv/http/%s.talent.careers-logs" + "/srv/http/%s.talent.careers-sessions" + "/srv/http/%s.talent.careers-uploads" + "/srv/http/%s.talent.careers.1234"] + :let [dir (.toPath (io/file (format dir-str company-name)))]] + (Files/createDirectory dir nil) + (set-owner dir owner) + (set-group dir group) + ) + (let [link (.toPath (io/file (format "/srv/http/staging.%s.talent.careers" company-name)))] + (Files/createSymbolicLink link + (.toPath (io/file (format "/srv/http/staging.%s.talent.careers-1234" company-name))) + nil) + (set-owner link owner) + (set-group link group)) + + (let [link (.toPath (io/file (format "/srv/http/%s.talent.careers" company-name)))] + (Files/createSymbolicLink link + (.toPath (io/file (format "/srv/http/%s.talent.careers-1234" company-name))) + nil) + (set-owner link owner) + (set-group link group)))) (defn create-nginx-server! [datamap] (doseq [file ["resources/nginx/skel.talent.careers"