Fix bug in preauthkeys: namespace object was not populated in the return

value from CreatePreAuthKey and GetPreAuthKeys. Add tests for that bug,
and the rest of the preauthkeys functionality.

Fix path in `compress` Makefile target.
This commit is contained in:
Ward Vandewege 2021-05-02 14:47:36 -04:00
parent 68c21faf64
commit b34e90c45d
7 changed files with 94 additions and 7 deletions

11
db.go
View file

@ -16,11 +16,13 @@ type KV struct {
}
func (h *Headscale) initDB() error {
db, err := gorm.Open("postgres", h.dbString)
db, err := gorm.Open(h.dbType, h.dbString)
if err != nil {
return err
}
db.Exec("create extension if not exists \"uuid-ossp\";")
if h.dbType == "postgres" {
db.Exec("create extension if not exists \"uuid-ossp\";")
}
db.AutoMigrate(&Machine{})
db.AutoMigrate(&KV{})
db.AutoMigrate(&Namespace{})
@ -32,10 +34,13 @@ func (h *Headscale) initDB() error {
}
func (h *Headscale) db() (*gorm.DB, error) {
db, err := gorm.Open("postgres", h.dbString)
db, err := gorm.Open(h.dbType, h.dbString)
if err != nil {
return nil, err
}
if h.dbDebug {
db.LogMode(true)
}
return db, nil
}