mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-08-02 00:57:45 +00:00
no message
This commit is contained in:
parent
3728ee08d6
commit
d715473088
@ -7,13 +7,32 @@ import (
|
||||
"mizuserver/src/pkg/database"
|
||||
"mizuserver/src/pkg/models"
|
||||
"mizuserver/src/pkg/utils"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func GetEntries(c *fiber.Ctx) error {
|
||||
var baseEntries []models.BaseEntryDetails
|
||||
database.EntriesTable.
|
||||
Find(&baseEntries).
|
||||
Limit(100)
|
||||
limit, e := strconv.Atoi(c.Query("limit", "100"))
|
||||
utils.CheckErr(e)
|
||||
|
||||
var entries []models.MizuEntry
|
||||
database.GetEntriesTable().
|
||||
Omit("entry"). // remove the "big" entry field
|
||||
Limit(limit).
|
||||
Find(&entries)
|
||||
|
||||
// Convert to base entries
|
||||
baseEntries := make([]models.BaseEntryDetails, 0)
|
||||
for _, entry := range entries {
|
||||
baseEntries = append(baseEntries, models.BaseEntryDetails{
|
||||
Id: entry.EntryId,
|
||||
Url: entry.Url,
|
||||
Service: entry.Service,
|
||||
Path: entry.Path,
|
||||
Status: entry.Status,
|
||||
Method: entry.Method,
|
||||
Timestamp: entry.Timestamp,
|
||||
})
|
||||
}
|
||||
|
||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||
"error": false,
|
||||
@ -21,15 +40,14 @@ func GetEntries(c *fiber.Ctx) error {
|
||||
})
|
||||
}
|
||||
|
||||
func GetEntry(c *fiber.Ctx) error {
|
||||
|
||||
func GetEntry(c *fiber.Ctx) error {
|
||||
var entryData models.EntryData
|
||||
database.EntriesTable.
|
||||
database.GetEntriesTable().
|
||||
Select("entry").
|
||||
Where(map[string]string{"entryId": c.Params("entryId")}).
|
||||
First(&entryData)
|
||||
|
||||
// TODO: check why don't we get entry here
|
||||
var fullEntry har.Entry
|
||||
unmarshallErr := json.Unmarshal([]byte(entryData.Entry), &fullEntry)
|
||||
utils.CheckErr(unmarshallErr)
|
||||
|
@ -12,9 +12,12 @@ const (
|
||||
|
||||
var (
|
||||
DB = initDataBase(DBPath)
|
||||
EntriesTable = DB.Table("mizu_entries")
|
||||
)
|
||||
|
||||
func GetEntriesTable() *gorm.DB{
|
||||
return DB.Table("mizu_entries")
|
||||
}
|
||||
|
||||
func initDataBase(databasePath string) *gorm.DB {
|
||||
temp, _ := gorm.Open(sqlite.Open(databasePath), &gorm.Config{})
|
||||
_ = temp.AutoMigrate(&models.MizuEntry{}) // this will ensure table is created
|
||||
|
@ -6,30 +6,27 @@ import (
|
||||
|
||||
type MizuEntry struct {
|
||||
gorm.Model
|
||||
// TODO: map id to _id?
|
||||
Entry string `json:"entry,omitempty" gorm:"column:entry"`
|
||||
EntryId string `json:"entryId" gorm:"column:entryId"`
|
||||
Url string `json:"url" gorm:"column:url"`
|
||||
Method string `json:"method" gorm:"column:method"`
|
||||
Status int `json:"status" gorm:"column:status"`
|
||||
Source string `json:"source" gorm:"column:source"`
|
||||
ServiceName string `json:"serviceName" gorm:"column:serviceName"`
|
||||
Timestamp int64 `json:"timestamp" gorm:"column:timestamp"`
|
||||
Path string `json:"path" gorm:"column:path"`
|
||||
Entry string `json:"entry,omitempty" gorm:"column:entry"`
|
||||
EntryId string `json:"entryId" gorm:"column:entryId"`
|
||||
Url string `json:"url" gorm:"column:url"`
|
||||
Method string `json:"method" gorm:"column:method"`
|
||||
Status int `json:"status" gorm:"column:status"`
|
||||
Source string `json:"source" gorm:"column:source"`
|
||||
Service string `json:"service" gorm:"column:service"`
|
||||
Timestamp int64 `json:"timestamp" gorm:"column:timestamp"`
|
||||
Path string `json:"path" gorm:"column:path"`
|
||||
}
|
||||
|
||||
type BaseEntryDetails struct {
|
||||
Id string `json:"id,omitempty"` // TODO: can be removed
|
||||
EntryId string `json:"entryId,omitempty" gorm:"column:entryId"`
|
||||
Url string `json:"url,omitempty"`
|
||||
ServiceName string `json:"serviceName,omitempty" gorm:"column:serviceName"`
|
||||
Path string `json:"path,omitempty"`
|
||||
Status int `json:"status,omitempty"`
|
||||
Method string `json:"method,omitempty"`
|
||||
Timestamp int64 `json:"timestamp,omitempty"`
|
||||
Id string `json:"id,omitempty"`
|
||||
Url string `json:"url,omitempty"`
|
||||
Service string `json:"service,omitempty"`
|
||||
Path string `json:"path,omitempty"`
|
||||
Status int `json:"status,omitempty"`
|
||||
Method string `json:"method,omitempty"`
|
||||
Timestamp int64 `json:"timestamp,omitempty"`
|
||||
}
|
||||
|
||||
|
||||
type EntryData struct {
|
||||
Entry string `json:"entry,omitempty"`
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ func StartServer(app *fiber.App) {
|
||||
|
||||
func CheckErr(e error) {
|
||||
if e != nil {
|
||||
panic(e)
|
||||
log.Printf("%v", e)
|
||||
//panic(e)
|
||||
}
|
||||
}
|
@ -39,17 +39,17 @@ func SaveHarToDb(entry har.Entry, source string) {
|
||||
entryBytes, _ := json.Marshal(entry)
|
||||
serviceName, urlPath := getServiceNameFromUrl(entry.Request.URL)
|
||||
mizuEntry := models.MizuEntry{
|
||||
EntryId: primitive.NewObjectID().Hex(),
|
||||
Entry: string(entryBytes), // simple way to store it and not convert to bytes
|
||||
ServiceName: serviceName,
|
||||
Url: entry.Request.URL,
|
||||
Path: urlPath,
|
||||
Method: entry.Request.Method,
|
||||
Status: entry.Response.Status,
|
||||
Source: source,
|
||||
Timestamp: entry.StartedDateTime.Unix(),
|
||||
EntryId: primitive.NewObjectID().Hex(),
|
||||
Entry: string(entryBytes), // simple way to store it and not convert to bytes
|
||||
Service: serviceName,
|
||||
Url: entry.Request.URL,
|
||||
Path: urlPath,
|
||||
Method: entry.Request.Method,
|
||||
Status: entry.Response.Status,
|
||||
Source: source,
|
||||
Timestamp: entry.StartedDateTime.Unix(),
|
||||
}
|
||||
database.EntriesTable.Create(&mizuEntry)
|
||||
database.GetEntriesTable().Create(&mizuEntry)
|
||||
}
|
||||
|
||||
func getServiceNameFromUrl(inputUrl string) (string, string) {
|
||||
|
Loading…
Reference in New Issue
Block a user