Skip to content

Commit 647a0f4

Browse files
patrick.rissmann@l3montree.compatrick.rissmann@l3montree.com
authored andcommitted
Changed the issues pointed out and added a way to retrieve attestations by asset version too
1 parent 247f848 commit 647a0f4

5 files changed

Lines changed: 18 additions & 4 deletions

File tree

internal/core/attestation/attestation_controller.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package attestation
22

33
import (
4+
"fmt"
5+
"io/ioutil"
6+
47
"github.com/l3montree-dev/devguard/internal/core"
58
"github.com/l3montree-dev/devguard/internal/database/models"
69
"github.com/labstack/echo/v4"
@@ -30,10 +33,13 @@ func (a *attestationController) List(ctx core.Context) error {
3033

3134
func (a *attestationController) Create(ctx core.Context) error {
3235
var attestation models.Attestation
33-
err := ctx.Bind(&attestation)
36+
37+
content, err := ioutil.ReadAll(ctx.Request().Body)
38+
3439
if err != nil {
3540
return echo.NewHTTPError(400, "unable to bind data to attestation model").WithInternal(err)
3641
}
42+
fmt.Printf("This is the content as string: %s\n", content)
3743

3844
err = core.V.Struct(attestation)
3945
if err != nil {

internal/core/common_interfaces.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type AssetRepository interface {
5454

5555
type AttestationRepository interface {
5656
GetByAssetID(assetID uuid.UUID) ([]models.Attestation, error)
57+
GetByAssetVersion(assetID uuid.UUID, assetVersion string) ([]models.Attestation, error)
5758
}
5859

5960
type CveRepository interface {

internal/database/models/asset_version_model.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type AssetVersion struct {
2323
AssetID uuid.UUID `json:"assetId" gorm:"primarykey;not null;type:uuid;"`
2424
Asset Asset `json:"asset" gorm:"foreignKey:AssetID;references:ID; constraint:OnDelete:CASCADE;"`
2525

26-
Attestation []Attestation `json:"attestations" gorm:"foreignKey:AssetVersionName,AssetID;references:Name,AssetID;constraint:OnDelete:CASCADE;"`
26+
Attestations []Attestation `json:"attestations" gorm:"foreignKey:AssetVersionName,AssetID;references:Name,AssetID;constraint:OnDelete:CASCADE;"`
2727
DefaultBranch bool `json:"defaultBranch" gorm:"default:false;"`
2828
Slug string `json:"slug" gorm:"type:text;not null;type:text;"`
2929
DependencyVulns []DependencyVuln `json:"dependencyVulns" gorm:"foreignKey:AssetVersionName,AssetID;references:Name,AssetID;constraint:OnDelete:CASCADE;"`

internal/database/models/attestation_model.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import (
88
"gorm.io/gorm"
99
)
1010

11-
type AttestationType string
12-
1311
type Attestation struct {
1412
CreatedAt time.Time `json:"createdAt"`
1513
UpdatedAt time.Time `json:"updatedAt"`

internal/database/repositories/attestation_repository.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ func (a *attestationRepository) GetByAssetID(assetID uuid.UUID) ([]models.Attest
3232
return attestationList, nil
3333
}
3434

35+
func (a *attestationRepository) GetByAssetVersion(assetID uuid.UUID, assetVersion string) ([]models.Attestation, error) {
36+
var attestationList []models.Attestation
37+
err := a.db.Where("asset_id = ? AND asset_version_name = ?", assetID, assetVersion).Find(&attestationList).Error
38+
if err != nil {
39+
return attestationList, err
40+
}
41+
return attestationList, nil
42+
}
43+
3544
func (a *attestationRepository) Create() error {
3645
return nil
3746
}

0 commit comments

Comments
 (0)