// Package app is a utility package package app import ( "strings" "time" "code.tnxs.net/taxnexus/lib/api/auth/auth_client" "code.tnxs.net/taxnexus/lib/api/auth0/auth0_client" "code.tnxs.net/taxnexus/lib/api/crm/crm_client" "code.tnxs.net/taxnexus/lib/api/geo/geo_client" "code.tnxs.net/taxnexus/lib/api/ledger/ledger_client" "code.tnxs.net/taxnexus/lib/api/ops/ops_client" "code.tnxs.net/taxnexus/lib/api/regs/regs_client" "code.tnxs.net/taxnexus/lib/api/stash/stash_client" "code.tnxs.net/taxnexus/lib/app/logger" httptransport "github.com/go-openapi/runtime/client" "github.com/spf13/viper" "go.uber.org/zap" "go.uber.org/zap/zapcore" ) var appViper = viper.New() var auth0Client = auth0_client.Default var authClient = auth_client.Default var authUser *User var config = Configuration{} var configured = false var crmClient = crm_client.Default var geoClient = geo_client.Default var ledgerClient = ledger_client.Default var opsClient = ops_client.Default var regsClient = regs_client.Default var stashClient = stash_client.Default var sugar *zap.SugaredLogger const getTimeout = 6 * time.Minute const postTimeout = 6 * time.Minute const constNotFound = "not found" const percentFactor = 100 const dateFormatDB = "2006-01-02" const dateFormat = "2006-01-02" const dateTimeFormat = "2006-01-02T15:04:05-0800" const dateTimeFormatAlt = "2006-01-02 15:04:05" const dateFormatAlt = "1/2/2006" const countyGeocodeLength = 7 var maxTaxTypes = int64(2000) //nolint:gomnd // it's a var const // const cityGeocodeLength = 12 // InitConfig exports the config initialization func func InitConfig(systemName string, initalLogLevel zapcore.Level) { if configured { return } sugar = logger.New(initalLogLevel) sugar.Infof("app.InitConfig: 📥 %s", systemName) appViper.SetConfigType("yaml") appViper.SetConfigName(systemName) appViper.AddConfigPath("/etc/taxnexus") appViper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) appViper.SetEnvPrefix("taxnexus") appViper.AutomaticEnv() // read in environment variables that match err := appViper.ReadInConfig() if err != nil { sugar.Fatalf("app.InitConfig: 💣 ⛔ can't read system config: %w", err) } err = appViper.Unmarshal(&config) if err != nil { sugar.Fatalf("app.InitConfig: 💣 ⛔ can't unmarshal system config: %w", err) } sugar = logger.New(GetLogLevel()) sugar.Debugf("app.InitConfig: 👍 📤 serviceAccounts: %d", len(config.ServiceAccounts)) configured = true } func apiUser(service string) *User { serviceAccount := GetServiceAccount(service) if serviceAccount == nil { return nil } return &User{ APIKey: serviceAccount.APIKey, Auth: httptransport.APIKeyAuth("X-API-Key", "header", serviceAccount.APIKey), } }