@@ -15,6 +15,7 @@ import (
15
15
"os/exec"
16
16
"path/filepath"
17
17
"regexp"
18
+ "slices"
18
19
"strings"
19
20
"time"
20
21
)
@@ -44,6 +45,20 @@ type PluginConfig struct {
44
45
ScopedPaths []string
45
46
}
46
47
48
+ func (p PluginConfig ) MatchesData (q PluginConfig ) bool {
49
+ //compare all but Enabled.
50
+ return p .Name == q .Name &&
51
+ p .URI == q .URI &&
52
+ p .UnixPath == q .UnixPath &&
53
+ p .Plus == q .Plus &&
54
+ p .GitURL == q .GitURL &&
55
+ p .ComposeFilePath == q .ComposeFilePath &&
56
+ p .HasUI == q .HasUI &&
57
+ p .SandboxedUI == q .SandboxedUI &&
58
+ p .InstallTokenPath == q .InstallTokenPath &&
59
+ slices .Compare (p .ScopedPaths , q .ScopedPaths ) == 0
60
+ }
61
+
47
62
var gPlusExtensionDefaults = []PluginConfig {
48
63
{"PFW" , "pfw" , "/state/plugins/pfw/socket" , false , true , PfwGitURL , "plugins/plus/pfw_extension/docker-compose.yml" , false , false , "" , []string {}},
49
64
{"MESH" , "mesh" , MeshdSocketPath , false , true , MeshGitURL , "plugins/plus/mesh_extension/docker-compose.yml" , false , false , "" , []string {}},
@@ -302,10 +317,13 @@ func updatePlugins(router *mux.Router, router_public *mux.Router) func(http.Resp
302
317
found := false
303
318
idx := - 1
304
319
oldComposeFilePath := plugin .ComposeFilePath
320
+ currentPlugin := PluginConfig {}
321
+
305
322
for idx_ , entry := range config .Plugins {
306
323
idx = idx_
307
324
if entry .Name == name || entry .Name == plugin .Name {
308
325
found = true
326
+ currentPlugin = entry
309
327
oldComposeFilePath = entry .ComposeFilePath
310
328
break
311
329
}
@@ -319,16 +337,28 @@ func updatePlugins(router *mux.Router, router_public *mux.Router) func(http.Resp
319
337
320
338
//if a GitURL is set, ensure OTP authentication for 'admin'
321
339
if ! plugin .Plus && plugin .GitURL != "" {
322
- if hasValidJwtOtpHeader ("admin" , r ) {
323
- http .Error (w , "OTP Token invalid for Remote Install" , 400 )
340
+
341
+ check_otp := true
342
+ if found {
343
+ if currentPlugin .MatchesData (plugin ) {
344
+ //for on/off with Enabled state don't need to validate the otp
345
+ check_otp = false
346
+ }
347
+ }
348
+
349
+ if check_otp && ! hasValidJwtOtpHeader ("admin" , r ) {
350
+ http .Redirect (w , r , "/auth/validate" , 302 )
324
351
return
325
352
}
326
353
327
- //clone but don't auto-config.
328
- ret := downloadUserExtension (plugin .GitURL , false )
329
- if ret == false {
330
- fmt .Println ("Failed to download extension " + plugin .GitURL )
331
- // fall thru, dont fail
354
+ //download new plugins
355
+ if ! found {
356
+ //clone but don't auto-config.
357
+ ret := downloadUserExtension (plugin .GitURL , false )
358
+ if ret == false {
359
+ fmt .Println ("Failed to download extension " + plugin .GitURL )
360
+ // fall thru, dont fail
361
+ }
332
362
}
333
363
}
334
364
@@ -693,6 +723,20 @@ func startExtension(composeFilePath string) bool {
693
723
return true
694
724
}
695
725
726
+ func restartExtension (composeFilePath string ) bool {
727
+ if composeFilePath == "" {
728
+ //no-op
729
+ return true
730
+ }
731
+
732
+ _ , err := superdRequest ("restart" , url.Values {"compose_file" : {composeFilePath }}, nil )
733
+ if err != nil {
734
+ return false
735
+ }
736
+
737
+ return true
738
+ }
739
+
696
740
func updateExtension (composeFilePath string ) bool {
697
741
_ , err := superdRequest ("update" , url.Values {"compose_file" : {composeFilePath }}, nil )
698
742
if err != nil {
@@ -831,11 +875,27 @@ func startExtensionServices() error {
831
875
if ! updateExtension (entry .ComposeFilePath ) {
832
876
return errors .New ("Could not update Extension at " + entry .ComposeFilePath )
833
877
}
834
- }
835
878
836
- if ! startExtension (entry .ComposeFilePath ) {
837
- return errors .New ("Could not start Extension at " + entry .ComposeFilePath )
879
+ //if it is pfw we restart for fw rules to refresh after api
880
+ if entry .Name == "PFW" {
881
+ if ! restartExtension (entry .ComposeFilePath ) {
882
+ //try a start
883
+ if ! startExtension (entry .ComposeFilePath ) {
884
+ return errors .New ("Could not start Extension at " + entry .ComposeFilePath )
885
+ }
886
+ }
887
+ } else {
888
+ if ! startExtension (entry .ComposeFilePath ) {
889
+ return errors .New ("Could not start Extension at " + entry .ComposeFilePath )
890
+ }
891
+ }
892
+
893
+ } else {
894
+ if ! startExtension (entry .ComposeFilePath ) {
895
+ return errors .New ("Could not start Extension at " + entry .ComposeFilePath )
896
+ }
838
897
}
898
+
839
899
}
840
900
}
841
901
return nil
0 commit comments