Best Gauge code snippet using plugin.startGRPCPlugin
grpc_plugin.go
Source:grpc_plugin.go
...15 "github.com/ovh/cds/sdk"16 "github.com/ovh/cds/sdk/grpcplugin"17 "github.com/ovh/cds/sdk/log"18)19type startGRPCPluginOptions struct {20 envs []string21}22type pluginClientSocket struct {23 Socket string24 StdPipe io.Reader25 Client interface{}26}27func enablePluginLogger(ctx context.Context, done chan struct{}, c *pluginClientSocket, w workerruntime.Runtime) {28 reader := bufio.NewReader(c.StdPipe)29 var accumulator string30 var shouldExit bool31 defer func() {32 if accumulator != "" {33 w.SendLog(ctx, workerruntime.LevelInfo, accumulator)34 }35 close(done)36 }()37 for {38 if ctx.Err() != nil {39 shouldExit = true40 }41 if reader.Buffered() == 0 && shouldExit {42 return43 }44 b, err := reader.ReadByte()45 if err == io.EOF {46 if shouldExit {47 return48 }49 continue50 }51 content := string(b)52 switch content {53 case "":54 continue55 case "\n":56 accumulator += content57 w.SendLog(ctx, workerruntime.LevelInfo, accumulator)58 accumulator = ""59 continue60 default:61 accumulator += content62 continue63 }64 }65}66func RunGRPCPlugin(ctx context.Context, actionName string, params []sdk.Parameter, action sdk.Action, w workerruntime.Runtime, chanRes chan sdk.Result, done chan struct{}) {67 //For the moment we consider that plugin name = action name68 pluginName := actionName69 var envs []string70 //set up environment variables from job parameters71 for _, p := range params {72 // avoid put private key in environment var as it's a binary value73 if (p.Type == sdk.KeyPGPParameter || p.Type == sdk.KeySSHParameter) && strings.HasSuffix(p.Name, ".priv") {74 continue75 }76 if p.Type == sdk.KeyParameter && !strings.HasSuffix(p.Name, ".pub") {77 continue78 }79 envs = append(envs, sdk.EnvVartoENV(p)...)80 envName := strings.Replace(p.Name, ".", "_", -1)81 envName = strings.ToUpper(envName)82 envs = append(envs, fmt.Sprintf("%s=%s", envName, p.Value))83 }84 pluginSocket, err := startGRPCPlugin(ctx, pluginName, w, nil, startGRPCPluginOptions{85 envs: envs,86 })87 if err != nil {88 close(done)89 pluginFail(ctx, w, chanRes, fmt.Sprintf("Unable to start grpc plugin... Aborting (%v)", err))90 return91 }92 c, err := actionplugin.Client(ctx, pluginSocket.Socket)93 if err != nil {94 close(done)95 pluginFail(ctx, w, chanRes, fmt.Sprintf("Unable to call grpc plugin... Aborting (%v)", err))96 return97 }98 qPort := actionplugin.WorkerHTTPPortQuery{Port: w.HTTPPort()}99 if _, err := c.WorkerHTTPPort(ctx, &qPort); err != nil {100 close(done)101 pluginFail(ctx, w, chanRes, fmt.Sprintf("Unable to set worker http port for grpc plugin... Aborting (%v)", err))102 return103 }104 pluginSocket.Client = c105 pluginClient := pluginSocket.Client106 actionPluginClient, ok := pluginClient.(actionplugin.ActionPluginClient)107 if !ok {108 close(done)109 pluginFail(ctx, w, chanRes, "Unable to retrieve plugin client... Aborting")110 return111 }112 logCtx, stopLogs := context.WithCancel(ctx)113 go enablePluginLogger(logCtx, done, pluginSocket, w)114 manifest, err := actionPluginClient.Manifest(ctx, &empty.Empty{})115 if err != nil {116 pluginFail(ctx, w, chanRes, fmt.Sprintf("Unable to retrieve plugin manifest... Aborting (%v)", err))117 actionPluginClientStop(ctx, actionPluginClient, stopLogs)118 return119 }120 log.Debug("plugin successfully initialized: %#v", manifest)121 w.SendLog(ctx, workerruntime.LevelInfo, fmt.Sprintf("# Plugin %s version %s is ready", manifest.Name, manifest.Version))122 jobID, err := workerruntime.JobID(ctx)123 if err != nil {124 pluginFail(ctx, w, chanRes, fmt.Sprintf("Unable to retrieve job ID... Aborting (%v)", err))125 actionPluginClientStop(ctx, actionPluginClient, stopLogs)126 return127 }128 query := actionplugin.ActionQuery{129 Options: sdk.ParametersMapMerge(sdk.ParametersToMap(params), sdk.ParametersToMap(action.Parameters), sdk.MapMergeOptions.ExcludeGitParams),130 JobID: jobID,131 }132 result, err := actionPluginClient.Run(ctx, &query)133 pluginDetails := fmt.Sprintf("plugin %s v%s", manifest.Name, manifest.Version)134 if err != nil {135 t := fmt.Sprintf("failure %s err: %v", pluginDetails, err)136 actionPluginClientStop(ctx, actionPluginClient, stopLogs)137 log.Error(ctx, t)138 pluginFail(ctx, w, chanRes, fmt.Sprintf("Error running action: %v", err))139 return140 }141 actionPluginClientStop(ctx, actionPluginClient, stopLogs)142 chanRes <- sdk.Result{143 Status: result.GetStatus(),144 Reason: result.GetDetails(),145 }146}147func startGRPCPlugin(ctx context.Context, pluginName string, w workerruntime.Runtime, p *sdk.GRPCPluginBinary, opts startGRPCPluginOptions) (*pluginClientSocket, error) {148 currentOS := strings.ToLower(sdk.GOOS)149 currentARCH := strings.ToLower(sdk.GOARCH)150 binary := p151 if binary == nil {152 var errBi error153 binary, errBi = w.Client().PluginGetBinaryInfos(pluginName, currentOS, currentARCH)154 if errBi != nil {155 return nil, sdk.WrapError(errBi, "plugin:%s Unable to get plugin binary infos... Aborting", pluginName)156 } else if binary == nil {157 return nil, fmt.Errorf("plugin:%s Unable to get plugin binary infos - binary is nil... Aborting", pluginName)158 }159 }160 // then try to download the plugin161 pluginBinary := binary.Name...
builtin_deploy_application.go
Source:builtin_deploy_application.go
...40 }41 if binary == nil {42 return sdk.Result{}, fmt.Errorf("Unable to retrieve the plugin for deployment integration %s... Aborting", pf.Model.Name)43 }44 pluginSocket, err := startGRPCPlugin(ctx, binary.PluginName, wk, binary, startGRPCPluginOptions{})45 if err != nil {46 return sdk.Result{}, fmt.Errorf("unable to start GRPCPlugin: %v", err)47 }48 c, err := integrationplugin.Client(context.Background(), pluginSocket.Socket)49 if err != nil {50 return sdk.Result{}, fmt.Errorf("unable to call GRPCPlugin: %v", err)51 }52 pluginSocket.Client = c53 if _, err := c.Manifest(context.Background(), new(empty.Empty)); err != nil {54 return sdk.Result{}, fmt.Errorf("unable to call GRPCPlugin: %v", err)55 }56 pluginClient := pluginSocket.Client57 integrationPluginClient, ok := pluginClient.(integrationplugin.IntegrationPluginClient)58 if !ok {...
startGRPCPlugin
Using AI Code Generation
1func main() {2 plugin.Serve(&plugin.ServeConfig{3 Plugins: map[string]plugin.Plugin{4 "plugin": &Plugin{},5 },6 })7}8func main() {9 client, err := plugin.Dial("tcp", "
startGRPCPlugin
Using AI Code Generation
1func main() {2 plugin.StartGRPCPlugin(new(HelloWorldPlugin))3}4func main() {5 plugin.StartGRPCPlugin(new(HelloWorldPlugin))6}7func main() {8 plugin.StartGRPCPlugin(new(HelloWorldPlugin))9}10func main() {11 plugin.StartGRPCPlugin(new(HelloWorldPlugin))12}13func main() {14 plugin.StartGRPCPlugin(new(HelloWorldPlugin))15}16func main() {17 plugin.StartGRPCPlugin(new(HelloWorldPlugin))18}19func main() {20 plugin.StartGRPCPlugin(new(HelloWorldPlugin))21}22func main() {23 plugin.StartGRPCPlugin(new(HelloWorldPlugin))24}25func main() {26 plugin.StartGRPCPlugin(new(HelloWorldPlugin))27}28func main() {29 plugin.StartGRPCPlugin(new(HelloWorldPlugin))30}31func main() {32 plugin.StartGRPCPlugin(new(HelloWorldPlugin))33}34func main() {35 plugin.StartGRPCPlugin(new(HelloWorldPlugin))36}37func main() {38 plugin.StartGRPCPlugin(new(HelloWorldPlugin))39}40func main() {41 plugin.StartGRPCPlugin(new(HelloWorldPlugin))42}
startGRPCPlugin
Using AI Code Generation
1func main() {2 go func() {3 if err := plugin.StartGRPCPlugin(); err != nil {4 log.Fatal(err)5 }6 }()7 time.Sleep(1 * time.Second)8 client, err := plugin.NewGRPCPluginClient("tcp", "
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!