api 호출 권한 일단 보류
This commit is contained in:
65
core/api.go
65
core/api.go
@ -104,10 +104,10 @@ func (caller apiCaller) isAdminOrValidToken() bool {
|
|||||||
|
|
||||||
func (caller apiCaller) filesAPI(w http.ResponseWriter, r *http.Request) error {
|
func (caller apiCaller) filesAPI(w http.ResponseWriter, r *http.Request) error {
|
||||||
if r.Method == "GET" {
|
if r.Method == "GET" {
|
||||||
if !caller.isAdminOrValidToken() {
|
// if !caller.isAdminOrValidToken() {
|
||||||
w.WriteHeader(http.StatusUnauthorized)
|
// w.WriteHeader(http.StatusUnauthorized)
|
||||||
return nil
|
// return nil
|
||||||
}
|
// }
|
||||||
|
|
||||||
allfiles, err := caller.mg.mongoClient.All(CollectionFile, options.Find().SetProjection(bson.M{
|
allfiles, err := caller.mg.mongoClient.All(CollectionFile, options.Find().SetProjection(bson.M{
|
||||||
"contents": 0,
|
"contents": 0,
|
||||||
@ -127,10 +127,10 @@ func (caller apiCaller) filesAPI(w http.ResponseWriter, r *http.Request) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if !caller.isAdminOrValidToken() {
|
// if !caller.isAdminOrValidToken() {
|
||||||
w.WriteHeader(http.StatusUnauthorized)
|
// w.WriteHeader(http.StatusUnauthorized)
|
||||||
return nil
|
// return nil
|
||||||
}
|
// }
|
||||||
|
|
||||||
_, err := caller.mg.mongoClient.Delete(CollectionFile, bson.M{
|
_, err := caller.mg.mongoClient.Delete(CollectionFile, bson.M{
|
||||||
"key": key,
|
"key": key,
|
||||||
@ -211,33 +211,26 @@ func (caller apiCaller) whitelistAPI(w http.ResponseWriter, r *http.Request) err
|
|||||||
mg := caller.mg
|
mg := caller.mg
|
||||||
queryvals := r.URL.Query()
|
queryvals := r.URL.Query()
|
||||||
if r.Method == "GET" {
|
if r.Method == "GET" {
|
||||||
service := queryvals.Get("service")
|
// if !caller.isAdminOrValidToken() {
|
||||||
if len(service) > 0 {
|
// logger.Println("whitelistAPI failed. not vaild user :", r.Method, caller.userinfo)
|
||||||
if !caller.isAdminOrValidToken() {
|
// w.WriteHeader(http.StatusUnauthorized)
|
||||||
logger.Println("whitelistAPI failed. not vaild user :", r.Method, caller.userinfo)
|
// return nil
|
||||||
w.WriteHeader(http.StatusUnauthorized)
|
// }
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
all, err := mg.mongoClient.FindAll(CollectionWhitelist, bson.M{
|
all, err := mg.mongoClient.All(CollectionWhitelist)
|
||||||
"service": service,
|
if err != nil {
|
||||||
})
|
return err
|
||||||
if err != nil {
|
}
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(all) > 0 {
|
if len(all) > 0 {
|
||||||
var notexp []primitive.M
|
var notexp []primitive.M
|
||||||
for _, v := range all {
|
for _, v := range all {
|
||||||
if _, exp := v["_ts"]; !exp {
|
if _, exp := v["_ts"]; !exp {
|
||||||
notexp = append(notexp, v)
|
notexp = append(notexp, v)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
allraw, _ := json.Marshal(notexp)
|
|
||||||
w.Write(allraw)
|
|
||||||
}
|
}
|
||||||
} else {
|
allraw, _ := json.Marshal(notexp)
|
||||||
logger.Println("service param is missing")
|
w.Write(allraw)
|
||||||
}
|
}
|
||||||
} else if r.Method == "PUT" {
|
} else if r.Method == "PUT" {
|
||||||
body, _ := io.ReadAll(r.Body)
|
body, _ := io.ReadAll(r.Body)
|
||||||
@ -246,11 +239,11 @@ func (caller apiCaller) whitelistAPI(w http.ResponseWriter, r *http.Request) err
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !caller.isAdminOrValidToken() {
|
// if !caller.isAdminOrValidToken() {
|
||||||
logger.Println("whitelistAPI failed. not vaild user :", r.Method, caller.userinfo)
|
// logger.Println("whitelistAPI failed. not vaild user :", r.Method, caller.userinfo)
|
||||||
w.WriteHeader(http.StatusUnauthorized)
|
// w.WriteHeader(http.StatusUnauthorized)
|
||||||
return nil
|
// return nil
|
||||||
}
|
// }
|
||||||
|
|
||||||
member.Expired = 0
|
member.Expired = 0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user