@@ -26,27 +26,29 @@ import (
2626 "github.com/google/uuid"
2727 toto "github.com/in-toto/in-toto-golang/in_toto"
2828 "github.com/l3montree-dev/devguard/internal/core"
29+ "github.com/l3montree-dev/devguard/internal/utils"
2930
3031 "github.com/l3montree-dev/devguard/internal/database/models"
3132
3233 "github.com/labstack/echo/v4"
3334)
3435
3536type httpController struct {
36- linkRepository core.InTotoLinkRepository
37- supplyChainRepository core.SupplyChainRepository
38-
39- patRepository core.PersonalAccessTokenRepository
37+ linkRepository core.InTotoLinkRepository
38+ supplyChainRepository core.SupplyChainRepository
39+ assetVersionRepository core. AssetVersionRepository
40+ patRepository core.PersonalAccessTokenRepository
4041
4142 inTotoVerifierService core.InTotoVerifierService
4243}
4344
44- func NewHTTPController (repository core.InTotoLinkRepository , supplyChainRepository core.SupplyChainRepository , patRepository core.PersonalAccessTokenRepository , inTotoVerifierService core.InTotoVerifierService ) * httpController {
45+ func NewHTTPController (repository core.InTotoLinkRepository , supplyChainRepository core.SupplyChainRepository , assetVersionRepository core. AssetVersionRepository , patRepository core.PersonalAccessTokenRepository , inTotoVerifierService core.InTotoVerifierService ) * httpController {
4546 return & httpController {
46- linkRepository : repository ,
47- supplyChainRepository : supplyChainRepository ,
48- patRepository : patRepository ,
49- inTotoVerifierService : inTotoVerifierService ,
47+ linkRepository : repository ,
48+ supplyChainRepository : supplyChainRepository ,
49+ assetVersionRepository : assetVersionRepository ,
50+ patRepository : patRepository ,
51+ inTotoVerifierService : inTotoVerifierService ,
5052 }
5153}
5254
@@ -130,9 +132,18 @@ func (a *httpController) Create(ctx core.Context) error {
130132 }
131133
132134 asset := core .GetAsset (ctx )
135+ tag := ctx .Request ().Header .Get ("X-Tag" )
136+ defaultBranch := ctx .Request ().Header .Get ("X-Asset-Default-Branch" )
137+ if defaultBranch == "" {
138+ defaultBranch = "main"
139+ }
140+ assetVersion , err := a .assetVersionRepository .FindOrCreate (assetVersionName , asset .ID , tag == "1" , utils .EmptyThenNil (defaultBranch ))
141+ if err != nil {
142+ return err
143+ }
133144
134145 link := models.InTotoLink {
135- AssetVersionName : assetVersionName ,
146+ AssetVersionName : assetVersion . Name ,
136147 AssetID : asset .ID ,
137148 SupplyChainID : strings .TrimSpace (req .SupplyChainID ),
138149 Step : strings .TrimSpace (req .Step ),
0 commit comments