[이민권] 서비스 준비
- 계정 삭제 시, TTL 적용
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"maingate_mongodb_url": "mongodb://...",
|
"maingate_mongodb_url": "mongodb://...",
|
||||||
"autologin_ttl": 604800,
|
"autologin_ttl": 604800,
|
||||||
|
"acc_del_ttl": 7776000,
|
||||||
"maximum_num_link_account": 10,
|
"maximum_num_link_account": 10,
|
||||||
"redirect_base_url": "",
|
"redirect_base_url": "",
|
||||||
"google_client_id" : "",
|
"google_client_id" : "",
|
||||||
|
|||||||
@ -124,6 +124,7 @@ type maingateConfig struct {
|
|||||||
Mongo string `json:"maingate_mongodb_url"`
|
Mongo string `json:"maingate_mongodb_url"`
|
||||||
SessionTTL int64 `json:"maingate_session_ttl"`
|
SessionTTL int64 `json:"maingate_session_ttl"`
|
||||||
Autologin_ttl int64 `json:"autologin_ttl"`
|
Autologin_ttl int64 `json:"autologin_ttl"`
|
||||||
|
AccDelTTL int64 `json:"acc_del_ttl"`
|
||||||
MaximumNumLinkAccount int64 `json:"maximum_num_link_account"`
|
MaximumNumLinkAccount int64 `json:"maximum_num_link_account"`
|
||||||
RedirectBaseUrl string `json:"redirect_base_url"`
|
RedirectBaseUrl string `json:"redirect_base_url"`
|
||||||
GoogleClientId string `json:"google_client_id"`
|
GoogleClientId string `json:"google_client_id"`
|
||||||
@ -354,6 +355,14 @@ func (mg *Maingate) prepare(context context.Context) (err error) {
|
|||||||
return makeErrorWithStack(err)
|
return makeErrorWithStack(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err = mg.mongoClient.MakeExpireIndex(CollectionAccount, int32(mg.AccDelTTL)); err != nil {
|
||||||
|
return makeErrorWithStack(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = mg.mongoClient.MakeExpireIndex(CollectionLink, int32(mg.AccDelTTL)); err != nil {
|
||||||
|
return makeErrorWithStack(err)
|
||||||
|
}
|
||||||
|
|
||||||
// Delete대신 _ts로 expire시킴. pipeline에 삭제 알려주기 위함
|
// Delete대신 _ts로 expire시킴. pipeline에 삭제 알려주기 위함
|
||||||
if err = mg.mongoClient.MakeExpireIndex(CollectionWhitelist, 10); err != nil {
|
if err = mg.mongoClient.MakeExpireIndex(CollectionWhitelist, 10); err != nil {
|
||||||
return makeErrorWithStack(err)
|
return makeErrorWithStack(err)
|
||||||
|
|||||||
@ -673,6 +673,7 @@ func (sh *serviceDescription) authorize(w http.ResponseWriter, r *http.Request)
|
|||||||
link, err := sh.mongoClient.FindOneAndUpdate(CollectionLink, bson.M{
|
link, err := sh.mongoClient.FindOneAndUpdate(CollectionLink, bson.M{
|
||||||
"platform": authtype,
|
"platform": authtype,
|
||||||
"uid": uid,
|
"uid": uid,
|
||||||
|
"_ts": bson.M{"$exists": false},
|
||||||
}, bson.M{
|
}, bson.M{
|
||||||
"$setOnInsert": bson.M{
|
"$setOnInsert": bson.M{
|
||||||
"create": createtime,
|
"create": createtime,
|
||||||
@ -850,27 +851,33 @@ func (sh *serviceDescription) delacc(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var addIdFilter bson.A
|
var addIdFilter primitive.A
|
||||||
for _, accid := range accids {
|
for _, accid := range accids {
|
||||||
addIdFilter = append(addIdFilter, accid["_id"].(primitive.ObjectID))
|
addIdFilter = append(addIdFilter, accid["_id"].(primitive.ObjectID))
|
||||||
}
|
}
|
||||||
|
|
||||||
delfilter := bson.D{{Key: "_id", Value: bson.D{{Key: "$in", Value: addIdFilter}}}}
|
delfilter := primitive.M{"_id": bson.M{"$in": addIdFilter}}
|
||||||
delaccnum, err := sh.mongoClient.DeleteMany(CollectionAccount, delfilter)
|
curtime := primitive.NewDateTimeFromTime(time.Now().UTC())
|
||||||
if err != nil {
|
updated, _, err := sh.mongoClient.Update(CollectionAccount, delfilter, bson.M{
|
||||||
logger.Error("delacc failed. Delete many CollectionAccount err :", err)
|
"$set": bson.M{"_ts": curtime},
|
||||||
|
}, options.Update().SetUpsert(false))
|
||||||
|
|
||||||
|
if !updated || err != nil {
|
||||||
|
logger.Error("delacc failed. Update CollectionAccount timestamp err :", err)
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = sh.mongoClient.DeleteMany(CollectionLink, delfilter)
|
updated, _, err = sh.mongoClient.Update(CollectionLink, delfilter, bson.M{
|
||||||
if err != nil {
|
"$set": bson.M{"_ts": curtime},
|
||||||
logger.Error("delacc failed. Delete many CollectionLink err :", err)
|
}, options.Update().SetUpsert(false))
|
||||||
|
if !updated || err != nil {
|
||||||
|
logger.Error("delacc failed. Update CollectionLink timestamp err :", err)
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Println("delacc success :", delaccnum)
|
logger.Println("delacc success :", accids)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sh *serviceDescription) serveHTTP(w http.ResponseWriter, r *http.Request) {
|
func (sh *serviceDescription) serveHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
Reference in New Issue
Block a user