File permissions

This commit is contained in:
Daniel Ziltener 2019-12-09 13:55:29 +01:00
parent a4ebeaacae
commit 1a87b41140
1 changed files with 46 additions and 25 deletions

View File

@ -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"