From 827abf34fee4283d6a474d1ccb5c2ebea0991c77 Mon Sep 17 00:00:00 2001 From: mountain Date: Tue, 30 May 2023 16:30:01 +0900 Subject: [PATCH] =?UTF-8?q?email=20=EC=A3=BC=EC=86=8C=EB=A5=BC=20=EC=A0=9C?= =?UTF-8?q?=EB=8C=80=EB=A1=9C=20=EB=AA=BB=EC=9D=BD=EB=8A=94=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/api.go | 2 +- core/service.go | 24 +++++++++++++++--------- core/watch.go | 2 -- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/core/api.go b/core/api.go index c4b9202..532613f 100644 --- a/core/api.go +++ b/core/api.go @@ -123,7 +123,7 @@ func (caller apiCaller) getAccessableServices() ([]*serviceDescription, []string return nil, nil } - email := v.(string) + email = v.(string) _, admin = caller.admins[email] } diff --git a/core/service.go b/core/service.go index 977d348..2b43d0f 100644 --- a/core/service.go +++ b/core/service.go @@ -166,10 +166,10 @@ type maintenance struct { } type division struct { - Url string `bson:"url"` - Priority int `bson:"priority"` - State divisionStateName `bson:"state"` - Maintenance *maintenance `bson:"maintenance"` + Url string // 요것은 클라이언트 빌드하고 나서 json:"-"으로 변경하자. 클라이언트에 직접 내려보내지 않음 + Priority int + State divisionStateName + Maintenance *maintenance `bson:",omitempty" json:",omitempty"` } type serviceDescription struct { @@ -307,9 +307,10 @@ func (sh *serviceDescription) prepare(mg *Maingate) error { if len(sh.ApiUsers) == 0 { sh.ApiUsers = map[string][]string{ - "service": {}, - "whitelist": {}, - "account": {}, + "service": {}, + "whitelist": {}, + "account": {}, + "maintenance": {}, } } parsedUsers := make(map[string]map[string]bool) @@ -329,7 +330,7 @@ func (sh *serviceDescription) prepare(mg *Maingate) error { bt, _ := json.Marshal(sh) atomic.StorePointer(&sh.serviceSerialized, unsafe.Pointer(&bt)) - logger.Println("service is ready :", sh.ServiceName, sh.ServiceCode, sh.UseWhitelist, string(divmarshaled)) + logger.Println("service is ready :", sh.ServiceName, sh.ServiceCode, sh.UseWhitelist, sh.ApiUsers, string(divmarshaled)) return nil } @@ -472,12 +473,17 @@ func (sh *serviceDescription) isValidAPIUser(category string, email string) bool return true } } - } else if users, ok := catusers[category]; ok { + logger.Println("isValidAPIUser failed. email is not allowed :", category, email, catusers) + return false + } + + if users, ok := catusers[category]; ok { if _, ok := users[email]; ok { return true } logger.Println("isValidAPIUser failed. email is not allowed :", category, email, users) + return false } logger.Println("isValidAPIUser failed. category is missing :", category) diff --git a/core/watch.go b/core/watch.go index 44ee9f2..738706d 100644 --- a/core/watch.go +++ b/core/watch.go @@ -263,8 +263,6 @@ func (mg *Maingate) watchServiceCollection(parentctx context.Context, serveMux * case "update": data.Service.prepare(mg) if old := mg.services.get(data.Service.ServiceName); old != nil { - logger.Printf("service is changed : %v", data.Service) - atomic.SwapPointer(&old.divisionsSerialized, data.Service.divisionsSerialized) atomic.SwapPointer(&old.apiUsers, data.Service.apiUsers) atomic.SwapPointer(&old.serviceSerialized, data.Service.serviceSerialized)