parent
27447ac9bd
commit
c6cc12ce7c
10
app/auth.go
10
app/auth.go
|
@ -1,16 +1,16 @@
|
|||
package app
|
||||
|
||||
import (
|
||||
"code.tnxs.net/taxnexus/lib/api/auth/auth_client"
|
||||
"code.tnxs.net/taxnexus/lib/api/auth/auth_client/user"
|
||||
"code.tnxs.net/taxnexus/lib/api/auth/auth_models"
|
||||
httptransport "github.com/go-openapi/runtime/client"
|
||||
)
|
||||
|
||||
var authClient = auth_client.Default
|
||||
var authUser *User
|
||||
|
||||
// CheckAPIUser is exported
|
||||
// CheckAPIUser authenticates a User with the auth service
|
||||
//
|
||||
// When called, ChechAPIUser assumes there is an "auth" service account in the
|
||||
// app configuration file.
|
||||
//
|
||||
func CheckAPIUser(token *string) (*User, error) {
|
||||
sugar.Debug("app.CheckAPIUser: 📥")
|
||||
if authUser == nil {
|
||||
|
|
|
@ -144,6 +144,7 @@ func GetServiceAccount(name string) *ServiceAccount {
|
|||
if ok {
|
||||
return &serviceaccount
|
||||
}
|
||||
sugar.Errorf("app.config: 💣⛔ unknown service account: %s", name)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"code.tnxs.net/taxnexus/lib/api/geo/geo_client/domain"
|
||||
)
|
||||
|
||||
// GetDomainMap returns a map of all domains
|
||||
//
|
||||
// Requires the presence of a "geo" service account in the
|
||||
// application configuration file.
|
||||
//
|
||||
func GetDomainMap() (map[string]*Domain, error) {
|
||||
sugar.Debug("ledger.GetDomainMap: 📥")
|
||||
geoUser := apiUser("geo")
|
||||
if geoUser == nil {
|
||||
return nil, fmt.Errorf("app.GetDomainMap: 💣⛔ cannot get auth, check config file")
|
||||
}
|
||||
params := domain.NewGetDomainsParamsWithTimeout(getTimeout)
|
||||
getOK, err := geoClient.Domain.GetDomains(params, geoUser.Auth)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
objMap := map[string]*Domain{}
|
||||
for _, itm := range getOK.Payload.Data {
|
||||
objMap[itm.ID] = UnMarshalDomain(itm)
|
||||
}
|
||||
sugar.Infof("ledger.GetDomainMap: 📀 📤 %v domains loaded", len(objMap))
|
||||
return objMap, nil
|
||||
}
|
30
app/root.go
30
app/root.go
|
@ -5,6 +5,7 @@ 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"
|
||||
|
@ -12,21 +13,24 @@ import (
|
|||
"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 sugar *zap.SugaredLogger
|
||||
var config = Configuration{}
|
||||
var appViper = viper.New()
|
||||
var auth0Client = auth0_client.Default
|
||||
var geoClient = geo_client.Default
|
||||
var authClient = auth_client.Default
|
||||
var authUser *User
|
||||
var config = Configuration{}
|
||||
var configured = false
|
||||
var crmClient = crm_client.Default
|
||||
var stashClient = stash_client.Default
|
||||
var geoClient = geo_client.Default
|
||||
var opsClient = ops_client.Default
|
||||
var regsClient = regs_client.Default
|
||||
var configured = false
|
||||
var stashClient = stash_client.Default
|
||||
var sugar *zap.SugaredLogger
|
||||
|
||||
const getTimeout = 6 * time.Minute
|
||||
const postTimeout = 6 * time.Minute
|
||||
|
@ -38,7 +42,10 @@ const dateTimeFormat = "2006-01-02T15:04:05-0800"
|
|||
const dateTimeFormatAlt = "2006-01-02 15:04:05"
|
||||
const dateFormatAlt = "1/2/2006"
|
||||
const countyGeocodeLength = 7
|
||||
const cityGeocodeLength = 12
|
||||
|
||||
var maxTaxTypes = int64(2000)
|
||||
|
||||
// const cityGeocodeLength = 12
|
||||
|
||||
// InitConfig exports the config initialization func
|
||||
func InitConfig(systemName string, initalLogLevel zapcore.Level) {
|
||||
|
@ -65,3 +72,14 @@ func InitConfig(systemName string, initalLogLevel zapcore.Level) {
|
|||
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),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"code.tnxs.net/taxnexus/lib/api/geo/geo_client/taxnexus_code"
|
||||
)
|
||||
|
||||
// GetTaxnexusCodeMap returns a map of all taxnexus codes
|
||||
//
|
||||
// Requires the presence of a "geo" service account in the
|
||||
// application configuration file.
|
||||
//
|
||||
func GetTaxnexusCodeMap() (map[string]*TaxnexusCode, error) {
|
||||
sugar.Debug("ledger.GetTaxnexusCodeMap: 📥")
|
||||
geoUser := apiUser("geo")
|
||||
if geoUser == nil {
|
||||
return nil, fmt.Errorf("app.GetTaxnexusCodeMap: 💣⛔ cannot get auth, check config file")
|
||||
}
|
||||
params := taxnexus_code.NewGetTaxnexusCodesParams()
|
||||
getOK, err := geoClient.TaxnexusCode.GetTaxnexusCodes(params, geoUser.Auth)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
objMap := map[string]*TaxnexusCode{}
|
||||
n := 0
|
||||
for _, itm := range getOK.Payload.Data {
|
||||
n++
|
||||
objMap[itm.ID] = UnMarshalTaxnexusCode(itm)
|
||||
objMap[itm.Code] = objMap[itm.ID]
|
||||
}
|
||||
sugar.Infof("ledger.GetTaxnexusCodeMap: 📀 📤 %v taxnexus codes loaded", n)
|
||||
return objMap, nil
|
||||
}
|
|
@ -32,6 +32,31 @@ var telecomCategories = map[string]string{
|
|||
"wireless": "wireless",
|
||||
}
|
||||
|
||||
// GetTaxTypeMap returns a map of all taxtypes
|
||||
//
|
||||
// Requires the presence of a "geo" service account in the
|
||||
// application configuration file.
|
||||
//
|
||||
func GetTaxTypeMap() (map[string]*TaxType, error) {
|
||||
sugar.Debug("ledger.GetTaxTypeMap: 📥")
|
||||
geoUser := apiUser("geo")
|
||||
if geoUser == nil {
|
||||
return nil, fmt.Errorf("app.GetTaxTypeMap: 💣⛔ cannot get auth, check config file")
|
||||
}
|
||||
params := tax_type.NewGetTaxTypesParamsWithTimeout(getTimeout)
|
||||
params.Limit = &maxTaxTypes
|
||||
getOK, err := geoClient.TaxType.GetTaxTypes(params, geoUser.Auth)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
objMap := map[string]*TaxType{}
|
||||
for _, itm := range getOK.Payload.Data {
|
||||
objMap[itm.ID] = UnMarshalTaxType(itm)
|
||||
}
|
||||
sugar.Infof("ledger.GetTaxTypeMap: 📀 📤 %v taxtypes loaded", len(objMap))
|
||||
return objMap, nil
|
||||
}
|
||||
|
||||
// GetTaxType is first class retrieval function
|
||||
func GetTaxType(recordID string, principal *User) *TaxType {
|
||||
obj, ok := taxTypeCache.get(recordID)
|
||||
|
|
Loading…
Reference in New Issue