Skip to content

Commit a2e3e2b

Browse files
Add dispatcher logic
Signed-off-by: Yogesh Deshpande <[email protected]>
1 parent 63c3c0b commit a2e3e2b

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

vts/trustedservices/dispatcher.go

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,33 @@
22
// SPDX-License-Identifier: Apache-2.0
33
package trustedservices
44

5+
import (
6+
"encoding/json"
7+
"fmt"
8+
"os"
9+
)
10+
511
type clientDetails struct {
6-
Type string
7-
Url string
8-
Insecure bool
9-
CaCerts []string
10-
Hints []string
12+
Type string `json:"type"`
13+
Url string `json:"url"`
14+
Insecure bool `json:"in-secure"`
15+
CaCerts []string `json:"caCerts"`
16+
Hints []string `json:"hint"`
1117
}
12-
type DispatchInfo struct {
18+
type Dispatcher struct {
1319
ClientInfo map[string]clientDetails
1420
}
21+
22+
var lvDispatcher Dispatcher
23+
24+
// LoadDispatchTable loads the Dispatch Table from the configuration
25+
func LoadDispatchTable(fp string) error {
26+
data, err := os.ReadFile(fp)
27+
if err != nil {
28+
return fmt.Errorf("error reading dispatch table from %s: %w", fp, err)
29+
}
30+
if err := json.Unmarshal(data, &lvDispatcher); err != nil {
31+
return fmt.Errorf("error unmarshalling dispatch table: %w", err)
32+
}
33+
return nil
34+
}

vts/trustedservices/trustedservices_grpc.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,12 @@ func (o *GRPC) Init(
181181
opts = append(opts, grpc.Creds(creds))
182182
}
183183

184+
if cfg.DispatchTable != "" {
185+
if err := LoadDispatchTable(cfg.DispatchTable); err != nil {
186+
return err
187+
}
188+
}
189+
184190
server := grpc.NewServer(opts...)
185191
proto.RegisterVTSServer(server, o)
186192

0 commit comments

Comments
 (0)