Skip to content

Commit 508674a

Browse files
patrick.rissmann@l3montree.compatrick.rissmann@l3montree.com
authored andcommitted
Added the remaining code review changes including the api Route, the list function and the create function
1 parent 1fedea7 commit 508674a

3 files changed

Lines changed: 15 additions & 12 deletions

File tree

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"cSpell.words": [
99
"devguard",
1010
"ghinstallation",
11+
"gorm",
12+
"montree",
1113
"Vulns"
1214
]
1315
}

cmd/devguard/api/api.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,9 @@ func BuildRouter(db core.DB) *echo.Echo {
555555

556556
assetVersionRouter.GET("/versions/", assetVersionController.Versions)
557557

558+
assetVersionRouter.GET("/attestations/", attestationController.List)
559+
assetVersionRouter.POST("/attestations/", attestationController.Create)
560+
558561
assetRouter.POST("/integrations/gitlab/autosetup/", integrationController.AutoSetup, projectScopedRBAC(accesscontrol.ObjectAsset, accesscontrol.ActionUpdate))
559562
assetRouter.PATCH("/", assetController.Update, projectScopedRBAC(accesscontrol.ObjectAsset, accesscontrol.ActionUpdate))
560563

@@ -564,7 +567,6 @@ func BuildRouter(db core.DB) *echo.Echo {
564567
assetRouter.GET("/in-toto/root.layout.json/", intotoController.RootLayout)
565568

566569
assetVersionRouter.GET("/in-toto/:supplyChainId/", intotoController.Read)
567-
assetVersionRouter.POST("/attestations/", attestationController.Create)
568570

569571
apiV1Router.GET("/verify-supply-chain/", intotoController.VerifySupplyChain)
570572

@@ -579,9 +581,6 @@ func BuildRouter(db core.DB) *echo.Echo {
579581

580582
dependencyVulnRouter.GET("/:dependencyVulnId/events/", vulnEventController.ReadAssetEventsByVulnID)
581583

582-
attestationRouter := assetVersionRouter.Group("/attestations")
583-
attestationRouter.GET("/", attestationController.List)
584-
585584
routes := server.Routes()
586585
sort.Slice(routes, func(i, j int) bool {
587586
return routes[i].Path < routes[j].Path

internal/core/attestation/attestation_controller.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package attestation
22

33
import (
4-
"fmt"
4+
"encoding/json"
55
"io"
66

77
"github.com/l3montree-dev/devguard/internal/core"
@@ -22,8 +22,9 @@ func NewAttestationController(repository core.AttestationRepository) *attestatio
2222
func (a *attestationController) List(ctx core.Context) error {
2323

2424
asset := core.GetAsset(ctx)
25+
assetVersion := core.GetAssetVersion(ctx)
2526

26-
attestationList, err := a.attestationRepository.GetByAssetID(asset.GetID())
27+
attestationList, err := a.attestationRepository.GetByAssetVersion(asset.GetID(), assetVersion.Name)
2728
if err != nil {
2829
return err
2930
}
@@ -33,23 +34,24 @@ func (a *attestationController) List(ctx core.Context) error {
3334

3435
func (a *attestationController) Create(ctx core.Context) error {
3536
var attestation models.Attestation
37+
jsonContent := make(map[string]any)
3638

3739
assetVersion := core.GetAssetVersion(ctx)
38-
3940
attestation.AssetID = core.GetAsset(ctx).ID
4041

4142
attestation.AssetVersionName = assetVersion.Name
4243
attestation.AssetVersion = assetVersion
43-
//How to get the name of the attestation ?
44+
attestation.AttestationName = ctx.Request().Header.Get("X-Attestation-Name")
4445

4546
content, err := io.ReadAll(ctx.Request().Body)
46-
4747
if err != nil {
4848
return echo.NewHTTPError(400, "unable to bind data to attestation model").WithInternal(err)
4949
}
50-
//json := make(map[string]string)
51-
//err = json.Unmarshal(content, &json)
52-
fmt.Printf("content: %s \n", content)
50+
51+
err = json.Unmarshal(content, &jsonContent)
52+
if err != nil {
53+
return err
54+
}
5355

5456
err = core.V.Struct(attestation)
5557
if err != nil {

0 commit comments

Comments
 (0)