Skip to content

Commit

Permalink
fix(api, worker): remove old code and run grpcplugin with recover (#3392
Browse files Browse the repository at this point in the history
)
  • Loading branch information
fsamin authored and yesnault committed Oct 3, 2018
1 parent e05fb6a commit 2848b74
Show file tree
Hide file tree
Showing 26 changed files with 10 additions and 1,978 deletions.
1 change: 0 additions & 1 deletion cli/cdsctl/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func admin() *cobra.Command {
adminHooks,
adminPlatformModels,
adminPlugins,
adminPluginsAction,
adminBroadcasts,
})
}
71 changes: 0 additions & 71 deletions cli/cdsctl/admin_plugin.go

This file was deleted.

6 changes: 0 additions & 6 deletions contrib/grpcplugins/action/kafka-publish/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ func initCli(mainFunc func()) *cli.App {
ArgsUsage: "[command]",
Action: helpAction,
},
cli.Command{
Name: "info",
Aliases: []string{"i"},
Usage: "Show CDS Plugin information",
Action: infoAction,
},
cli.Command{
Name: "listen",
Aliases: []string{"l"},
Expand Down
7 changes: 0 additions & 7 deletions contrib/grpcplugins/action/kafka-publish/cli_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"gopkg.in/urfave/cli.v1"

"github.com/ovh/cds/contrib/grpcplugins/action/kafka-publish/kafkapublisher"
"github.com/ovh/cds/sdk/plugin"
)

//This shows the help
Expand All @@ -26,12 +25,6 @@ func helpAction(c *cli.Context) error {
return nil
}

//This shows information about the plugin
func infoAction(c *cli.Context) error {
fmt.Print(plugin.InfoMarkdown(&KafkaPlugin{}))
return nil
}

