-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #245 from l3montree-dev/243-add-repo-parts-vulnera…
…bilities-handling started to refactor: rename Asset to AssetNew and update related refe…
- Loading branch information
Showing
47 changed files
with
1,887 additions
and
1,183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package commands | ||
|
||
import ( | ||
"log/slog" | ||
|
||
"github.com/l3montree-dev/devguard/internal/core" | ||
"github.com/l3montree-dev/devguard/internal/database/models" | ||
"github.com/l3montree-dev/devguard/internal/database/repositories" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewMigrateCommand() *cobra.Command { | ||
migrate := cobra.Command{ | ||
Use: "migrate", | ||
Short: "Migrate data", | ||
} | ||
|
||
migrate.AddCommand(newFlawHashMigration()) | ||
return &migrate | ||
} | ||
|
||
func newFlawHashMigration() *cobra.Command { | ||
flawHashMigration := cobra.Command{ | ||
Use: "flaw-hash", | ||
Short: "Will recalculate the flaw hashes for all flaws", | ||
Args: cobra.ExactArgs(0), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
core.LoadConfig() // nolint | ||
database, err := core.DatabaseFactory() | ||
if err != nil { | ||
slog.Error("could not connect to database", "err", err) | ||
return | ||
} | ||
|
||
flawRepository := repositories.NewFlawRepository(database) | ||
|
||
var flaws []models.Flaw | ||
err = flawRepository.GetDB(nil).Model(&models.Flaw{}).Find(&flaws).Error | ||
|
||
if err != nil { | ||
slog.Error("could not fetch flaws", "err", err) | ||
return | ||
} | ||
|
||
for _, flaw := range flaws { | ||
oldHash := flaw.ID | ||
newHash := flaw.CalculateHash() | ||
|
||
// update the hash in the database | ||
err = flawRepository.GetDB(nil).Model(&models.Flaw{}).Where("id = ?", oldHash).UpdateColumn("id", newHash).Error | ||
if err != nil { | ||
slog.Error("could not update flaw hash", "err", err) | ||
return | ||
} | ||
} | ||
}, | ||
} | ||
|
||
return &flawHashMigration | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.