mirror of https://github.com/curusarn/resh
parent
e8072597c8
commit
ad4784de7d
@ -0,0 +1,12 @@ |
|||||||
|
package syncconnector |
||||||
|
|
||||||
|
import "github.com/curusarn/resh/internal/record" |
||||||
|
|
||||||
|
func (sc SyncConnector) getLatestRecord(machineId *string) (map[string]string, error) { |
||||||
|
return map[string]string{}, nil |
||||||
|
} |
||||||
|
|
||||||
|
func (sc SyncConnector) downloadRecords(lastRecords map[string]string) ([]record.V1, error) { |
||||||
|
var records []record.V1 |
||||||
|
return records, nil |
||||||
|
} |
||||||
@ -0,0 +1,54 @@ |
|||||||
|
package syncconnector |
||||||
|
|
||||||
|
import ( |
||||||
|
"github.com/curusarn/resh/internal/histcli" |
||||||
|
"github.com/curusarn/resh/internal/record" |
||||||
|
"github.com/curusarn/resh/internal/recordint" |
||||||
|
"go.uber.org/zap" |
||||||
|
"net/url" |
||||||
|
"time" |
||||||
|
) |
||||||
|
|
||||||
|
type SyncConnector struct { |
||||||
|
sugar *zap.SugaredLogger |
||||||
|
|
||||||
|
address *url.URL |
||||||
|
authToken string |
||||||
|
|
||||||
|
history *histcli.Histcli |
||||||
|
|
||||||
|
// TODO periodic push (or from the write channel)
|
||||||
|
// TODO push period
|
||||||
|
} |
||||||
|
|
||||||
|
func New(sugar *zap.SugaredLogger, address string, authToken string, pullPeriodSeconds int, history *histcli.Histcli) (*SyncConnector, error) { |
||||||
|
parsedAddress, err := url.Parse(address) |
||||||
|
if err != nil { |
||||||
|
return nil, err |
||||||
|
} |
||||||
|
|
||||||
|
sc := &SyncConnector{ |
||||||
|
sugar: sugar.With(zap.String("component", "syncConnector")), |
||||||
|
authToken: authToken, |
||||||
|
address: parsedAddress, |
||||||
|
history: history, |
||||||
|
} |
||||||
|
|
||||||
|
// TODO: propagate signals
|
||||||
|
go func(sc *SyncConnector) { |
||||||
|
for _ = range time.Tick(time.Second * time.Duration(pullPeriodSeconds)) { |
||||||
|
sc.sugar.Infow("checking remote") |
||||||
|
|
||||||
|
// Add fake record (this will be produced by the sync connector)
|
||||||
|
sc.history.AddRecord(&recordint.Indexed{ |
||||||
|
Rec: record.V1{ |
||||||
|
CmdLine: "__fake_test__", |
||||||
|
DeviceID: "__test__", |
||||||
|
}, |
||||||
|
}) |
||||||
|
|
||||||
|
} |
||||||
|
}(sc) |
||||||
|
|
||||||
|
return sc, nil |
||||||
|
} |
||||||
@ -0,0 +1,49 @@ |
|||||||
|
package syncconnector |
||||||
|
|
||||||
|
import ( |
||||||
|
"github.com/curusarn/resh/internal/recordint" |
||||||
|
) |
||||||
|
|
||||||
|
func (sc SyncConnector) write(collect chan recordint.Collect) { |
||||||
|
//for {
|
||||||
|
// func() {
|
||||||
|
// select {
|
||||||
|
// case rec := <-collect:
|
||||||
|
// part := "2"
|
||||||
|
// if rec.Rec.PartOne {
|
||||||
|
// part = "1"
|
||||||
|
// }
|
||||||
|
// sugar := h.sugar.With(
|
||||||
|
// "recordCmdLine", rec.Rec.CmdLine,
|
||||||
|
// "recordPart", part,
|
||||||
|
// "recordShell", rec.Shell,
|
||||||
|
// )
|
||||||
|
// sc.sugar.Debugw("Got record")
|
||||||
|
// h.sessionsMutex.Lock()
|
||||||
|
// defer h.sessionsMutex.Unlock()
|
||||||
|
//
|
||||||
|
// // allows nested sessions to merge records properly
|
||||||
|
// mergeID := rec.SessionID + "_" + strconv.Itoa(rec.Shlvl)
|
||||||
|
// sugar = sc.sugar.With("mergeID", mergeID)
|
||||||
|
// if rec.Rec.PartOne {
|
||||||
|
// if _, found := h.sessions[mergeID]; found {
|
||||||
|
// msg := "Got another first part of the records before merging the previous one - overwriting!"
|
||||||
|
// if rec.Shell == "zsh" {
|
||||||
|
// sc.sugar.Warnw(msg)
|
||||||
|
// } else {
|
||||||
|
// sc.sugar.Infow(msg + " Unfortunately this is normal in bash, it can't be prevented.")
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// h.sessions[mergeID] = rec
|
||||||
|
// } else {
|
||||||
|
// if part1, found := h.sessions[mergeID]; found == false {
|
||||||
|
// sc.sugar.Warnw("Got second part of record and nothing to merge it with - ignoring!")
|
||||||
|
// } else {
|
||||||
|
// delete(h.sessions, mergeID)
|
||||||
|
// go h.mergeAndWriteRecord(sugar, part1, rec)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }()
|
||||||
|
//}
|
||||||
|
} |
||||||
Loading…
Reference in new issue