fix(influxdb): also update auth token indices

This commit is contained in:
oddlama 2023-08-17 12:40:37 +02:00
parent 301e7b353c
commit e99253b9db
No known key found for this signature in database
GPG key ID: 14EFE510775FE39A
2 changed files with 22 additions and 6 deletions

View file

@ -29,13 +29,19 @@ func main() {
defer db.Close()
err = db.Update(func(tx *bbolt.Tx) error {
bucket := tx.Bucket([]byte("authorizationsv1"))
if bucket == nil {
authBucket := tx.Bucket([]byte("authorizationsv1"))
if authBucket == nil {
fmt.Println("Bucket 'authorizationsv1' not found.")
os.Exit(1)
}
return bucket.ForEach(func(k, v []byte) error {
authIndex := tx.Bucket([]byte("authorizationindexv1"))
if authIndex == nil {
fmt.Println("Bucket 'authorizationindexv1' not found.")
os.Exit(1)
}
return authBucket.ForEach(func(k, v []byte) error {
var obj map[string]interface{}
if err := json.Unmarshal(v, &obj); err != nil {
fmt.Printf("Error unmarshalling JSON: %v\n", err)
@ -83,8 +89,18 @@ func main() {
return nil // Continue processing other rows
}
if err := bucket.Put(k, updatedValue); err != nil {
fmt.Printf("Error updating bucket: %v\n", err)
if err := authIndex.Delete([]byte(oldToken)); err != nil {
fmt.Printf("Error deleting old token index in authorizationindexv1: %v\n", err)
return nil // Continue processing other rows
}
if err := authIndex.Put([]byte(newToken), k); err != nil {
fmt.Printf("Error adding new token index in authorizationindexv1: %v\n", err)
return nil // Continue processing other rows
}
if err := authBucket.Put(k, updatedValue); err != nil {
fmt.Printf("Error updating token in authorizationsv1: %v\n", err)
return nil // Continue processing other rows
}

View file

@ -822,7 +822,7 @@ in {
listArgs
++ [
"--description"
(optionalString (apiToken.description != null) "${apiToken.description} - " + apiToken.id)
("${apiToken.name} - " + optionalString (apiToken.description != null) "${apiToken.description} - " + apiToken.id)
]
++ optional apiToken.operator "--operator"
++ optional apiToken.allAccess "--all-access"