//This will listen kafka topic forever and manage all incoming context, file and chunks
func listenAction(c *cli.Context) error {
args := []string{c.Args().First()}
Expand Down
8 changes: 5 additions & 3 deletions contrib/grpcplugins/action/kafka-publish/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ type kafkaPublishActionPlugin struct {
func (actPlugin *kafkaPublishActionPlugin) Manifest(ctx context.Context, _ *empty.Empty) (*actionplugin.ActionPluginManifest, error) {
return &actionplugin.ActionPluginManifest{
Name: "plugin-kafka-publish",
Author: "Alexandre JIN <alexandre.jin@corp.ovh.com>",
Description: `This action helps you generates a file using a template file and text/template golang package.
Author: "François SAMIN <francois.samin@corp.ovh.com>",
Description: `This action helps you to send data through Kafka across every network.
Check documentation on text/template for more information https://golang.org/pkg/text/template.`,
You are able to send a custom "message" file and all the artifacts you want: there is no file size limit. To improve security, you can encrypt the files content with a GPG Key. From the consumer side, you will need to decrypt files content with you GPG private key and your passphrase.
This action is a CDS Plugin packaged as a single binary file you can download and use to listen and consume data coming from CDS through Kafka. CDS can also wait for an acknowledgement coming from the consumer side. To send the acknowledgement, you can again use the plugin binary. For more details, see readme file of the plugin.`,
Version: sdk.VERSION,
}, nil
}
Expand Down
56 changes: 0 additions & 56 deletions contrib/grpcplugins/action/kafka-publish/plugin.go

This file was deleted.

184 changes: 0 additions & 184 deletions engine/api/actionplugin/plugin.go
Original file line number Diff line number Diff line change
@@ -1,141 +1,13 @@
package actionplugin

import (
"context"
"fmt"
"os"

"github.com/go-gorp/gorp"

"github.com/ovh/cds/engine/api/action"
"github.com/ovh/cds/sdk"
"github.com/ovh/cds/sdk/log"
"github.com/ovh/cds/sdk/plugin"
)

//Get returns action plugin metadata and parameters list
func Get(name, path string) (*sdk.ActionPlugin, *plugin.Parameters, error) {
//FIXME: run this in a jail with apparmor
log.Debug("actionplugin.Get> Getting info from '%s' (%s)", name, path)
client := plugin.NewClient(context.Background(), name, path, "ID", "http://127.0.0.1:8081", true)
defer func() {
log.Debug("actionplugin.Get> kill rpc-server")
client.Kill()
}()
log.Debug("actionplugin.Get> Client '%s'", name)
_plugin, err := client.Instance()
if err != nil {
return nil, nil, sdk.WrapError(err, "actionplugin.Get> ")
}

fi, err := os.Open(path)
if err != nil {
return nil, nil, err
}
defer fi.Close()
stat, err := fi.Stat()
if err != nil {
return nil, nil, err
}

sha512sum, err512 := sdk.FileSHA512sum(path)
if err512 != nil {
return nil, nil, sdk.WrapError(err512, "actionplugin.Get> FileSHA512sum")
}

md5sum, errmd5 := sdk.FileMd5sum(path)
if errmd5 != nil {
return nil, nil, sdk.WrapError(err512, "actionplugin.Get> FileMd5sum")
}

ap := sdk.ActionPlugin{
Filename: name,
Name: _plugin.Name(),
Author: _plugin.Author(),
Description: _plugin.Description(),
Path: path,
Size: stat.Size(),
Perm: uint32(stat.Mode().Perm()),
MD5sum: md5sum,
SHA512sum: sha512sum,
}

params := _plugin.Parameters()

return &ap, &params, nil
}

func actionPluginToAction(ap *sdk.ActionPlugin, params *plugin.Parameters) (*sdk.Action, error) {
actionParams := []sdk.Parameter{}
names := params.Names()
for _, p := range names {
var t string
switch params.GetType(p) {
case plugin.EnvironmentParameter:
t = sdk.EnvironmentParameter
case plugin.PipelineParameter:
t = sdk.PipelineParameter
case plugin.ListParameter:
t = sdk.ListParameter
case plugin.NumberParameter:
t = sdk.NumberParameter
// case plugin.PasswordParameter:
// t = sdk.PasswordParameter
case plugin.StringParameter:
t = sdk.StringParameter
case plugin.TextParameter:
t = sdk.TextParameter
case plugin.BooleanParameter:
t = sdk.BooleanParameter
default:
log.Warning("plugin.Insert> unsupported parameter type '%s'", t)
return nil, fmt.Errorf("Unsupported parameter type '%s' in plugin '%s'", t, ap.Name)
}

actionParams = append(actionParams, sdk.Parameter{
Name: p,
Value: params.GetValue(p),
Type: t,
Description: params.GetDescription(p),
})
}

a := &sdk.Action{
Name: ap.Name,
Type: sdk.PluginAction,
Description: ap.Description,
Requirements: sdk.RequirementList{
sdk.Requirement{
Name: ap.Name,
Type: sdk.PluginRequirement,
Value: ap.Name,
},
},
Parameters: actionParams,
Enabled: true,
}
return a, nil
}

//Insert create action in database
func Insert(db gorp.SqlExecutor, ap *sdk.ActionPlugin, params *plugin.Parameters) (*sdk.Action, error) {
a, err := actionPluginToAction(ap, params)
if err != nil {
return nil, err
}

if err = action.InsertAction(db, a, true); err != nil {
log.Warning("plugin.Insert> Action: Cannot insert action: %s\n", err)
return nil, err
}

query := `INSERT INTO plugin (name, size, perm, md5sum, object_path) VALUES ($1, $2, $3, $4, $5) RETURNING id`
if err = db.QueryRow(query, ap.Name, ap.Size, ap.Perm, ap.MD5sum, ap.ObjectPath).Scan(&ap.ID); err != nil {
return nil, err
}
return a, nil
}

//InsertWithGRPCPlugin create action in database
func InsertWithGRPCPlugin(db gorp.SqlExecutor, pl *sdk.GRPCPlugin, params []sdk.Parameter) (*sdk.Action, error) {
a := sdk.Action{
Expand Down Expand Up @@ -190,59 +62,3 @@ func UpdateGRPCPlugin(db gorp.SqlExecutor, pl *sdk.GRPCPlugin, params []sdk.Para

return &a, nil
}

//Update action in database
func Update(db gorp.SqlExecutor, ap *sdk.ActionPlugin, params *plugin.Parameters, userID int64) (*sdk.Action, error) {
a, err := actionPluginToAction(ap, params)
if err != nil {
return nil, err
}

//oldA, err := action.LoadPublicAction(db, a.Name, action.WithClearPasswords())
oldA, err := action.LoadPublicAction(db, a.Name)
if err != nil {
return nil, err
}
a.ID = oldA.ID

if err := action.UpdateActionDB(db, a, userID); err != nil {
return nil, err
}

query := "DELETE FROM plugin WHERE name = $1"
if _, err := db.Exec(query, a.Name); err != nil {
return nil, err
}

query = `INSERT INTO plugin (name, size, perm, md5sum, object_path) VALUES ($1, $2, $3, $4, $5) RETURNING id`
if err = db.QueryRow(query, ap.Name, ap.Size, ap.Perm, ap.MD5sum, ap.ObjectPath).Scan(&ap.ID); err != nil {
return nil, err
}
return a, nil
}

//Delete action in database
func Delete(db *gorp.DbMap, name string, userID int64) error {
tx, err := db.Begin()
if err != nil {
return err
}
defer tx.Rollback()

a, err := action.LoadPublicAction(tx, name)
if err != nil {
return sdk.WrapError(err, "plugin.Delete> Action: Cannot get action %s", name)
}

query := "DELETE FROM plugin WHERE name = $1"
if _, err := tx.Exec(query, a.Name); err != nil {
return err
}

if err := action.DeleteAction(tx, a.ID, userID); err != nil {
return err
}

return tx.Commit()

}
Loading

0 comments on commit 2848b74

Please sign in to comment.