mirror of
https://github.com/ddworken/hishtory.git
synced 2025-02-02 11:39:24 +01:00
Add data types for custom columns
This commit is contained in:
parent
51b41aa171
commit
12163483dd
@ -6,6 +6,7 @@ import (
|
||||
"crypto/hmac"
|
||||
"crypto/rand"
|
||||
"crypto/sha256"
|
||||
"database/sql/driver"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@ -25,15 +26,36 @@ const (
|
||||
)
|
||||
|
||||
type HistoryEntry struct {
|
||||
LocalUsername string `json:"local_username" gorm:"uniqueIndex:compositeindex"`
|
||||
Hostname string `json:"hostname" gorm:"uniqueIndex:compositeindex"`
|
||||
Command string `json:"command" gorm:"uniqueIndex:compositeindex"`
|
||||
CurrentWorkingDirectory string `json:"current_working_directory" gorm:"uniqueIndex:compositeindex"`
|
||||
HomeDirectory string `json:"home_directory" gorm:"uniqueIndex:compositeindex"`
|
||||
ExitCode int `json:"exit_code" gorm:"uniqueIndex:compositeindex"`
|
||||
StartTime time.Time `json:"start_time" gorm:"uniqueIndex:compositeindex"`
|
||||
EndTime time.Time `json:"end_time" gorm:"uniqueIndex:compositeindex"`
|
||||
DeviceId string `json:"device_id" gorm:"uniqueIndex:compositeindex"`
|
||||
LocalUsername string `json:"local_username" gorm:"uniqueIndex:compositeindex"`
|
||||
Hostname string `json:"hostname" gorm:"uniqueIndex:compositeindex"`
|
||||
Command string `json:"command" gorm:"uniqueIndex:compositeindex"`
|
||||
CurrentWorkingDirectory string `json:"current_working_directory" gorm:"uniqueIndex:compositeindex"`
|
||||
HomeDirectory string `json:"home_directory" gorm:"uniqueIndex:compositeindex"`
|
||||
ExitCode int `json:"exit_code" gorm:"uniqueIndex:compositeindex"`
|
||||
StartTime time.Time `json:"start_time" gorm:"uniqueIndex:compositeindex"`
|
||||
EndTime time.Time `json:"end_time" gorm:"uniqueIndex:compositeindex"`
|
||||
DeviceId string `json:"device_id" gorm:"uniqueIndex:compositeindex"`
|
||||
CustomColumns CustomColumns `json:"custom_columns"`
|
||||
}
|
||||
|
||||
type CustomColumns []CustomColumns
|
||||
|
||||
type CustomColumn struct {
|
||||
Name string `json:"name"`
|
||||
Val string `json:"value"`
|
||||
}
|
||||
|
||||
func (c *CustomColumns) Scan(value interface{}) error {
|
||||
bytes, ok := value.([]byte)
|
||||
if !ok {
|
||||
return fmt.Errorf("failed to unmarshal CustomColumns value %#v", value)
|
||||
}
|
||||
|
||||
return json.Unmarshal(bytes, c)
|
||||
}
|
||||
|
||||
func (c CustomColumns) Value() (driver.Value, error) {
|
||||
return json.Marshal(c)
|
||||
}
|
||||
|
||||
func (h *HistoryEntry) GoString() string {
|
||||
|
@ -70,3 +70,23 @@ func TestParseTimeGenerously(t *testing.T) {
|
||||
t.Fatalf("parsed time incorrectly: %d", ts.Unix())
|
||||
}
|
||||
}
|
||||
|
||||
func TestCustomColumnSerialization(t *testing.T) {
|
||||
// cc1 := CustomColumn{
|
||||
// Name: "name1",
|
||||
// Val: "val1",
|
||||
// }
|
||||
// cc2 := CustomColumn{
|
||||
// Name: "name2",
|
||||
// Val: "val2",
|
||||
// }
|
||||
var ccs CustomColumns = make(CustomColumns, 0)
|
||||
v, err := ccs.Value()
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
}
|
||||
val := string(v.([]uint8))
|
||||
if val != "[]" {
|
||||
t.Fatalf("unexpected val for empty CustomColumns: %#v", val)
|
||||
}
|
||||
}
|
||||
|
@ -160,6 +160,13 @@ type ClientConfig struct {
|
||||
ControlRSearchEnabled bool `json:"enable_control_r_search"`
|
||||
// The set of columns that the user wants to be displayed
|
||||
DisplayedColumns []string `json:"displayed_columns"`
|
||||
// Custom columns
|
||||
CustomColumns []CustomColumnDefinition `json:"custom_columns"`
|
||||
}
|
||||
|
||||
type CustomColumnDefinition struct {
|
||||
ColumnName string `json:"column_name"`
|
||||
ColumnCommand string `json:"column_command"`
|
||||
}
|
||||
|
||||
func GetConfigContents() ([]byte, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user