mirror of
https://github.com/ddworken/hishtory.git
synced 2025-06-20 11:57:50 +02:00
Add reupload command + include source_device_id query param when submitting entries
This commit is contained in:
parent
f7a1e14451
commit
52c3b13cb6
@ -245,12 +245,15 @@ func testIntegrationWithNewDevice(t *testing.T, tester shellTester) {
|
|||||||
t.Fatalf("hishtory query doesn't contain cmd run on another machine! out=%#v", out)
|
t.Fatalf("hishtory query doesn't contain cmd run on another machine! out=%#v", out)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Run a reupload just to test that flow
|
||||||
|
tester.RunInteractiveShell(t, "hishtory reupload")
|
||||||
|
|
||||||
// Finally, test the export command
|
// Finally, test the export command
|
||||||
out = tester.RunInteractiveShell(t, `hishtory export | grep -v pipefail | grep -v '/tmp/client install'`)
|
out = tester.RunInteractiveShell(t, `hishtory export | grep -v pipefail | grep -v '/tmp/client install'`)
|
||||||
if strings.Contains(out, "thisisnotrecorded") {
|
if strings.Contains(out, "thisisnotrecorded") {
|
||||||
t.Fatalf("hishtory export contains a command that should not have been recorded, out=%#v", out)
|
t.Fatalf("hishtory export contains a command that should not have been recorded, out=%#v", out)
|
||||||
}
|
}
|
||||||
expectedOutputWithoutKey := "hishtory status\nhishtory query\nls /a\nls /bar\nls /foo\necho foo\necho bar\nhishtory enable\necho thisisrecorded\nhishtory query\nhishtory query foo\necho hello | grep complex | sed s/h/i/g; echo baz && echo \"fo 'o\"\nhishtory query complex\nhishtory query\necho mynewcommand\nhishtory query\nyes | hishtory init %s\nhishtory query\necho mynewercommand\nhishtory query\nothercomputer\nhishtory query\n"
|
expectedOutputWithoutKey := "hishtory status\nhishtory query\nls /a\nls /bar\nls /foo\necho foo\necho bar\nhishtory enable\necho thisisrecorded\nhishtory query\nhishtory query foo\necho hello | grep complex | sed s/h/i/g; echo baz && echo \"fo 'o\"\nhishtory query complex\nhishtory query\necho mynewcommand\nhishtory query\nyes | hishtory init %s\nhishtory query\necho mynewercommand\nhishtory query\nothercomputer\nhishtory query\nhishtory reupload\n"
|
||||||
expectedOutput := fmt.Sprintf(expectedOutputWithoutKey, userSecret)
|
expectedOutput := fmt.Sprintf(expectedOutputWithoutKey, userSecret)
|
||||||
if diff := cmp.Diff(expectedOutput, out); diff != "" {
|
if diff := cmp.Diff(expectedOutput, out); diff != "" {
|
||||||
t.Fatalf("hishtory export mismatch (-expected +got):\n%s\nout=%#v", diff, out)
|
t.Fatalf("hishtory export mismatch (-expected +got):\n%s\nout=%#v", diff, out)
|
||||||
|
16
hishtory.go
16
hishtory.go
@ -107,6 +107,18 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to update hishtory: %v", err)
|
log.Fatalf("Failed to update hishtory: %v", err)
|
||||||
}
|
}
|
||||||
|
case "reupload":
|
||||||
|
// Purposefully undocumented since this command is generally not necessary to run
|
||||||
|
ctx := hctx.MakeContext()
|
||||||
|
config := hctx.GetConf(ctx)
|
||||||
|
entries, err := data.Search(hctx.GetDb(ctx), "", 0)
|
||||||
|
lib.CheckFatalError(err)
|
||||||
|
for _, entry := range entries {
|
||||||
|
jsonValue, err := lib.EncryptAndMarshal(config, entry)
|
||||||
|
lib.CheckFatalError(err)
|
||||||
|
_, err = lib.ApiPost("/api/v1/submit?source_device_id="+config.DeviceId, "application/json", jsonValue)
|
||||||
|
lib.CheckFatalError(err)
|
||||||
|
}
|
||||||
case "-h":
|
case "-h":
|
||||||
fallthrough
|
fallthrough
|
||||||
case "help":
|
case "help":
|
||||||
@ -265,7 +277,7 @@ func maybeUploadSkippedHistoryEntries(ctx *context.Context) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = lib.ApiPost("/api/v1/submit", "application/json", jsonValue)
|
_, err = lib.ApiPost("/api/v1/submit?source_device_id="+config.DeviceId, "application/json", jsonValue)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Failed to upload the history entry, so we must still be offline. So just return nil and we'll try again later.
|
// Failed to upload the history entry, so we must still be offline. So just return nil and we'll try again later.
|
||||||
return nil
|
return nil
|
||||||
@ -303,7 +315,7 @@ func saveHistoryEntry(ctx *context.Context) {
|
|||||||
// Persist it remotely
|
// Persist it remotely
|
||||||
jsonValue, err := lib.EncryptAndMarshal(config, entry)
|
jsonValue, err := lib.EncryptAndMarshal(config, entry)
|
||||||
lib.CheckFatalError(err)
|
lib.CheckFatalError(err)
|
||||||
_, err = lib.ApiPost("/api/v1/submit", "application/json", jsonValue)
|
_, err = lib.ApiPost("/api/v1/submit?source_device_id="+config.DeviceId, "application/json", jsonValue)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if lib.IsOfflineError(err) {
|
if lib.IsOfflineError(err) {
|
||||||
hctx.GetLogger().Printf("Failed to remotely persist hishtory entry because the device is offline!")
|
hctx.GetLogger().Printf("Failed to remotely persist hishtory entry because the device is offline!")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user