fix null source in mizu fetch

fix null source in mizu fetch
This commit is contained in:
RamiBerm 2021-07-06 13:55:26 +03:00 committed by GitHub
commit 672accba0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View File

@ -93,13 +93,16 @@ func GetHARs(c *fiber.Ctx) error {
harEntry.Request.URL = utils.SetHostname(harEntry.Request.URL, entryData.ResolvedDestination) harEntry.Request.URL = utils.SetHostname(harEntry.Request.URL, entryData.ResolvedDestination)
} }
var fileName string
sourceOfEntry := entryData.ResolvedSource sourceOfEntry := entryData.ResolvedSource
if sourceOfEntry != "" { if sourceOfEntry != "" {
// naively assumes the proper service source is http // naively assumes the proper service source is http
sourceOfEntry = fmt.Sprintf("http://%s", sourceOfEntry) sourceOfEntry = fmt.Sprintf("http://%s", sourceOfEntry)
//replace / from the file name cause they end up creating a corrupted folder
fileName = fmt.Sprintf("%s.har", strings.ReplaceAll(sourceOfEntry, "/", "_"))
} else {
fileName = "unknown_source.har"
} }
//replace / from the file name cause they end up creating a corrupted folder
fileName := fmt.Sprintf("%s.har", strings.ReplaceAll(sourceOfEntry, "/", "_"))
if harOfSource, ok := harsObject[fileName]; ok { if harOfSource, ok := harsObject[fileName]; ok {
harOfSource.Log.Entries = append(harOfSource.Log.Entries, &harEntry) harOfSource.Log.Entries = append(harOfSource.Log.Entries, &harEntry)
} else { } else {
@ -119,7 +122,7 @@ func GetHARs(c *fiber.Ctx) error {
} }
// leave undefined when no source is present, otherwise modeler assumes source is empty string "" // leave undefined when no source is present, otherwise modeler assumes source is empty string ""
if sourceOfEntry != "" { if sourceOfEntry != "" {
harsObject[fileName].Log.Creator.Source = sourceOfEntry harsObject[fileName].Log.Creator.Source = &sourceOfEntry
} }
} }
} }

View File

@ -105,5 +105,5 @@ type ExtendedLog struct {
type ExtendedCreator struct { type ExtendedCreator struct {
*har.Creator *har.Creator
Source string `json:"_source"` Source *string `json:"_source"`
} }