#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 ())