Skip to content

Commit

Permalink
Add user secrets pimbrouwers#115
Browse files Browse the repository at this point in the history
  • Loading branch information
kgday committed Dec 3, 2023
1 parent ccc4307 commit a8651a7
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/Falco/ConfigBuilder.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@ type ConfigFile =
| XmlFile of path : string
| JsonFile of path : string


type ConfigBuilderSpec =
{ AddEnvVars : bool
BasePath : string
RequiredFiles : ConfigFile list
OptionalFiles : ConfigFile list
InMemory : Map<string, string> }
InMemory : Map<string, string>
AddUserSecrets: bool}

static member Empty =
{ AddEnvVars = false
BasePath = Directory.GetCurrentDirectory()
RequiredFiles = []
OptionalFiles = []
InMemory = Map.empty }
InMemory = Map.empty
AddUserSecrets= false }

/// Computation expression to allow for elegant IConfiguration construction.
type ConfigBuilder (args : string[]) =
Expand Down Expand Up @@ -51,6 +54,9 @@ type ConfigBuilder (args : string[]) =

bldr.AddCommandLine(args) |> ignore

if conf.AddUserSecrets then
bldr.AddUserSecrets() |> ignore

bldr.Build() :> IConfiguration

/// Sets the base path of the ConfigurationBuilder.
Expand Down Expand Up @@ -101,6 +107,11 @@ type ConfigBuilder (args : string[]) =
member _.AddOptionalJsonFile (conf : ConfigBuilderSpec, filePath : string) =
{ conf with OptionalFiles = (JsonFile filePath) :: conf.OptionalFiles }

///Adds optional user secrets to the ConfigurationBuilder.
[<CustomOperation("optional_user_secrets")>]
member _.AddOptionalUserSecrets (conf : ConfigBuilderSpec) =
{ conf with AddUserSecrets = true }

[<AutoOpen>]
module ConfigurationBuilder =
/// Computation expression to allow for elegant IConfiguration construction.
Expand Down

0 comments on commit a8651a7

Please sign in to comment.