@@ -73,20 +73,24 @@ type CompatV1Shim struct {
7373 pluginServer * grpc.Server
7474 pluginInfo * papiv1.Info
7575 http.Server
76+ }
77+
78+ type compatV1ShimServer struct {
79+ shim * CompatV1Shim
7680 protobuf.UnimplementedPluginServer
7781 protobuf.UnimplementedDisplayerServer
7882 protobuf.UnimplementedConfigurerServer
7983}
8084
81- func (s * CompatV1Shim ) GetPluginInfo (ctx context.Context , req * emptypb.Empty ) (* protobuf.Info , error ) {
85+ func (s * compatV1ShimServer ) GetPluginInfo (ctx context.Context , req * emptypb.Empty ) (* protobuf.Info , error ) {
8286 return & protobuf.Info {
83- Version : s .pluginInfo .Version ,
84- Author : s .pluginInfo .Author ,
85- Name : s .pluginInfo .Name ,
86- Website : s .pluginInfo .Website ,
87- Description : s .pluginInfo .Description ,
88- License : s .pluginInfo .License ,
89- ModulePath : s .pluginInfo .ModulePath ,
87+ Version : s .shim . pluginInfo .Version ,
88+ Author : s .shim . pluginInfo .Author ,
89+ Name : s .shim . pluginInfo .Name ,
90+ Website : s .shim . pluginInfo .Website ,
91+ Description : s .shim . pluginInfo .Description ,
92+ License : s .shim . pluginInfo .License ,
93+ ModulePath : s .shim . pluginInfo .ModulePath ,
9094 }, nil
9195}
9296
@@ -122,13 +126,10 @@ func (h *shimV1StorageHandler) Load() (b []byte, err error) {
122126 return
123127}
124128
125- func (s * CompatV1Shim ) SetEnable (ctx context.Context , req * protobuf.SetEnableRequest ) (* emptypb.Empty , error ) {
126- if req .User .Id > math .MaxUint {
127- return nil , errors .New ("user id is too large" )
128- }
129- s .mu .RLock ()
130- instance , ok := s .instances [uint64 (req .User .Id )]
131- s .mu .RUnlock ()
129+ func (s * compatV1ShimServer ) SetEnable (ctx context.Context , req * protobuf.SetEnableRequest ) (* emptypb.Empty , error ) {
130+ s .shim .mu .RLock ()
131+ instance , ok := s .shim .instances [req .User .Id ]
132+ s .shim .mu .RUnlock ()
132133 if ! ok {
133134 return nil , errors .New ("instance not found" )
134135 }
@@ -139,13 +140,10 @@ func (s *CompatV1Shim) SetEnable(ctx context.Context, req *protobuf.SetEnableReq
139140 }
140141}
141142
142- func (s * CompatV1Shim ) Display (ctx context.Context , req * protobuf.DisplayRequest ) (* protobuf.DisplayResponse , error ) {
143- if req .User .Id > math .MaxUint {
144- return nil , errors .New ("user id is too large" )
145- }
146- s .mu .RLock ()
147- instance , ok := s .instances [uint64 (req .User .Id )]
148- s .mu .RUnlock ()
143+ func (s * compatV1ShimServer ) Display (ctx context.Context , req * protobuf.DisplayRequest ) (* protobuf.DisplayResponse , error ) {
144+ s .shim .mu .RLock ()
145+ instance , ok := s .shim .instances [req .User .Id ]
146+ s .shim .mu .RUnlock ()
149147 if ! ok {
150148 return nil , errors .New ("instance not found" )
151149 }
@@ -161,13 +159,10 @@ func (s *CompatV1Shim) Display(ctx context.Context, req *protobuf.DisplayRequest
161159 return nil , errors .New ("instance does not implement displayer" )
162160}
163161
164- func (s * CompatV1Shim ) DefaultConfig (ctx context.Context , req * protobuf.DefaultConfigRequest ) (* protobuf.Config , error ) {
165- if req .User .Id > math .MaxUint {
166- return nil , errors .New ("user id is too large" )
167- }
168- s .mu .RLock ()
169- instance , ok := s .instances [uint64 (req .User .Id )]
170- s .mu .RUnlock ()
162+ func (s * compatV1ShimServer ) DefaultConfig (ctx context.Context , req * protobuf.DefaultConfigRequest ) (* protobuf.Config , error ) {
163+ s .shim .mu .RLock ()
164+ instance , ok := s .shim .instances [req .User .Id ]
165+ s .shim .mu .RUnlock ()
171166 if ! ok {
172167 return nil , errors .New ("instance not found" )
173168 }
@@ -184,13 +179,10 @@ func (s *CompatV1Shim) DefaultConfig(ctx context.Context, req *protobuf.DefaultC
184179 return nil , errors .New ("instance does not implement configurer" )
185180}
186181
187- func (s * CompatV1Shim ) ValidateAndSetConfig (ctx context.Context , req * protobuf.ValidateAndSetConfigRequest ) (* protobuf.ValidateAndSetConfigResponse , error ) {
188- if req .User .Id > math .MaxUint {
189- return nil , errors .New ("user id is too large" )
190- }
191- s .mu .RLock ()
192- instance , ok := s .instances [uint64 (req .User .Id )]
193- s .mu .RUnlock ()
182+ func (s * compatV1ShimServer ) ValidateAndSetConfig (ctx context.Context , req * protobuf.ValidateAndSetConfigRequest ) (* protobuf.ValidateAndSetConfigResponse , error ) {
183+ s .shim .mu .RLock ()
184+ instance , ok := s .shim .instances [req .User .Id ]
185+ s .shim .mu .RUnlock ()
194186 if ! ok {
195187 return nil , errors .New ("instance not found" )
196188 }
@@ -217,11 +209,11 @@ func (s *CompatV1Shim) ValidateAndSetConfig(ctx context.Context, req *protobuf.V
217209 return nil , errors .New ("instance does not implement configurer" )
218210}
219211
220- func (s * CompatV1Shim ) RunUserInstance (req * protobuf.UserInstanceRequest , stream protobuf.Plugin_RunUserInstanceServer ) error {
212+ func (s * compatV1ShimServer ) RunUserInstance (req * protobuf.UserInstanceRequest , stream protobuf.Plugin_RunUserInstanceServer ) error {
221213 if req .User .Id > math .MaxUint {
222214 return errors .New ("user id is too large" )
223215 }
224- instance , err := s .compatV1 .GetInstance (& papiv1.UserContext {
216+ instance , err := s .shim . compatV1 .GetInstance (& papiv1.UserContext {
225217 ID : uint (req .User .Id ),
226218 Name : req .User .Name ,
227219 Admin : req .User .Admin ,
@@ -284,14 +276,14 @@ func (s *CompatV1Shim) RunUserInstance(req *protobuf.UserInstanceRequest, stream
284276
285277 if webhooker , ok := instance .(papiv1.Webhooker ); ok {
286278 if req .WebhookBasePath != nil {
287- group := s .gin .Group (* req .WebhookBasePath )
279+ group := s .shim . gin .Group (* req .WebhookBasePath )
288280 webhooker .RegisterWebhook (* req .WebhookBasePath , group )
289281 }
290282 }
291283
292- s .mu .Lock ()
293- s .instances [uint64 ( req .User .Id ) ] = instance
294- s .mu .Unlock ()
284+ s .shim . mu .Lock ()
285+ s .shim . instances [req .User .Id ] = instance
286+ s .shim . mu .Unlock ()
295287
296288 return nil
297289}
@@ -346,9 +338,13 @@ func NewPluginRpc(compatV1 *CompatV1, cliArgs []string) (*CompatV1Shim, error) {
346338 pluginInfo : pluginInfo ,
347339 }
348340
349- protobuf .RegisterPluginServer (rpcServer , self )
350- protobuf .RegisterDisplayerServer (rpcServer , self )
351- protobuf .RegisterConfigurerServer (rpcServer , self )
341+ selfServer := & compatV1ShimServer {
342+ shim : self ,
343+ }
344+
345+ protobuf .RegisterPluginServer (rpcServer , selfServer )
346+ protobuf .RegisterDisplayerServer (rpcServer , selfServer )
347+ protobuf .RegisterConfigurerServer (rpcServer , selfServer )
352348
353349 protocols := new (http.Protocols )
354350 protocols .SetHTTP1 (true )
0 commit comments