mirror of
https://codeberg.org/puppe/secrets.git
synced 2025-12-20 00:42:17 +01:00
Change interpretation of paths in config file
The paths are now interpreted relatively to the location of the config file.
This commit is contained in:
parent
fad70955eb
commit
2ea10580b9
1 changed files with 17 additions and 9 deletions
26
secrets
26
secrets
|
|
@ -28,10 +28,14 @@
|
||||||
[(group) string?]
|
[(group) string?]
|
||||||
[(mode) string?])])))
|
[(mode) string?])])))
|
||||||
|
|
||||||
(define/contract (make-file file-config)
|
(define/contract (make-file file-config source-basedir)
|
||||||
(-> (or/c string? file-contract) secret-file?)
|
(-> (or/c string? file-contract) path-string? secret-file?)
|
||||||
(let* ([file-config (if (string? file-config) (hash 'source file-config) file-config)]
|
(let* ([file-config (if (string? file-config)
|
||||||
[source-path (string->path (dict-ref file-config 'source))]
|
(hash 'source file-config)
|
||||||
|
file-config)]
|
||||||
|
[source-path (simplify-path
|
||||||
|
(path->complete-path (dict-ref file-config 'source)
|
||||||
|
source-basedir))]
|
||||||
[fs (file-size source-path)]
|
[fs (file-size source-path)]
|
||||||
[name (dict-ref file-config 'name (file-name-from-path source-path))]
|
[name (dict-ref file-config 'name (file-name-from-path source-path))]
|
||||||
[owner (dict-ref file-config 'owner "root")]
|
[owner (dict-ref file-config 'owner "root")]
|
||||||
|
|
@ -113,8 +117,9 @@ EOF
|
||||||
(printf "~a\n" line)
|
(printf "~a\n" line)
|
||||||
(read-loop input-port)))))
|
(read-loop input-port)))))
|
||||||
|
|
||||||
(define/contract (deploy-secrets config)
|
(define/contract (deploy-secrets config
|
||||||
(-> config-contract void?)
|
[source-basedir (current-directory)])
|
||||||
|
(->* (config-contract) (path-string?) void?)
|
||||||
|
|
||||||
(define (handle-stderr stderr phase-channel)
|
(define (handle-stderr stderr phase-channel)
|
||||||
(define p (current-error-port))
|
(define p (current-error-port))
|
||||||
|
|
@ -193,7 +198,9 @@ EOF
|
||||||
(close-output-port stdin))])))
|
(close-output-port stdin))])))
|
||||||
|
|
||||||
(let* ([basedir (dict-ref config 'basedir "/var/lib/secrets")]
|
(let* ([basedir (dict-ref config 'basedir "/var/lib/secrets")]
|
||||||
[files (map make-file (dict-ref config 'files))]
|
[files (map
|
||||||
|
(curryr make-file source-basedir)
|
||||||
|
(dict-ref config 'files))]
|
||||||
[host (dict-ref config 'host)])
|
[host (dict-ref config 'host)])
|
||||||
(let-values ([(sp _ stdin stderr) (subprocess
|
(let-values ([(sp _ stdin stderr) (subprocess
|
||||||
(current-output-port) #f #f
|
(current-output-port) #f #f
|
||||||
|
|
@ -216,6 +223,7 @@ EOF
|
||||||
|
|
||||||
(void))
|
(void))
|
||||||
|
|
||||||
(let* ([config (call-with-input-file "config.json" read-json)])
|
(let* ([config-file "test/config.json"]
|
||||||
(deploy-secrets config)
|
[config (call-with-input-file config-file read-json)])
|
||||||
|
(deploy-secrets config (path->complete-path (path-only config-file)))
|
||||||
(displayln "Done."))
|
(displayln "Done."))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue