From e99253b9dbd12e4b11d74d7ae8a1f9d09399df9c Mon Sep 17 00:00:00 2001 From: oddlama Date: Thu, 17 Aug 2023 12:40:37 +0200 Subject: [PATCH] fix(influxdb): also update auth token indices --- modules/meta/influx-token-manipulator/main.go | 26 +++++++++++++++---- modules/meta/influxdb.nix | 2 +- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/modules/meta/influx-token-manipulator/main.go b/modules/meta/influx-token-manipulator/main.go index b51d04c..8b2f5ae 100644 --- a/modules/meta/influx-token-manipulator/main.go +++ b/modules/meta/influx-token-manipulator/main.go @@ -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 } diff --git a/modules/meta/influxdb.nix b/modules/meta/influxdb.nix index 47fe26c..81308cf 100644 --- a/modules/meta/influxdb.nix +++ b/modules/meta/influxdb.nix @@ -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"