@@ -2,6 +2,7 @@ package main
22
33import (
44 log "github.com/sirupsen/logrus"
5+ "google.golang.org/grpc/credentials"
56 "google.golang.org/grpc/credentials/insecure"
67 pb "nwnx4.org/nwn2dev/xp_rpc/proto"
78 "strings"
@@ -32,6 +33,7 @@ const rpcEndBuildGeneric int32 = 2
3233
3334type rpcPlugin struct {
3435 config rpcConfig
36+ certPath * string
3537 clients map [string ]* rpcClient
3638 globalExBuildGenericRequest * pb.ExBuildGenericRequest
3739 globalExBuildGenericResponse * pb.ExBuildGenericResponse
@@ -41,6 +43,7 @@ type rpcPlugin struct {
4143func newRpcPlugin () * rpcPlugin {
4244 return & rpcPlugin {
4345 config : rpcConfig {},
46+ certPath : nil ,
4447 clients : make (map [string ]* rpcClient ),
4548 globalExBuildGenericRequest : newExBuildGenericRequest (),
4649 globalExBuildGenericResponse : newExBuildGenericResponse (),
@@ -85,7 +88,31 @@ func (p *rpcPlugin) init() {
8588// Runs on an rpcPlugin and adds a client by name and URL
8689func (p * rpcPlugin ) addRpcClient (name , url string ) {
8790 log .Infof ("Adding client: %s@%s" , name , url )
88- conn , err := grpc .Dial (url , grpc .WithTransportCredentials (insecure .NewCredentials ()))
91+
92+ // Load the certificate
93+ var conn * grpc.ClientConn
94+ var err error
95+ if p .certPath != nil {
96+ creds , err := credentials .NewClientTLSFromFile (* p .certPath , "" )
97+ if err != nil {
98+ log .Errorf ("Unable to load certificate: %v" , err )
99+ p .clients [name ] = & rpcClient {
100+ isValid : false ,
101+ name : name ,
102+ url : url ,
103+ exServiceClient : nil ,
104+ nwnxServiceClient : nil ,
105+ scorcoServiceClient : nil ,
106+ }
107+ return
108+ }
109+
110+ conn , err = grpc .Dial (url , grpc .WithTransportCredentials (creds ))
111+ } else {
112+ conn , err = grpc .Dial (url , grpc .WithTransportCredentials (insecure .NewCredentials ()))
113+ }
114+
115+ // Dial with the loaded certificate
89116 if err != nil {
90117 log .Errorf ("Unable to attach client: %s@%s" , name , url )
91118
@@ -101,6 +128,7 @@ func (p *rpcPlugin) addRpcClient(name, url string) {
101128 return
102129 }
103130
131+ // Create gRPC clients with the connection
104132 p .clients [name ] = & rpcClient {
105133 isValid : true ,
106134 name : name ,
0 commit comments