diff --git a/PulumiWebServer.Test/TestConfiguration.fs b/PulumiWebServer.Test/TestConfiguration.fs index 34885dd..bab365e 100644 --- a/PulumiWebServer.Test/TestConfiguration.fs +++ b/PulumiWebServer.Test/TestConfiguration.fs @@ -70,6 +70,8 @@ module TestConfiguration = Subdomains = Set.empty AcmeEmail = EmailAddress "test@example.com" RemoteUsername = Username "non-root" + RadicaleConfig = None + GiteaConfig = None } let serialised = SerialisedConfig.Make publicConfig diff --git a/PulumiWebServer/Configuration.fs b/PulumiWebServer/Configuration.fs index 6b87e7d..f8f9721 100644 --- a/PulumiWebServer/Configuration.fs +++ b/PulumiWebServer/Configuration.fs @@ -5,6 +5,23 @@ open System.Collections.Generic open System.IO open Newtonsoft.Json +[] +type RadicaleConfig = + { + User : string + Password : string + GitEmail : string + } + +[] +type GiteaConfig = + { + ServerPassword : string + AdminPassword : string + AdminEmailAddress : string + AdminUsername : string + } + [] type Configuration = { @@ -30,6 +47,8 @@ type Configuration = AcmeEmail : EmailAddress /// Username for the user account to be created on the server RemoteUsername : Username + RadicaleConfig : RadicaleConfig option + GiteaConfig : GiteaConfig option } member this.PublicKey = @@ -39,6 +58,61 @@ type Configuration = let (PrivateKey k) = this.PrivateKey Path.Combine (k.Directory.FullName, k.Name + ".pub") |> FileInfo |> PublicKey +[] +type SerialisedRadicaleConfig = + { + [] + User : string + [] + Password : string + [] + GitEmail : string + } + + static member Make (config : RadicaleConfig) : SerialisedRadicaleConfig = + { + User = config.User + Password = config.Password + GitEmail = config.GitEmail + } + + static member Deserialise (config : SerialisedRadicaleConfig) : RadicaleConfig = + { + User = config.User + Password = config.Password + GitEmail = config.GitEmail + } + +[] +type SerialisedGiteaConfig = + { + [] + ServerPassword : string + [] + AdminPassword : string + [] + AdminEmailAddress : string + [] + AdminUsername : string + } + + static member Make (config : GiteaConfig) : SerialisedGiteaConfig = + { + ServerPassword = config.ServerPassword + AdminPassword = config.AdminPassword + AdminEmailAddress = config.AdminEmailAddress + AdminUsername = config.AdminUsername + } + + static member Deserialise (config : SerialisedGiteaConfig) : GiteaConfig = + { + ServerPassword = config.ServerPassword + AdminPassword = config.AdminPassword + AdminEmailAddress = config.AdminEmailAddress + AdminUsername = config.AdminUsername + } + + [] [] type SerialisedConfig = @@ -61,6 +135,10 @@ type SerialisedConfig = AcmeEmail : string [] RemoteUsername : string + [] + RadicaleConfig : SerialisedRadicaleConfig + [] + GiteaConfig : SerialisedGiteaConfig } static member Make (config : Configuration) = @@ -82,6 +160,11 @@ type SerialisedConfig = Subdomains = config.Subdomains |> Seq.map (fun sub -> sub.ToString ()) |> Seq.toArray AcmeEmail = config.AcmeEmail.ToString () RemoteUsername = config.RemoteUsername.ToString () + RadicaleConfig = + config.RadicaleConfig + |> Option.map SerialisedRadicaleConfig.Make + |> Option.toObj + GiteaConfig = config.GiteaConfig |> Option.map SerialisedGiteaConfig.Make |> Option.toObj } static member Deserialise (config : SerialisedConfig) : Configuration = @@ -105,6 +188,14 @@ type SerialisedConfig = | subdomains -> subdomains |> Seq.map WellKnownSubdomain.Parse |> Set.ofSeq AcmeEmail = config.AcmeEmail |> EmailAddress RemoteUsername = config.RemoteUsername |> Username + RadicaleConfig = + config.RadicaleConfig + |> Option.ofObj + |> Option.map SerialisedRadicaleConfig.Deserialise + GiteaConfig = + config.GiteaConfig + |> Option.ofObj + |> Option.map SerialisedGiteaConfig.Deserialise } [] diff --git a/PulumiWebServer/config.schema.json b/PulumiWebServer/config.schema.json index 1829b4a..bd09e41 100644 --- a/PulumiWebServer/config.schema.json +++ b/PulumiWebServer/config.schema.json @@ -41,6 +41,72 @@ }, "remoteUsername": { "type": "string" + }, + "radicaleConfig": { + "oneOf": [ + { + "type": "null" + }, + { + "$ref": "#/definitions/SerialisedRadicaleConfig" + } + ] + }, + "giteaConfig": { + "oneOf": [ + { + "type": "null" + }, + { + "$ref": "#/definitions/SerialisedGiteaConfig" + } + ] + } + }, + "definitions": { + "SerialisedRadicaleConfig": { + "type": "object", + "additionalProperties": false, + "required": [ + "user", + "password", + "gitEmail" + ], + "properties": { + "user": { + "type": "string" + }, + "password": { + "type": "string" + }, + "gitEmail": { + "type": "string" + } + } + }, + "SerialisedGiteaConfig": { + "type": "object", + "additionalProperties": false, + "required": [ + "serverPassword", + "adminPassword", + "adminEmailAddress", + "adminUsername" + ], + "properties": { + "serverPassword": { + "type": "string" + }, + "adminPassword": { + "type": "string" + }, + "adminEmailAddress": { + "type": "string" + }, + "adminUsername": { + "type": "string" + } + } } } } \ No newline at end of file