From 4f6f9bf5314a60f119c35df7655ebfa814608fe7 Mon Sep 17 00:00:00 2001 From: mountain Date: Tue, 20 Jun 2023 11:18:32 +0900 Subject: [PATCH] =?UTF-8?q?whitelist=EB=A5=BC=20mg=EB=A1=9C=20=EC=9D=B4?= =?UTF-8?q?=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/maingate.go | 12 ++++++++++-- core/service.go | 11 ++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/core/maingate.go b/core/maingate.go index 6c94c87..d351838 100644 --- a/core/maingate.go +++ b/core/maingate.go @@ -175,8 +175,10 @@ type Maingate struct { auths *common.AuthCollection //services servicelist - serviceptr unsafe.Pointer - admins unsafe.Pointer + serviceptr unsafe.Pointer + admins unsafe.Pointer + wl whitelist + tokenEndpoints map[string]string authorizationEndpoints map[string]string userinfoEndpoint map[string]string @@ -422,6 +424,12 @@ func (mg *Maingate) prepare(context context.Context) (err error) { } } + var whites []whitelistmember + if err := mg.mongoClient.AllAs(CollectionWhitelist, &whites, options.Find().SetReturnKey(false)); err != nil { + return err + } + mg.wl.init(whites) + go watchAuthCollection(context, mg.auths, mg.mongoClient) go mg.watchWhitelistCollection(context) diff --git a/core/service.go b/core/service.go index 9373f7f..047f562 100644 --- a/core/service.go +++ b/core/service.go @@ -139,7 +139,7 @@ type serviceDescription struct { Admins []string `bson:"admins" json:"admins"` auths *common.AuthCollection - wl whitelist + wl *whitelist mongoClient common.MongoClient sessionTTL time.Duration serviceCodeBytes []byte @@ -250,20 +250,13 @@ func (sh *serviceDescription) prepare(mg *Maingate) error { sh.mongoClient = mg.mongoClient sh.auths = mg.auths sh.sessionTTL = time.Duration(mg.SessionTTL * int64(time.Second)) - sh.wl = whitelist{} sh.serviceCodeBytes, _ = hex.DecodeString(sh.ServiceCode) sh.getUserBrowserInfo = mg.GetUserBrowserInfo sh.getUserTokenWithCheck = mg.getUserTokenWithCheck sh.updateUserinfo = mg.updateUserinfo sh.getProviderInfo = mg.getProviderInfo - - var whites []whitelistmember - if err := mg.mongoClient.AllAs(CollectionWhitelist, &whites, options.Find().SetReturnKey(false)); err != nil { - return err - } - - sh.wl.init(whites) sh.admins = unsafe.Pointer(&sh.Admins) + sh.wl = &mg.wl bt, _ := json.Marshal(sh) atomic.StorePointer(&sh.serviceSerialized, unsafe.Pointer(&bt))