Skip to content

Commit

Permalink
Add todos
Browse files Browse the repository at this point in the history
  • Loading branch information
airenas committed May 30, 2023
1 parent 9303e4c commit 086c381
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions internal/pkg/mongodb/cmsIntegrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ func (ss *CmsIntegrator) Usage(keyID string, from, to *time.Time, full bool) (*a
return nil, err
}

filter := makeDateFilter(keyMapR.Key, keyMapR.Old, from, to)
filter := makeDateFilter(keyMapR.Key, keyMapR.Old, from, to)

c := sessCtx.Client().Database(keyMapR.Project).Collection(logTable)
cursor, err := c.Find(sessCtx, filter)
Expand Down Expand Up @@ -373,7 +373,7 @@ func getDateFilter(from, to *time.Time) bson.M {
}

func makeDateFilter(key string, old []oldKey, from, to *time.Time) bson.M {
res := bson.M{"key": Sanitize(key)}
res := bson.M{"key": Sanitize(key)} // TODO: need to use keyID for new records
if len(old) > 0 {
keys := []string{Sanitize(key)}
for _, k := range old {
Expand Down Expand Up @@ -522,7 +522,7 @@ func (ss *CmsIntegrator) createKeyWithQuota(sessCtx mongo.SessionContext, input
keyMap.Created = time.Now()
keyMap.ExternalID = input.ID
var err error
keyMap.Key, err = randkey.Generate(ss.newKeySize)
keyMap.Key, err = randkey.Generate(ss.newKeySize) // TODO: use UUID here, not the key
if err != nil {
return nil, errors.Wrap(err, "can't generate key")
}
Expand All @@ -538,7 +538,7 @@ func (ss *CmsIntegrator) createKeyWithQuota(sessCtx mongo.SessionContext, input
c = sessCtx.Client().Database(input.Service).Collection(operationTable)
var operation operationRecord
operation.Date = time.Now()
operation.Key = keyMap.Key
operation.Key = keyMap.Key // TODO: use UUID here, not the user's key
operation.OperationID = input.OperationID
operation.QuotaValue = input.Credits
_, err = c.InsertOne(sessCtx, operation)
Expand Down Expand Up @@ -570,7 +570,7 @@ func (ss *CmsIntegrator) changeKey(sessCtx mongo.SessionContext, keyMapR *keyMap

// update map
c := sessCtx.Client().Database(keyMapDB).Collection(keyMapTable)
err = c.FindOneAndUpdate(sessCtx,
err = c.FindOneAndUpdate(sessCtx, // TODO: use key hash here
bson.M{"externalID": keyMapR.ExternalID},
bson.M{"$set": bson.M{"key": newKey, "updated": time.Now()},
"$push": bson.M{"old": bson.M{"changedOn": time.Now(), "key": oldKey}}}).Err()
Expand Down

0 comments on commit 086c381

Please sign in to comment.