Skip to content
This repository was archived by the owner on Oct 14, 2024. It is now read-only.

Commit

Permalink
refactor(api): copy PointerTo to api types
Browse files Browse the repository at this point in the history
  • Loading branch information
paralta committed Feb 1, 2024
1 parent 54a38e2 commit a6eb21a
Show file tree
Hide file tree
Showing 25 changed files with 437 additions and 474 deletions.
5 changes: 2 additions & 3 deletions api/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"net/http"

"github.com/openclarity/vmclarity/api/types"
"github.com/openclarity/vmclarity/pkg/shared/utils"
)

type BackendClient struct {
Expand Down Expand Up @@ -241,7 +240,7 @@ func (b *BackendClient) PatchScan(ctx context.Context, scanID types.ScanID, scan

func (b *BackendClient) GetAssetScanSummary(ctx context.Context, assetScanID string) (*types.ScanFindingsSummary, error) {
params := types.GetAssetScansAssetScanIDParams{
Select: utils.PointerTo("summary"),
Select: types.PointerTo("summary"),
}
assetScan, err := b.GetAssetScan(ctx, assetScanID, params)
if err != nil {
Expand All @@ -252,7 +251,7 @@ func (b *BackendClient) GetAssetScanSummary(ctx context.Context, assetScanID str

func (b *BackendClient) GetAssetScanStatus(ctx context.Context, assetScanID string) (*types.AssetScanStatus, error) {
params := types.GetAssetScansAssetScanIDParams{
Select: utils.PointerTo("status"),
Select: types.PointerTo("status"),
}
assetScan, err := b.GetAssetScan(ctx, assetScanID, params)
if err != nil {
Expand Down
9 changes: 1 addition & 8 deletions api/client/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go 1.21.4
require (
github.com/deepmap/oapi-codegen/v2 v2.1.0
github.com/oapi-codegen/runtime v1.1.1
github.com/openclarity/vmclarity v0.0.0-00010101000000-000000000000
github.com/openclarity/vmclarity/api/types v0.0.0-00010101000000-000000000000
)

Expand All @@ -20,17 +19,11 @@ require (
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/perimeterx/marshmallow v1.1.5 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.17.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace (
github.com/openclarity/vmclarity => ../../
github.com/openclarity/vmclarity/api/types => ../types
)
replace github.com/openclarity/vmclarity/api/types => ../types
20 changes: 2 additions & 18 deletions api/client/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7D
github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP2+08jFMw88y4klk=
github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/deepmap/oapi-codegen/v2 v2.1.0 h1:I/NMVhJCtuvL9x+S2QzZKpSjGi33oDZwPRdemvOZWyQ=
Expand All @@ -14,10 +13,8 @@ github.com/go-openapi/jsonpointer v0.20.2 h1:mQc3nmndL8ZBzStEo3JYF8wzmeWffDH4VbX
github.com/go-openapi/jsonpointer v0.20.2/go.mod h1:bHen+N0u1KEO3YlmqOjTT9Adn1RfD91Ar825/PuiRVs=
github.com/go-openapi/swag v0.22.8 h1:/9RjDSQ0vbFR+NyjGMkFTsA1IA0fmhKSThmfGZjicbw=
github.com/go-openapi/swag v0.22.8/go.mod h1:6QT22icPLEqAM/z/TChgb4WAveCHF92+2gF0CNjHpPI=
github.com/go-test/deep v1.1.0 h1:WOcxcdHcvdgThNXjw0t76K42FXTU7HpNQWHpA2HHNlg=
github.com/go-test/deep v1.1.0/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM=
github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/invopop/yaml v0.2.0 h1:7zky/qH+O0DwAyoobXUqvVBwgBFRxKoQ/3FjcVpjTMY=
Expand All @@ -35,21 +32,16 @@ github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/oapi-codegen/runtime v1.1.1 h1:EXLHh0DXIJnWhdRPN2w4MXAzFyE4CskzhNLUmtpMYro=
github.com/oapi-codegen/runtime v1.1.1/go.mod h1:SK9X900oXmPWilYR5/WKPzt3Kqxn/uS/+lbpREv+eCg=
github.com/onsi/gomega v1.31.1 h1:KYppCUK+bUgAZwHOu7EXVBKyQA6ILvOESHkn/tgoqvo=
github.com/onsi/gomega v1.31.1/go.mod h1:y40C95dwAD1Nz36SsEnxvfFe8FFfNxzI5eJ0EYGyAy0=
github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX50IvK2s=
github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
Expand All @@ -58,13 +50,6 @@ golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhp
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc=
Expand All @@ -74,7 +59,6 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
1 change: 0 additions & 1 deletion api/server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ require (
github.com/oapi-codegen/echo-middleware v1.0.1
github.com/oapi-codegen/runtime v1.1.1
github.com/onsi/gomega v1.31.1
github.com/openclarity/vmclarity v0.0.0-00010101000000-000000000000
github.com/openclarity/vmclarity/api/types v0.0.0-00010101000000-000000000000
github.com/openclarity/vmclarity/uibackend/types v0.0.0-00010101000000-000000000000
github.com/openclarity/vmclarity/utils v0.0.0-00010101000000-000000000000
Expand Down
9 changes: 4 additions & 5 deletions api/server/pkg/asset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/openclarity/vmclarity/api/server/pkg/common"
dbtypes "github.com/openclarity/vmclarity/api/server/pkg/database/types"
"github.com/openclarity/vmclarity/api/types"
"github.com/openclarity/vmclarity/pkg/shared/utils"
)

func (s *ServerImpl) GetAssets(ctx echo.Context, params types.GetAssetsParams) error {
Expand All @@ -52,7 +51,7 @@ func (s *ServerImpl) PostAssets(ctx echo.Context) error {
switch true {
case errors.As(err, &conflictErr):
existResponse := &types.AssetExists{
Message: utils.PointerTo(conflictErr.Reason),
Message: types.PointerTo(conflictErr.Reason),
Asset: &createdAsset,
}
return sendResponse(ctx, http.StatusConflict, existResponse)
Expand Down Expand Up @@ -102,7 +101,7 @@ func (s *ServerImpl) PutAssetsAssetID(ctx echo.Context, assetID types.AssetID, p
return sendError(ctx, http.StatusNotFound, fmt.Sprintf("Asset with ID %v not found", assetID))
case errors.As(err, &conflictErr):
existResponse := &types.AssetExists{
Message: utils.PointerTo(conflictErr.Reason),
Message: types.PointerTo(conflictErr.Reason),
Asset: &updatedAsset,
}
return sendResponse(ctx, http.StatusConflict, existResponse)
Expand Down Expand Up @@ -141,7 +140,7 @@ func (s *ServerImpl) PatchAssetsAssetID(ctx echo.Context, assetID types.AssetID,
return sendError(ctx, http.StatusNotFound, fmt.Sprintf("Asset with ID %v not found", assetID))
case errors.As(err, &conflictErr):
existResponse := &types.AssetExists{
Message: utils.PointerTo(conflictErr.Reason),
Message: types.PointerTo(conflictErr.Reason),
Asset: &updatedAsset,
}
return sendResponse(ctx, http.StatusConflict, existResponse)
Expand All @@ -157,7 +156,7 @@ func (s *ServerImpl) PatchAssetsAssetID(ctx echo.Context, assetID types.AssetID,

func (s *ServerImpl) DeleteAssetsAssetID(ctx echo.Context, assetID types.AssetID) error {
success := types.Success{
Message: utils.PointerTo(fmt.Sprintf("asset %v deleted", assetID)),
Message: types.PointerTo(fmt.Sprintf("asset %v deleted", assetID)),
}

if err := s.dbHandler.AssetsTable().DeleteAsset(assetID); err != nil {
Expand Down
7 changes: 3 additions & 4 deletions api/server/pkg/asset_scan_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/openclarity/vmclarity/api/server/pkg/common"
dbtypes "github.com/openclarity/vmclarity/api/server/pkg/database/types"
"github.com/openclarity/vmclarity/api/types"
"github.com/openclarity/vmclarity/pkg/shared/utils"
)

func (s *ServerImpl) GetAssetScans(ctx echo.Context, params types.GetAssetScansParams) error {
Expand Down Expand Up @@ -71,7 +70,7 @@ func (s *ServerImpl) PostAssetScans(ctx echo.Context) error {
var conflictErr *common.ConflictError
if errors.As(err, &conflictErr) {
existResponse := &types.AssetScanExists{
Message: utils.PointerTo(conflictErr.Reason),
Message: types.PointerTo(conflictErr.Reason),
AssetScan: &createdAssetScan,
}
return sendResponse(ctx, http.StatusConflict, existResponse)
Expand Down Expand Up @@ -151,7 +150,7 @@ func (s *ServerImpl) PatchAssetScansAssetScanID(ctx echo.Context, assetScanID ty
switch true {
case errors.As(err, &conflictErr):
existResponse := &types.AssetScanExists{
Message: utils.PointerTo(conflictErr.Reason),
Message: types.PointerTo(conflictErr.Reason),
AssetScan: &updatedAssetScan,
}
return sendResponse(ctx, http.StatusConflict, existResponse)
Expand Down Expand Up @@ -228,7 +227,7 @@ func (s *ServerImpl) PutAssetScansAssetScanID(ctx echo.Context, assetScanID type
switch true {
case errors.As(err, &conflictErr):
existResponse := &types.AssetScanExists{
Message: utils.PointerTo(conflictErr.Reason),
Message: types.PointerTo(conflictErr.Reason),
AssetScan: &updatedAssetScan,
}
return sendResponse(ctx, http.StatusConflict, existResponse)
Expand Down
9 changes: 4 additions & 5 deletions api/server/pkg/asset_scan_estimation_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/openclarity/vmclarity/api/server/pkg/common"
dbtypes "github.com/openclarity/vmclarity/api/server/pkg/database/types"
"github.com/openclarity/vmclarity/api/types"
"github.com/openclarity/vmclarity/pkg/shared/utils"
)

func (s *ServerImpl) GetAssetScanEstimations(ctx echo.Context, params types.GetAssetScanEstimationsParams) error {
Expand Down Expand Up @@ -59,7 +58,7 @@ func (s *ServerImpl) PostAssetScanEstimations(ctx echo.Context) error {
var conflictErr *common.ConflictError
if errors.As(err, &conflictErr) {
existResponse := &types.AssetScanEstimationExists{
Message: utils.PointerTo(conflictErr.Reason),
Message: types.PointerTo(conflictErr.Reason),
AssetScanEstimation: &createdAssetScanEstimation,
}
return sendResponse(ctx, http.StatusConflict, existResponse)
Expand Down Expand Up @@ -126,7 +125,7 @@ func (s *ServerImpl) PatchAssetScanEstimationsAssetScanEstimationID(ctx echo.Con
switch true {
case errors.As(err, &conflictErr):
existResponse := &types.AssetScanEstimationExists{
Message: utils.PointerTo(conflictErr.Reason),
Message: types.PointerTo(conflictErr.Reason),
AssetScanEstimation: &updatedAssetScanEstimation,
}
return sendResponse(ctx, http.StatusConflict, existResponse)
Expand Down Expand Up @@ -188,7 +187,7 @@ func (s *ServerImpl) PutAssetScanEstimationsAssetScanEstimationID(ctx echo.Conte
switch true {
case errors.As(err, &conflictErr):
existResponse := &types.AssetScanEstimationExists{
Message: utils.PointerTo(conflictErr.Reason),
Message: types.PointerTo(conflictErr.Reason),
AssetScanEstimation: &updatedAssetScanEstimation,
}
return sendResponse(ctx, http.StatusConflict, existResponse)
Expand All @@ -206,7 +205,7 @@ func (s *ServerImpl) PutAssetScanEstimationsAssetScanEstimationID(ctx echo.Conte

func (s *ServerImpl) DeleteAssetScanEstimationsAssetScanEstimationID(ctx echo.Context, assetScanEstimationID types.AssetScanEstimationID) error {
success := types.Success{
Message: utils.PointerTo(fmt.Sprintf("asset scan estimation %v deleted", assetScanEstimationID)),
Message: types.PointerTo(fmt.Sprintf("asset scan estimation %v deleted", assetScanEstimationID)),
}

if err := s.dbHandler.AssetScanEstimationsTable().DeleteAssetScanEstimation(assetScanEstimationID); err != nil {
Expand Down
Loading

0 comments on commit a6eb21a

Please sign in to comment.