parent
530e351912
commit
27447ac9bd
14
app/auth.go
14
app/auth.go
|
@ -4,16 +4,28 @@ 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
|
||||
func CheckAPIUser(token *string) (*User, error) {
|
||||
sugar.Debug("app.CheckAPIUser: 📥")
|
||||
if authUser == nil {
|
||||
authUser = &User{
|
||||
APIKey: GetServiceAccount("auth").APIKey,
|
||||
Auth: httptransport.APIKeyAuth(
|
||||
"X-API-Key",
|
||||
"header",
|
||||
GetServiceAccount("auth").APIKey,
|
||||
),
|
||||
}
|
||||
}
|
||||
params := user.NewGetUsersParams()
|
||||
params.Apikey = token
|
||||
response, err := authClient.User.GetUsers(params, apiUsers["auth"].Auth)
|
||||
response, err := authClient.User.GetUsers(params, authUser.Auth)
|
||||
if err != nil {
|
||||
sugar.Warnf("app.CheckAPIUser: ❗ Access attempt with invalid API key: %s", *token)
|
||||
return nil, err
|
||||
|
|
26
app/root.go
26
app/root.go
|
@ -12,7 +12,6 @@ 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"
|
||||
|
@ -28,7 +27,6 @@ var stashClient = stash_client.Default
|
|||
var opsClient = ops_client.Default
|
||||
var regsClient = regs_client.Default
|
||||
var configured = false
|
||||
var apiUsers map[string]User
|
||||
|
||||
const getTimeout = 6 * time.Minute
|
||||
const postTimeout = 6 * time.Minute
|
||||
|
@ -64,30 +62,6 @@ func InitConfig(systemName string, initalLogLevel zapcore.Level) {
|
|||
sugar.Fatalf("app.InitConfig: 💣 ⛔ can't unmarshal system config: %w", err)
|
||||
}
|
||||
sugar = logger.New(GetLogLevel())
|
||||
apiUsers = initAPIUsers()
|
||||
sugar.Debugf("app.InitConfig: 👍 📤 serviceAccounts: %d", len(config.ServiceAccounts))
|
||||
configured = true
|
||||
}
|
||||
|
||||
func initAPIUsers() map[string]User {
|
||||
sugar.Info("app.initAPIUsers: 📥")
|
||||
users := map[string]User{
|
||||
"auth": {
|
||||
APIKey: GetServiceAccount("auth").APIKey,
|
||||
Auth: httptransport.APIKeyAuth(
|
||||
"X-API-Key",
|
||||
"header",
|
||||
GetServiceAccount("auth").APIKey,
|
||||
),
|
||||
},
|
||||
"test-service-account": {
|
||||
APIKey: GetServiceAccount("test-service-account").APIKey,
|
||||
Auth: httptransport.APIKeyAuth(
|
||||
"X-API-Key",
|
||||
"header",
|
||||
GetServiceAccount("test-service-account").APIKey),
|
||||
},
|
||||
}
|
||||
sugar.Debugf("app.initAPIUsers: 👍 📤")
|
||||
return users
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue