feat: add support for database cert, key, ca-cert

This commit is contained in:
Lakhan Samani
2022-04-23 17:52:02 +05:30
parent 4778827545
commit 075c287f34
12 changed files with 163 additions and 35 deletions

View File

@@ -1,12 +1,7 @@
package utils
import (
"log"
"reflect"
"github.com/authorizerdev/authorizer/server/db"
"github.com/authorizerdev/authorizer/server/db/models"
"github.com/gin-gonic/gin"
)
// StringSliceContains checks if a string slice contains a particular string
@@ -19,23 +14,6 @@ func StringSliceContains(s []string, e string) bool {
return false
}
// SaveSessionInDB saves sessions generated for a given user with meta information
// Do not store token here as that could be security breach
func SaveSessionInDB(c *gin.Context, userId string) {
sessionData := models.Session{
UserID: userId,
UserAgent: GetUserAgent(c.Request),
IP: GetIP(c.Request),
}
err := db.Provider.AddSession(sessionData)
if err != nil {
log.Println("=> error saving session in db:", err)
} else {
log.Println("=> session saved in db:", sessionData)
}
}
// RemoveDuplicateString removes duplicate strings from a string slice
func RemoveDuplicateString(strSlice []string) []string {
allKeys := make(map[string]bool)

48
server/utils/file.go Normal file
View File

@@ -0,0 +1,48 @@
package utils
import (
"errors"
"os"
)
// CreateFolder creates a folder in Current working dir
func CreateFolder(dir string) (string, error) {
pwd, err := os.Getwd()
if err != nil {
return "", err
}
path := pwd + "/" + dir
err = os.Mkdir(path, 0o755)
if err == nil {
return path, nil
}
if os.IsExist(err) {
// check that the existing path is a directory
info, err := os.Stat(path)
if err != nil {
return "", err
}
if !info.IsDir() {
return "", errors.New("path exists but is not a directory")
}
return path, nil
}
return path, err
}
// CreateFile creates a file on given path with given content
func CreateFile(filePath string, content string) error {
f, err := os.Create(filePath)
if err != nil {
return err
}
defer f.Close()
_, err = f.WriteString(content)
if err != nil {
return err
}
return nil
}