From a0e67fe3feb5b3a2d6d0f8e5f33ff96007955b17 Mon Sep 17 00:00:00 2001 From: "kali kaneko (leap communications)" Date: Tue, 8 Sep 2020 03:32:46 +0200 Subject: [feat] lookup the config vars at runtime - Resolves: #326 --- pkg/bitmask/init.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'pkg/bitmask') diff --git a/pkg/bitmask/init.go b/pkg/bitmask/init.go index b86deb8..4907b2f 100644 --- a/pkg/bitmask/init.go +++ b/pkg/bitmask/init.go @@ -20,6 +20,7 @@ import ( "log" "os" "path" + "strconv" "github.com/jmshal/go-locale" "golang.org/x/text/message" @@ -34,12 +35,46 @@ type ProviderInfo struct { AppName string } +type ProviderOpts struct { + Provider string `json:"name"` + AppName string `json:"applicationName"` + BinaryName string `json:"binaryName"` + Auth string `json:"auth"` + ProviderURL string `json:"providerURL"` + DonateURL string `json:"donateURL"` + ApiURL string `json:"apiURL"` + TosURL string `json:"tosURL"` + HelpURL string `json:"helpURL"` + GeolocationURL string `json:"geolocationAPI"` + AskForDonations string `json:"askForDonations"` + CaCert string `json:"caCertString"` +} + func GetConfiguredProvider() *ProviderInfo { provider := config.Provider appName := config.ApplicationName return &ProviderInfo{provider, appName} } +func ConfigureProvider(opts *ProviderOpts) { + config.Provider = opts.ProviderURL + config.ProviderName = opts.Provider + config.ApplicationName = opts.AppName + config.BinaryName = opts.BinaryName + config.Auth = opts.Auth + config.DonateURL = opts.DonateURL + config.HelpURL = opts.HelpURL + config.TosURL = opts.TosURL + config.APIURL = opts.ApiURL + config.GeolocationAPI = opts.GeolocationURL + config.CaCert = []byte(opts.CaCert) + + wantsDonations, err := strconv.ParseBool(opts.AskForDonations) + if err == nil { + config.AskForDonations = wantsDonations + } +} + func InitializeLogger() { _, err := config.ConfigureLogger(path.Join(config.LogPath)) if err != nil { -- cgit v1.2.3