ce7cb702218693d08ea6d83464d2457c9250027c
This commit is contained in:
commit
34c5f8963c
1 changed files with 145336 additions and 0 deletions
49
services/ca-sync/run.fsx
Normal file
49
services/ca-sync/run.fsx
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
#load "sync.fsx"
|
||||
|
||||
open System
|
||||
open System.IO
|
||||
open System.Net.Http
|
||||
open Sync
|
||||
|
||||
let run () =
|
||||
match settings Environment.GetEnvironmentVariable (fsi.CommandLineArgs |> Array.skip 1) with
|
||||
| Error error ->
|
||||
eprintfn "%s" error
|
||||
1
|
||||
| Ok config ->
|
||||
use client =
|
||||
new HttpClient(BaseAddress = config.Vault, Timeout = TimeSpan.FromSeconds 10.)
|
||||
|
||||
let jwt =
|
||||
try
|
||||
Ok(File.ReadAllText(config.TokenFile).Trim())
|
||||
with
|
||||
| :? IOException
|
||||
| :? UnauthorizedAccessException -> Error "Cannot read JWT_PATH"
|
||||
|
||||
match jwt |> Result.bind (reconcile config client) with
|
||||
| Error error ->
|
||||
eprintfn "%s" error
|
||||
1
|
||||
| Ok results ->
|
||||
results
|
||||
|> List.iter (fun result ->
|
||||
match result.Outcome with
|
||||
| Ok Unchanged -> printfn "unchanged %s" result.Source.Kv
|
||||
| Ok(Publish _) -> printfn "updated %s" result.Source.Kv
|
||||
| Error error -> eprintfn "%s: %s" result.Source.Kv error)
|
||||
|
||||
let updated, failed =
|
||||
results
|
||||
|> List.fold
|
||||
(fun (updated, failed) result ->
|
||||
match result.Outcome with
|
||||
| Ok Unchanged -> updated, failed
|
||||
| Ok(Publish _) -> updated + 1, failed
|
||||
| Error _ -> updated, failed + 1)
|
||||
(0, 0)
|
||||
|
||||
printfn "checked=%d updated=%d failed=%d" results.Length updated failed
|
||||
if failed = 0 then 0 else 1
|
||||
|
||||
exit (run ())
|
||||
Loading…
Reference in a new issue