From 1191fdf97d6a4d9519a063cba0a622b58e1b1328 Mon Sep 17 00:00:00 2001 From: Zachary Huff Date: Sun, 14 Jul 2019 01:23:16 -0400 Subject: [PATCH] Fix invalid service records in init --- service/service.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/service/service.go b/service/service.go index 4e356d2a..81a0381b 100644 --- a/service/service.go +++ b/service/service.go @@ -7,9 +7,11 @@ import ( "github.com/dropbox/godropbox/container/set" "github.com/dropbox/godropbox/errors" + "github.com/pritunl/mongo-go-driver/bson" "github.com/pritunl/mongo-go-driver/bson/primitive" "github.com/pritunl/pritunl-zero/database" "github.com/pritunl/pritunl-zero/errortypes" + "github.com/pritunl/pritunl-zero/requires" "github.com/pritunl/pritunl-zero/utils" ) @@ -174,3 +176,35 @@ func (s *Service) Insert(db *database.Database) (err error) { return } + +func init() { + module := requires.New("service") + module.After("settings") + + module.Handler = func() (err error) { + db := database.GetDatabase() + defer db.Close() + + coll := db.Services() + + _, err = coll.UpdateMany(db, &bson.M{ + "domains": nil, + "roles": nil, + "servers": nil, + "whitelist_networks": nil, + }, &bson.M{ + "$set": &bson.M{ + "domains": []interface{}{}, + "roles": []interface{}{}, + "servers": []interface{}{}, + "whitelist_networks": []interface{}{}, + }, + }) + if err != nil { + err = database.ParseError(err) + return + } + + return + } +}