add sanitized flag to record, add Enrich() to record

pull/13/head
Simon Let 6 years ago
parent 7d968147c1
commit 939fb2f847
  1. 32
      common/resh-common.go
  2. 2
      sanitize-history/resh-sanitize-history.go

@ -1,6 +1,11 @@
package common package common
import "strconv" import (
"log"
"strconv"
"github.com/mattn/go-shellwords"
)
// Record representing single executed command with its metadata // Record representing single executed command with its metadata
type Record struct { type Record struct {
@ -65,7 +70,11 @@ type Record struct {
ReshRevision string `json:"reshRevision"` ReshRevision string `json:"reshRevision"`
// added by sanitizatizer // added by sanitizatizer
Sanitized bool `json:"sanitized"`
CmdLength int `json:"cmdLength"` CmdLength int `json:"cmdLength"`
// enriching fields - added "later"
FirstWord string `json:"firstWord"`
} }
// FallbackRecord when record is too old and can't be parsed into regular Record // FallbackRecord when record is too old and can't be parsed into regular Record
@ -131,9 +140,6 @@ type FallbackRecord struct {
ReshUuid string `json:"reshUuid"` ReshUuid string `json:"reshUuid"`
ReshVersion string `json:"reshVersion"` ReshVersion string `json:"reshVersion"`
ReshRevision string `json:"reshRevision"` ReshRevision string `json:"reshRevision"`
// added by sanitizatizer
CmdLength int `json:"cmdLength"`
} }
// ConvertRecord from FallbackRecord to Record // ConvertRecord from FallbackRecord to Record
@ -202,6 +208,24 @@ func ConvertRecord(r *FallbackRecord) Record {
} }
} }
// Enrich - adds additional fields to the record
func (r *Record) Enrich() {
// Get command/first word from commandline
r.FirstWord = GetCommandFromCommandLine(r.CmdLine)
}
// GetCommandFromCommandLine func
func GetCommandFromCommandLine(cmdLine string) string {
args, err := shellwords.Parse(cmdLine)
if err != nil {
log.Fatal("shellwords Error:", err)
}
if len(args) > 0 {
return args[0]
}
return ""
}
// Config struct // Config struct
type Config struct { type Config struct {
Port int Port int

@ -176,6 +176,8 @@ func (s *sanitizer) sanitizeRecord(record *common.Record) error {
if err != nil { if err != nil {
log.Fatal("Cmd:", record.CmdLine, "; sanitization error:", err) log.Fatal("Cmd:", record.CmdLine, "; sanitization error:", err)
} }
record.Sanitized = true
return nil return nil
} }

Loading…
Cancel
Save