Skip to content

Commit

Permalink
feat(api): remove action plugin when deleting grpc plugin aciton (#6529)
Browse files Browse the repository at this point in the history
  • Loading branch information
sguiheux committed Apr 11, 2023
1 parent 90b4eaa commit ca0b143
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
18 changes: 16 additions & 2 deletions engine/api/actionplugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/ovh/cds/sdk"
)

//InsertWithGRPCPlugin creates action in database
// InsertWithGRPCPlugin creates action in database
func InsertWithGRPCPlugin(db gorp.SqlExecutor, pl *sdk.GRPCPlugin, params []sdk.Parameter) (*sdk.Action, error) {
a := sdk.Action{
Name: pl.Name,
Expand All @@ -33,7 +33,7 @@ func InsertWithGRPCPlugin(db gorp.SqlExecutor, pl *sdk.GRPCPlugin, params []sdk.
return &a, nil
}

//UpdateGRPCPlugin creates action in database
// UpdateGRPCPlugin creates action in database
func UpdateGRPCPlugin(ctx context.Context, db gorp.SqlExecutor, pl *sdk.GRPCPlugin, params []sdk.Parameter) (*sdk.Action, error) {
a := sdk.Action{
Name: pl.Name,
Expand Down Expand Up @@ -62,3 +62,17 @@ func UpdateGRPCPlugin(ctx context.Context, db gorp.SqlExecutor, pl *sdk.GRPCPlug

return &a, nil
}

// DeleteGRPCPlugin delete action in database
func DeleteGRPCPlugin(ctx context.Context, db gorp.SqlExecutor, pl *sdk.GRPCPlugin) error {
act, err := action.LoadByTypesAndName(ctx, db, []string{sdk.PluginAction}, pl.Name, action.LoadOptions.Default)
if err != nil {
return err
}

if err := action.Delete(db, act); err != nil {
return err
}

return nil
}
20 changes: 16 additions & 4 deletions engine/api/grpc_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,23 @@ func (api *API) deleteGRPCluginHandler() service.Handler {
return sdk.WrapError(err, "unable to load old plugin")
}

if err := plugin.Delete(ctx, api.mustDB(), api.SharedStorage, old); err != nil {
tx, err := api.mustDB().Begin()
if err != nil {
return sdk.WithStack(err)
}
defer tx.Rollback()

if old.Type == sdk.GRPCPluginAction {
if err := actionplugin.DeleteGRPCPlugin(ctx, tx, old); err != nil {
return err
}
}

if err := plugin.Delete(ctx, tx, api.SharedStorage, old); err != nil {
return sdk.WrapError(err, "unable to delete plugin")
}

return nil
return sdk.WithStack(tx.Commit())
}
}

Expand Down Expand Up @@ -305,8 +317,8 @@ func (api *API) deleteGRPCluginBinaryHandler() service.Handler {
}

if err := plugin.DeleteBinary(ctx, tx, api.SharedStorage, p, os, arch); err != nil {
return err
}
return err
}

if err := tx.Commit(); err != nil {
return sdk.WrapError(err, "unable to commit tx")
Expand Down

0 comments on commit ca0b143

Please sign in to comment.