@@ -5,33 +5,36 @@ import (
5
5
"fmt"
6
6
"time"
7
7
8
+ "google.golang.org/grpc"
9
+ "google.golang.org/grpc/metadata"
10
+
8
11
"github.com/dsrhub/dsrhub/idl_dsrhub"
9
12
"github.com/ovh/utask/pkg/plugins/taskplugin"
10
- "google.golang.org/grpc"
11
13
)
12
14
13
15
var (
14
16
// Plugin is the dsrhub_grpc plugin that we can use as a customized plugin
15
17
// nolint
16
18
Plugin = taskplugin .New (
17
19
"dsrhub_grpc" , "1.0" , exec ,
18
- taskplugin .WithConfig (validConfig , DsrHubGRPCConfig {}),
20
+ taskplugin .WithConfig (validConfig , DSRHubGRPCConfig {}),
19
21
)
20
22
)
21
23
22
24
const (
23
25
defaultTimeoutSeconds = 10
24
26
)
25
27
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 {
28
30
URL string `json:"url"`
29
31
Request idl_dsrhub.CreateDSRRequest `json:"request"`
30
32
Timeout int `json:"timeout,omitempty"` // timeout in seconds
33
+ Header map [string ]string `json:"header,omitempty"`
31
34
}
32
35
33
36
func validConfig (config interface {}) error {
34
- cfg := config .(* DsrHubGRPCConfig )
37
+ cfg := config .(* DSRHubGRPCConfig )
35
38
if cfg .URL == "" {
36
39
return fmt .Errorf ("invalid dsrhub_grpc config url: empty url" )
37
40
}
@@ -50,8 +53,8 @@ func validConfig(config interface{}) error {
50
53
return nil
51
54
}
52
55
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 )
55
58
56
59
// TODO: support secure connection with configuration
57
60
conn , err := grpc .Dial (cfg .URL , grpc .WithInsecure ())
@@ -69,7 +72,8 @@ func exec(stepName string, config interface{}, execCtx interface{}) (output inte
69
72
)
70
73
defer cancel ()
71
74
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 ))
73
77
if err != nil {
74
78
return nil , nil , err
75
79
}
0 commit comments