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)