feat: setup logours for logging
This commit is contained in:
parent
773213e5a4
commit
da0fcb109b
|
@ -2,7 +2,6 @@ package arangodb
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
arangoDriver "github.com/arangodb/go-driver"
|
||||
|
@ -22,7 +21,6 @@ func (p *provider) AddEnv(env models.Env) (models.Env, error) {
|
|||
configCollection, _ := p.db.Collection(nil, models.Collections.Env)
|
||||
meta, err := configCollection.CreateDocument(arangoDriver.WithOverwrite(nil), env)
|
||||
if err != nil {
|
||||
log.Println("error adding config:", err)
|
||||
return env, err
|
||||
}
|
||||
env.Key = meta.Key
|
||||
|
@ -36,7 +34,6 @@ func (p *provider) UpdateEnv(env models.Env) (models.Env, error) {
|
|||
collection, _ := p.db.Collection(nil, models.Collections.Env)
|
||||
meta, err := collection.UpdateDocument(nil, env.Key, env)
|
||||
if err != nil {
|
||||
log.Println("error updating config:", err)
|
||||
return env, err
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package arangodb
|
|||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
|
||||
"github.com/arangodb/go-driver"
|
||||
arangoDriver "github.com/arangodb/go-driver"
|
||||
|
@ -42,7 +41,6 @@ func NewProvider() (*provider, error) {
|
|||
arangodb_exists, err := arangoClient.DatabaseExists(nil, envstore.EnvStoreObj.GetStringStoreEnvVariable(constants.EnvKeyDatabaseName))
|
||||
|
||||
if arangodb_exists {
|
||||
log.Println(envstore.EnvStoreObj.GetStringStoreEnvVariable(constants.EnvKeyDatabaseName) + " db exists already")
|
||||
arangodb, err = arangoClient.Database(nil, envstore.EnvStoreObj.GetStringStoreEnvVariable(constants.EnvKeyDatabaseName))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -55,12 +53,10 @@ func NewProvider() (*provider, error) {
|
|||
}
|
||||
|
||||
userCollectionExists, err := arangodb.CollectionExists(ctx, models.Collections.User)
|
||||
if userCollectionExists {
|
||||
log.Println(models.Collections.User + " collection exists already")
|
||||
} else {
|
||||
if !userCollectionExists {
|
||||
_, err = arangodb.CreateCollection(ctx, models.Collections.User, nil)
|
||||
if err != nil {
|
||||
log.Println("error creating collection("+models.Collections.User+"):", err)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
userCollection, _ := arangodb.Collection(nil, models.Collections.User)
|
||||
|
@ -74,12 +70,10 @@ func NewProvider() (*provider, error) {
|
|||
})
|
||||
|
||||
verificationRequestCollectionExists, err := arangodb.CollectionExists(ctx, models.Collections.VerificationRequest)
|
||||
if verificationRequestCollectionExists {
|
||||
log.Println(models.Collections.VerificationRequest + " collection exists already")
|
||||
} else {
|
||||
if !verificationRequestCollectionExists {
|
||||
_, err = arangodb.CreateCollection(ctx, models.Collections.VerificationRequest, nil)
|
||||
if err != nil {
|
||||
log.Println("error creating collection("+models.Collections.VerificationRequest+"):", err)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,12 +87,10 @@ func NewProvider() (*provider, error) {
|
|||
})
|
||||
|
||||
sessionCollectionExists, err := arangodb.CollectionExists(ctx, models.Collections.Session)
|
||||
if sessionCollectionExists {
|
||||
log.Println(models.Collections.Session + " collection exists already")
|
||||
} else {
|
||||
if !sessionCollectionExists {
|
||||
_, err = arangodb.CreateCollection(ctx, models.Collections.Session, nil)
|
||||
if err != nil {
|
||||
log.Println("error creating collection("+models.Collections.Session+"):", err)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,12 +100,10 @@ func NewProvider() (*provider, error) {
|
|||
})
|
||||
|
||||
configCollectionExists, err := arangodb.CollectionExists(ctx, models.Collections.Env)
|
||||
if configCollectionExists {
|
||||
log.Println(models.Collections.Env + " collection exists already")
|
||||
} else {
|
||||
if !configCollectionExists {
|
||||
_, err = arangodb.CreateCollection(ctx, models.Collections.Env, nil)
|
||||
if err != nil {
|
||||
log.Println("error creating collection("+models.Collections.Env+"):", err)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package arangodb
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/authorizerdev/authorizer/server/db/models"
|
||||
|
@ -20,7 +19,6 @@ func (p *provider) AddSession(session models.Session) error {
|
|||
sessionCollection, _ := p.db.Collection(nil, models.Collections.Session)
|
||||
_, err := sessionCollection.CreateDocument(nil, session)
|
||||
if err != nil {
|
||||
log.Println(`error saving session`, err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -3,7 +3,6 @@ package arangodb
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -31,7 +30,6 @@ func (p *provider) AddUser(user models.User) (models.User, error) {
|
|||
userCollection, _ := p.db.Collection(nil, models.Collections.User)
|
||||
meta, err := userCollection.CreateDocument(arangoDriver.WithOverwrite(nil), user)
|
||||
if err != nil {
|
||||
log.Println("error adding user:", err)
|
||||
return user, err
|
||||
}
|
||||
user.Key = meta.Key
|
||||
|
@ -46,7 +44,6 @@ func (p *provider) UpdateUser(user models.User) (models.User, error) {
|
|||
collection, _ := p.db.Collection(nil, models.Collections.User)
|
||||
meta, err := collection.UpdateDocument(nil, user.Key, user)
|
||||
if err != nil {
|
||||
log.Println("error updating user:", err)
|
||||
return user, err
|
||||
}
|
||||
|
||||
|
@ -60,7 +57,6 @@ func (p *provider) DeleteUser(user models.User) error {
|
|||
collection, _ := p.db.Collection(nil, models.Collections.User)
|
||||
_, err := collection.RemoveDocument(nil, user.Key)
|
||||
if err != nil {
|
||||
log.Println(`error deleting user:`, err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ package arangodb
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/arangodb/go-driver"
|
||||
|
@ -23,7 +22,6 @@ func (p *provider) AddVerificationRequest(verificationRequest models.Verificatio
|
|||
verificationRequestRequestCollection, _ := p.db.Collection(nil, models.Collections.VerificationRequest)
|
||||
meta, err := verificationRequestRequestCollection.CreateDocument(nil, verificationRequest)
|
||||
if err != nil {
|
||||
log.Println("error saving verificationRequest record:", err)
|
||||
return verificationRequest, err
|
||||
}
|
||||
verificationRequest.Key = meta.Key
|
||||
|
@ -136,7 +134,6 @@ func (p *provider) DeleteVerificationRequest(verificationRequest models.Verifica
|
|||
collection, _ := p.db.Collection(nil, models.Collections.VerificationRequest)
|
||||
_, err := collection.RemoveDocument(nil, verificationRequest.Key)
|
||||
if err != nil {
|
||||
log.Println(`error deleting verification request:`, err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/authorizerdev/authorizer/server/constants"
|
||||
|
@ -88,7 +87,6 @@ func NewProvider() (*provider, error) {
|
|||
|
||||
session, err := cassandraClient.CreateSession()
|
||||
if err != nil {
|
||||
log.Println("Error while creating connection to cassandra db", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -101,7 +99,6 @@ func NewProvider() (*provider, error) {
|
|||
var keySpace string
|
||||
err := scanner.Scan(&keySpace)
|
||||
if err != nil {
|
||||
log.Println("Error while getting keyspace information", err)
|
||||
return nil, err
|
||||
}
|
||||
if keySpace == KeySpace {
|
||||
|
@ -114,7 +111,6 @@ func NewProvider() (*provider, error) {
|
|||
createKeySpaceQuery := fmt.Sprintf("CREATE KEYSPACE %s WITH REPLICATION = {'class': 'SimpleStrategy', 'replication_factor': 1};", KeySpace)
|
||||
err = session.Query(createKeySpaceQuery).Exec()
|
||||
if err != nil {
|
||||
log.Println("Error while creating keyspace", err)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
@ -124,27 +120,23 @@ func NewProvider() (*provider, error) {
|
|||
KeySpace, models.Collections.Env)
|
||||
err = session.Query(envCollectionQuery).Exec()
|
||||
if err != nil {
|
||||
log.Println("Unable to create env collection:", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sessionCollectionQuery := fmt.Sprintf("CREATE TABLE IF NOT EXISTS %s.%s (id text, user_id text, user_agent text, ip text, updated_at bigint, created_at bigint, PRIMARY KEY (id))", KeySpace, models.Collections.Session)
|
||||
err = session.Query(sessionCollectionQuery).Exec()
|
||||
if err != nil {
|
||||
log.Println("Unable to create session collection:", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
userCollectionQuery := fmt.Sprintf("CREATE TABLE IF NOT EXISTS %s.%s (id text, email text, email_verified_at bigint, password text, signup_methods text, given_name text, family_name text, middle_name text, nickname text, gender text, birthdate text, phone_number text, phone_number_verified_at bigint, picture text, roles text, updated_at bigint, created_at bigint, revoked_timestamp bigint, PRIMARY KEY (id))", KeySpace, models.Collections.User)
|
||||
err = session.Query(userCollectionQuery).Exec()
|
||||
if err != nil {
|
||||
log.Println("Unable to create user collection:", err)
|
||||
return nil, err
|
||||
}
|
||||
userIndexQuery := fmt.Sprintf("CREATE INDEX IF NOT EXISTS authorizer_user_email ON %s.%s (email)", KeySpace, models.Collections.User)
|
||||
err = session.Query(userIndexQuery).Exec()
|
||||
if err != nil {
|
||||
log.Println("Unable to create user index:", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -152,25 +144,21 @@ func NewProvider() (*provider, error) {
|
|||
verificationRequestCollectionQuery := fmt.Sprintf("CREATE TABLE IF NOT EXISTS %s.%s (id text, jwt_token text, identifier text, expires_at bigint, email text, nonce text, redirect_uri text, created_at bigint, updated_at bigint, PRIMARY KEY (id))", KeySpace, models.Collections.VerificationRequest)
|
||||
err = session.Query(verificationRequestCollectionQuery).Exec()
|
||||
if err != nil {
|
||||
log.Println("Unable to create verification request collection:", err)
|
||||
return nil, err
|
||||
}
|
||||
verificationRequestIndexQuery := fmt.Sprintf("CREATE INDEX IF NOT EXISTS authorizer_verification_request_email ON %s.%s (email)", KeySpace, models.Collections.VerificationRequest)
|
||||
err = session.Query(verificationRequestIndexQuery).Exec()
|
||||
if err != nil {
|
||||
log.Println("Unable to create verification_requests index:", err)
|
||||
return nil, err
|
||||
}
|
||||
verificationRequestIndexQuery = fmt.Sprintf("CREATE INDEX IF NOT EXISTS authorizer_verification_request_identifier ON %s.%s (identifier)", KeySpace, models.Collections.VerificationRequest)
|
||||
err = session.Query(verificationRequestIndexQuery).Exec()
|
||||
if err != nil {
|
||||
log.Println("Unable to create verification_requests index:", err)
|
||||
return nil, err
|
||||
}
|
||||
verificationRequestIndexQuery = fmt.Sprintf("CREATE INDEX IF NOT EXISTS authorizer_verification_request_jwt_token ON %s.%s (jwt_token)", KeySpace, models.Collections.VerificationRequest)
|
||||
err = session.Query(verificationRequestIndexQuery).Exec()
|
||||
if err != nil {
|
||||
log.Println("Unable to create verification_requests index:", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package cassandradb
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/authorizerdev/authorizer/server/db/models"
|
||||
|
@ -61,7 +60,6 @@ func (p *provider) ListVerificationRequests(pagination model.Pagination) (*model
|
|||
totalCountQuery := fmt.Sprintf(`SELECT COUNT(*) FROM %s`, KeySpace+"."+models.Collections.VerificationRequest)
|
||||
err := p.db.Query(totalCountQuery).Consistency(gocql.One).Scan(&paginationClone.Total)
|
||||
if err != nil {
|
||||
log.Println("Error while quering verification request", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -77,7 +75,6 @@ func (p *provider) ListVerificationRequests(pagination model.Pagination) (*model
|
|||
var verificationRequest models.VerificationRequest
|
||||
err := scanner.Scan(&verificationRequest.ID, &verificationRequest.Token, &verificationRequest.Identifier, &verificationRequest.ExpiresAt, &verificationRequest.Email, &verificationRequest.Nonce, &verificationRequest.RedirectURI, &verificationRequest.CreatedAt, &verificationRequest.UpdatedAt)
|
||||
if err != nil {
|
||||
log.Println("Error while parsing verification request", err)
|
||||
return nil, err
|
||||
}
|
||||
verificationRequests = append(verificationRequests, verificationRequest.AsAPIVerificationRequest())
|
||||
|
|
|
@ -2,7 +2,6 @@ package mongodb
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/authorizerdev/authorizer/server/db/models"
|
||||
|
@ -23,7 +22,6 @@ func (p *provider) AddEnv(env models.Env) (models.Env, error) {
|
|||
configCollection := p.db.Collection(models.Collections.Env, options.Collection())
|
||||
_, err := configCollection.InsertOne(nil, env)
|
||||
if err != nil {
|
||||
log.Println("error adding config:", err)
|
||||
return env, err
|
||||
}
|
||||
return env, nil
|
||||
|
@ -35,7 +33,6 @@ func (p *provider) UpdateEnv(env models.Env) (models.Env, error) {
|
|||
configCollection := p.db.Collection(models.Collections.Env, options.Collection())
|
||||
_, err := configCollection.UpdateOne(nil, bson.M{"_id": bson.M{"$eq": env.ID}}, bson.M{"$set": env}, options.MergeUpdateOptions())
|
||||
if err != nil {
|
||||
log.Println("error updating config:", err)
|
||||
return env, err
|
||||
}
|
||||
return env, nil
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package mongodb
|
||||
|
||||
import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/authorizerdev/authorizer/server/db/models"
|
||||
|
@ -22,7 +21,6 @@ func (p *provider) AddSession(session models.Session) error {
|
|||
sessionCollection := p.db.Collection(models.Collections.Session, options.Collection())
|
||||
_, err := sessionCollection.InsertOne(nil, session)
|
||||
if err != nil {
|
||||
log.Println(`error saving session`, err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
@ -33,7 +31,6 @@ func (p *provider) DeleteSession(userId string) error {
|
|||
sessionCollection := p.db.Collection(models.Collections.Session, options.Collection())
|
||||
_, err := sessionCollection.DeleteMany(nil, bson.M{"user_id": userId}, options.Delete())
|
||||
if err != nil {
|
||||
log.Println("error deleting session:", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package mongodb
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -29,7 +28,6 @@ func (p *provider) AddUser(user models.User) (models.User, error) {
|
|||
userCollection := p.db.Collection(models.Collections.User, options.Collection())
|
||||
_, err := userCollection.InsertOne(nil, user)
|
||||
if err != nil {
|
||||
log.Println("error adding user:", err)
|
||||
return user, err
|
||||
}
|
||||
|
||||
|
@ -42,7 +40,6 @@ func (p *provider) UpdateUser(user models.User) (models.User, error) {
|
|||
userCollection := p.db.Collection(models.Collections.User, options.Collection())
|
||||
_, err := userCollection.UpdateOne(nil, bson.M{"_id": bson.M{"$eq": user.ID}}, bson.M{"$set": user}, options.MergeUpdateOptions())
|
||||
if err != nil {
|
||||
log.Println("error updating user:", err)
|
||||
return user, err
|
||||
}
|
||||
return user, nil
|
||||
|
@ -53,7 +50,6 @@ func (p *provider) DeleteUser(user models.User) error {
|
|||
userCollection := p.db.Collection(models.Collections.User, options.Collection())
|
||||
_, err := userCollection.DeleteOne(nil, bson.M{"_id": user.ID}, options.Delete())
|
||||
if err != nil {
|
||||
log.Println("error deleting user:", err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -74,7 +70,6 @@ func (p *provider) ListUsers(pagination model.Pagination) (*model.Users, error)
|
|||
userCollection := p.db.Collection(models.Collections.User, options.Collection())
|
||||
count, err := userCollection.CountDocuments(nil, bson.M{}, options.Count())
|
||||
if err != nil {
|
||||
log.Println("error getting total users:", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -82,7 +77,6 @@ func (p *provider) ListUsers(pagination model.Pagination) (*model.Users, error)
|
|||
|
||||
cursor, err := userCollection.Find(nil, bson.M{}, opts)
|
||||
if err != nil {
|
||||
log.Println("error getting users:", err)
|
||||
return nil, err
|
||||
}
|
||||
defer cursor.Close(nil)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package mongodb
|
||||
|
||||
import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/authorizerdev/authorizer/server/db/models"
|
||||
|
@ -22,7 +21,6 @@ func (p *provider) AddVerificationRequest(verificationRequest models.Verificatio
|
|||
verificationRequestCollection := p.db.Collection(models.Collections.VerificationRequest, options.Collection())
|
||||
_, err := verificationRequestCollection.InsertOne(nil, verificationRequest)
|
||||
if err != nil {
|
||||
log.Println("error saving verification record:", err)
|
||||
return verificationRequest, err
|
||||
}
|
||||
}
|
||||
|
@ -73,7 +71,6 @@ func (p *provider) ListVerificationRequests(pagination model.Pagination) (*model
|
|||
|
||||
cursor, err := verificationRequestCollection.Find(nil, bson.M{}, opts)
|
||||
if err != nil {
|
||||
log.Println("error getting verification requests:", err)
|
||||
return nil, err
|
||||
}
|
||||
defer cursor.Close(nil)
|
||||
|
@ -98,7 +95,6 @@ func (p *provider) DeleteVerificationRequest(verificationRequest models.Verifica
|
|||
verificationRequestCollection := p.db.Collection(models.Collections.VerificationRequest, options.Collection())
|
||||
_, err := verificationRequestCollection.DeleteOne(nil, bson.M{"_id": verificationRequest.ID}, options.Delete())
|
||||
if err != nil {
|
||||
log.Println("error deleting verification request::", err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package sql
|
||||
|
||||
import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/authorizerdev/authorizer/server/db/models"
|
||||
|
@ -20,7 +19,6 @@ func (p *provider) AddEnv(env models.Env) (models.Env, error) {
|
|||
|
||||
result := p.db.Create(&env)
|
||||
if result.Error != nil {
|
||||
log.Println("error adding config:", result.Error)
|
||||
return env, result.Error
|
||||
}
|
||||
return env, nil
|
||||
|
@ -32,7 +30,6 @@ func (p *provider) UpdateEnv(env models.Env) (models.Env, error) {
|
|||
result := p.db.Save(&env)
|
||||
|
||||
if result.Error != nil {
|
||||
log.Println("error updating config:", result.Error)
|
||||
return env, result.Error
|
||||
}
|
||||
return env, nil
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package sql
|
||||
|
||||
import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/authorizerdev/authorizer/server/db/models"
|
||||
|
@ -23,7 +22,6 @@ func (p *provider) AddSession(session models.Session) error {
|
|||
DoNothing: true,
|
||||
}).Create(&session)
|
||||
if res.Error != nil {
|
||||
log.Println(`error saving session`, res.Error)
|
||||
return res.Error
|
||||
}
|
||||
return nil
|
||||
|
@ -34,7 +32,6 @@ func (p *provider) DeleteSession(userId string) error {
|
|||
result := p.db.Where("user_id = ?", userId).Delete(&models.Session{})
|
||||
|
||||
if result.Error != nil {
|
||||
log.Println(`error deleting session:`, result.Error)
|
||||
return result.Error
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package sql
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -33,7 +32,6 @@ func (p *provider) AddUser(user models.User) (models.User, error) {
|
|||
}).Create(&user)
|
||||
|
||||
if result.Error != nil {
|
||||
log.Println("error adding user:", result.Error)
|
||||
return user, result.Error
|
||||
}
|
||||
|
||||
|
@ -47,7 +45,6 @@ func (p *provider) UpdateUser(user models.User) (models.User, error) {
|
|||
result := p.db.Save(&user)
|
||||
|
||||
if result.Error != nil {
|
||||
log.Println("error updating user:", result.Error)
|
||||
return user, result.Error
|
||||
}
|
||||
|
||||
|
@ -59,7 +56,6 @@ func (p *provider) DeleteUser(user models.User) error {
|
|||
result := p.db.Delete(&user)
|
||||
|
||||
if result.Error != nil {
|
||||
log.Println(`error deleting user:`, result.Error)
|
||||
return result.Error
|
||||
}
|
||||
|
||||
|
@ -71,7 +67,6 @@ func (p *provider) ListUsers(pagination model.Pagination) (*model.Users, error)
|
|||
var users []models.User
|
||||
result := p.db.Limit(int(pagination.Limit)).Offset(int(pagination.Offset)).Order("created_at DESC").Find(&users)
|
||||
if result.Error != nil {
|
||||
log.Println("error getting users:", result.Error)
|
||||
return nil, result.Error
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package sql
|
||||
|
||||
import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/authorizerdev/authorizer/server/db/models"
|
||||
|
@ -25,7 +24,6 @@ func (p *provider) AddVerificationRequest(verificationRequest models.Verificatio
|
|||
}).Create(&verificationRequest)
|
||||
|
||||
if result.Error != nil {
|
||||
log.Println(`error saving verification request record`, result.Error)
|
||||
return verificationRequest, result.Error
|
||||
}
|
||||
|
||||
|
@ -38,7 +36,6 @@ func (p *provider) GetVerificationRequestByToken(token string) (models.Verificat
|
|||
result := p.db.Where("token = ?", token).First(&verificationRequest)
|
||||
|
||||
if result.Error != nil {
|
||||
log.Println(`error getting verification request:`, result.Error)
|
||||
return verificationRequest, result.Error
|
||||
}
|
||||
|
||||
|
@ -52,7 +49,6 @@ func (p *provider) GetVerificationRequestByEmail(email string, identifier string
|
|||
result := p.db.Where("email = ? AND identifier = ?", email, identifier).First(&verificationRequest)
|
||||
|
||||
if result.Error != nil {
|
||||
log.Println(`error getting verification token:`, result.Error)
|
||||
return verificationRequest, result.Error
|
||||
}
|
||||
|
||||
|
@ -65,7 +61,6 @@ func (p *provider) ListVerificationRequests(pagination model.Pagination) (*model
|
|||
|
||||
result := p.db.Limit(int(pagination.Limit)).Offset(int(pagination.Offset)).Order("created_at DESC").Find(&verificationRequests)
|
||||
if result.Error != nil {
|
||||
log.Println("error getting verification requests:", result.Error)
|
||||
return nil, result.Error
|
||||
}
|
||||
|
||||
|
@ -94,7 +89,6 @@ func (p *provider) DeleteVerificationRequest(verificationRequest models.Verifica
|
|||
result := p.db.Delete(&verificationRequest)
|
||||
|
||||
if result.Error != nil {
|
||||
log.Println(`error deleting verification request:`, result.Error)
|
||||
return result.Error
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ require (
|
|||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.1 // indirect
|
||||
github.com/robertkrimen/otto v0.0.0-20211024170158-b87d35c0b86f
|
||||
github.com/sirupsen/logrus v1.8.1 // indirect
|
||||
github.com/stretchr/testify v1.7.0
|
||||
github.com/ugorji/go v1.2.6 // indirect
|
||||
github.com/vektah/gqlparser/v2 v2.2.0
|
||||
|
|
|
@ -331,6 +331,8 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV
|
|||
github.com/shurcooL/vfsgen v0.0.0-20180121065927-ffb13db8def0/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw=
|
||||
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
|
||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
|
||||
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
|
||||
|
|
|
@ -2,7 +2,8 @@ package main
|
|||
|
||||
import (
|
||||
"flag"
|
||||
"log"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/authorizerdev/authorizer/server/constants"
|
||||
"github.com/authorizerdev/authorizer/server/db"
|
||||
|
@ -21,7 +22,9 @@ func main() {
|
|||
envstore.ARG_ENV_FILE = flag.String("env_file", "", "Env file path")
|
||||
flag.Parse()
|
||||
|
||||
log.Println("=> version:", VERSION)
|
||||
log.SetFormatter(&log.JSONFormatter{})
|
||||
log.SetReportCaller(true)
|
||||
|
||||
constants.VERSION = VERSION
|
||||
|
||||
// initialize required envs (mainly db & env file path)
|
||||
|
@ -62,5 +65,6 @@ func main() {
|
|||
}
|
||||
|
||||
router := routes.InitRouter()
|
||||
log.Info("Starting Authorizer: ", VERSION)
|
||||
router.Run(":" + envstore.EnvStoreObj.GetStringStoreEnvVariable(constants.EnvKeyPort))
|
||||
}
|
||||
|
|
60
server/middlewares/log.go
Normal file
60
server/middlewares/log.go
Normal file
|
@ -0,0 +1,60 @@
|
|||
package middlewares
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/authorizerdev/authorizer/server/constants"
|
||||
"github.com/authorizerdev/authorizer/server/utils"
|
||||
)
|
||||
|
||||
// GinLogWriteFunc convert func to io.Writer.
|
||||
type GinLogWriteFunc func([]byte) (int, error)
|
||||
|
||||
// GinLog Write function
|
||||
func (fn GinLogWriteFunc) Write(data []byte) (int, error) {
|
||||
return fn(data)
|
||||
}
|
||||
|
||||
// NewGinLogrusWrite logrus writer for gin
|
||||
func NewGinLogrusWrite() io.Writer {
|
||||
return GinLogWriteFunc(func(data []byte) (int, error) {
|
||||
log.Debugf("%s", data)
|
||||
return 0, nil
|
||||
})
|
||||
}
|
||||
|
||||
// JSONLogMiddleware logs a gin HTTP request in JSON format, with some additional custom key/values
|
||||
func JSONLogMiddleware() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
// Start timer
|
||||
start := time.Now()
|
||||
|
||||
// Process Request
|
||||
c.Next()
|
||||
|
||||
// Stop timer
|
||||
duration := utils.GetDurationInMillseconds(start)
|
||||
|
||||
entry := log.WithFields(log.Fields{
|
||||
"client_ip": utils.GetIP(c.Request),
|
||||
"duration": fmt.Sprintf("%.2f", duration),
|
||||
"method": c.Request.Method,
|
||||
"path": c.Request.RequestURI,
|
||||
"status": c.Writer.Status(),
|
||||
"referrer": c.Request.Referer(),
|
||||
"request_id": c.Writer.Header().Get("Request-Id"),
|
||||
"authorizer_version": constants.VERSION,
|
||||
})
|
||||
|
||||
if c.Writer.Status() >= 500 {
|
||||
entry.Error(c.Errors.String())
|
||||
} else {
|
||||
entry.Info("")
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,15 +1,17 @@
|
|||
package routes
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"github.com/authorizerdev/authorizer/server/handlers"
|
||||
"github.com/authorizerdev/authorizer/server/middlewares"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// InitRouter initializes gin router
|
||||
func InitRouter() *gin.Engine {
|
||||
router := gin.Default()
|
||||
// router.Use(location.Default())
|
||||
gin.DefaultWriter = middlewares.NewGinLogrusWrite()
|
||||
router.Use(middlewares.JSONLogMiddleware())
|
||||
router.Use(middlewares.GinContextToContextMiddleware())
|
||||
router.Use(middlewares.CORSMiddleware())
|
||||
|
||||
|
|
12
server/utils/time.go
Normal file
12
server/utils/time.go
Normal file
|
@ -0,0 +1,12 @@
|
|||
package utils
|
||||
|
||||
import "time"
|
||||
|
||||
// GetDurationInMillseconds takes a start time and returns a duration in milliseconds
|
||||
func GetDurationInMillseconds(start time.Time) float64 {
|
||||
end := time.Now()
|
||||
duration := end.Sub(start)
|
||||
milliseconds := float64(duration) / float64(time.Millisecond)
|
||||
rounded := float64(int(milliseconds*100+.5)) / 100
|
||||
return rounded
|
||||
}
|
Loading…
Reference in New Issue
Block a user