mirror of
https://github.com/Smaug123/PulumiConfig
synced 2025-10-10 19:18:40 +00:00
Create Pulumi-provisioned web server
This commit is contained in:
34
PulumiWebServer/Htpasswd.fs
Normal file
34
PulumiWebServer/Htpasswd.fs
Normal file
@@ -0,0 +1,34 @@
|
||||
namespace PulumiWebServer
|
||||
|
||||
open System.Diagnostics
|
||||
|
||||
[<RequireQualifiedAccess>]
|
||||
module Htpasswd =
|
||||
|
||||
/// Return the contents of an htpasswd file
|
||||
let generate (username : string) (password : string) : string =
|
||||
let args = ProcessStartInfo ()
|
||||
args.FileName <- "htpasswd"
|
||||
args.RedirectStandardOutput <- true
|
||||
args.RedirectStandardError <- true
|
||||
args.RedirectStandardInput <- true
|
||||
args.UseShellExecute <- false
|
||||
args.Arguments <- $"-n -i -B {username}"
|
||||
|
||||
use p = new Process ()
|
||||
p.StartInfo <- args
|
||||
|
||||
if not <| p.Start () then
|
||||
failwith "failed to start htpasswd"
|
||||
|
||||
p.StandardInput.Write password
|
||||
p.StandardInput.Close ()
|
||||
|
||||
p.WaitForExit ()
|
||||
|
||||
if p.ExitCode = 0 then
|
||||
p.StandardOutput.ReadToEnd ()
|
||||
else
|
||||
|
||||
printfn $"{p.StandardError.ReadToEnd ()}"
|
||||
failwith $"Bad exit code from htpasswd: {p.ExitCode}"
|
Reference in New Issue
Block a user