Fixes for bugs in MySQL migration (#501)

* Fix users table name in MySQL ListUsers
* Fix invalid SQL
* Implement MarkHostSeen
* Partial fix for targets autocompletion
This commit is contained in:
Zachary Wasserman 2016-11-16 15:12:59 -08:00 committed by GitHub
parent 34625ce4d0
commit eff7f60dc2
5 changed files with 23 additions and 7 deletions

View file

@ -191,8 +191,20 @@ func (d *Datastore) AuthenticateHost(nodeKey string) (*kolide.Host, error) {
}
func (d *Datastore) MarkHostSeen(*kolide.Host, time.Time) error {
panic("not implemented")
func (d *Datastore) MarkHostSeen(host *kolide.Host, t time.Time) error {
sqlStatement := `
UPDATE hosts SET
updated_at = ?
WHERE node_key=?
`
_, err := d.db.Exec(sqlStatement, t, host.NodeKey)
if err != nil {
return errors.DatabaseError(err)
}
host.UpdatedAt = t
return nil
}
func (d *Datastore) searchHostsWithOmits(query string, omits ...uint) ([]kolide.Host, error) {

View file

@ -181,6 +181,10 @@ func (d *Datastore) ListHostsInLabel(lid uint) ([]kolide.Host, error) {
}
func (d *Datastore) ListUniqueHostsInLabels(labels []uint) ([]kolide.Host, error) {
if len(labels) == 0 {
return []kolide.Host{}, nil
}
sqlStatement := `
SELECT h.*
FROM label_query_executions lqe

View file

@ -8,7 +8,7 @@ import (
func (d *Datastore) SessionByKey(key string) (*kolide.Session, error) {
sqlStatement := `
SELECT * FROM sessions
WHERE key = ? LIMIT 1
WHERE ` + "`key`" + ` = ? LIMIT 1
`
session := &kolide.Session{}
err := d.db.Get(session, sqlStatement, key)
@ -53,9 +53,9 @@ func (d *Datastore) NewSession(session *kolide.Session) (*kolide.Session, error)
sqlStatement := `
INSERT INTO sessions (
user_id,
key
` + "`key`" + `
)
VALUES(?,?,?,?)
VALUES(?,?)
`
result, err := d.db.Exec(sqlStatement, session.UserID, session.Key)
if err != nil {

View file

@ -60,7 +60,7 @@ func (d *Datastore) User(username string) (*kolide.User, error) {
// kolide.ListOptions
func (d *Datastore) ListUsers(opt kolide.ListOptions) ([]*kolide.User, error) {
sqlStatement := `
SELECT * FROM USERS WHERE NOT deleted
SELECT * FROM users WHERE NOT deleted
`
sqlStatement = appendListOptionsToSQL(sqlStatement, opt)
users := []*kolide.User{}

View file

@ -71,7 +71,7 @@ type Session struct {
CreateTimestamp
ID uint
AccessedAt time.Time `db:"accessed_at"`
UserID uint
UserID uint `db:"user_id"`
Key string
}