Skip to content

Commit 5e059be

Browse files
committed
Fix CodeRabbit comments
1 parent 1b0c30e commit 5e059be

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

gateway/gateway-controller/pkg/api/handlers/handlers.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,6 +1956,12 @@ func (s *APIServer) GenerateAPIKey(c *gin.Context, name string, version string)
19561956
zap.Error(err),
19571957
zap.String("name", name),
19581958
zap.String("version", version))
1959+
// Rollback database save to maintain consistency
1960+
if s.db != nil {
1961+
if delErr := s.db.DeleteAPIKey(apiKey.APIKey); delErr != nil {
1962+
log.Error("Failed to rollback API key from database", zap.Error(delErr))
1963+
}
1964+
}
19591965
c.JSON(http.StatusInternalServerError, api.ErrorResponse{
19601966
Status: "error",
19611967
Message: "Failed to store API key",

gateway/gateway-controller/pkg/storage/sqlite.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,10 @@ func (s *SQLiteStorage) initSchema() error {
198198
if _, err := s.db.Exec(`CREATE INDEX IF NOT EXISTS idx_api_key_expiry ON api_keys(expires_at);`); err != nil {
199199
return fmt.Errorf("failed to create api_keys expiry index: %w", err)
200200
}
201-
if _, err := s.db.Exec("PRAGMA user_version = 4"); err != nil {
202-
return fmt.Errorf("failed to set schema version to 4: %w", err)
201+
if _, err := s.db.Exec("PRAGMA user_version = 5"); err != nil {
202+
return fmt.Errorf("failed to set schema version to 5: %w", err)
203203
}
204-
s.logger.Info("Schema migrated to version 4 (api_keys table)")
204+
s.logger.Info("Schema migrated to version 5 (api_keys table)")
205205
version = 5
206206
}
207207

@@ -1164,7 +1164,7 @@ func (s *SQLiteStorage) UpdateAPIKey(apiKey *models.APIKey) error {
11641164
}
11651165

11661166
s.logger.Info("API key updated successfully",
1167-
zap.String("key", apiKey.APIKey),
1167+
zap.String(" id", apiKey.ID),
11681168
zap.String("status", string(apiKey.Status)))
11691169

11701170
return nil
@@ -1188,7 +1188,7 @@ func (s *SQLiteStorage) DeleteAPIKey(key string) error {
11881188
return fmt.Errorf("%w: API key not found", ErrNotFound)
11891189
}
11901190

1191-
s.logger.Info("API key deleted successfully", zap.String("key", key))
1191+
s.logger.Info("API key deleted successfully", zap.String("key_prefix", key[:min(8, len(key))]+"***"))
11921192

11931193
return nil
11941194
}

0 commit comments

Comments
 (0)