@@ -5,33 +5,36 @@ import (
55 "fmt"
66 "time"
77
8+ "google.golang.org/grpc"
9+ "google.golang.org/grpc/metadata"
10+
811 "github.com/dsrhub/dsrhub/idl_dsrhub"
912 "github.com/ovh/utask/pkg/plugins/taskplugin"
10- "google.golang.org/grpc"
1113)
1214
1315var (
1416 // Plugin is the dsrhub_grpc plugin that we can use as a customized plugin
1517 // nolint
1618 Plugin = taskplugin .New (
1719 "dsrhub_grpc" , "1.0" , exec ,
18- taskplugin .WithConfig (validConfig , DsrHubGRPCConfig {}),
20+ taskplugin .WithConfig (validConfig , DSRHubGRPCConfig {}),
1921 )
2022)
2123
2224const (
2325 defaultTimeoutSeconds = 10
2426)
2527
26- // DsrHubGRPCConfig is the configuration needed to perform an gRPC client side call
27- type DsrHubGRPCConfig struct {
28+ // DSRHubGRPCConfig is the configuration needed to perform an gRPC client side call
29+ type DSRHubGRPCConfig struct {
2830 URL string `json:"url"`
2931 Request idl_dsrhub.CreateDSRRequest `json:"request"`
3032 Timeout int `json:"timeout,omitempty"` // timeout in seconds
33+ Header map [string ]string `json:"header,omitempty"`
3134}
3235
3336func validConfig (config interface {}) error {
34- cfg := config .(* DsrHubGRPCConfig )
37+ cfg := config .(* DSRHubGRPCConfig )
3538 if cfg .URL == "" {
3639 return fmt .Errorf ("invalid dsrhub_grpc config url: empty url" )
3740 }
@@ -50,8 +53,8 @@ func validConfig(config interface{}) error {
5053 return nil
5154}
5255
53- func exec (stepName string , config interface {}, execCtx interface {}) (output interface {}, metadata interface {}, err error ) {
54- cfg := config .(* DsrHubGRPCConfig )
56+ func exec (stepName string , config interface {}, execCtx interface {}) (output interface {}, _ interface {}, err error ) {
57+ cfg := config .(* DSRHubGRPCConfig )
5558
5659 // TODO: support secure connection with configuration
5760 conn , err := grpc .Dial (cfg .URL , grpc .WithInsecure ())
@@ -69,7 +72,8 @@ func exec(stepName string, config interface{}, execCtx interface{}) (output inte
6972 )
7073 defer cancel ()
7174
72- res , err := idl_dsrhub .NewDSRHubServiceClient (conn ).CreateDSR (ctx , & cfg .Request )
75+ header := metadata .New (cfg .Header )
76+ res , err := idl_dsrhub .NewDSRHubServiceClient (conn ).CreateDSR (ctx , & cfg .Request , grpc .Header (& header ))
7377 if err != nil {
7478 return nil , nil , err
7579 }
0 commit comments