@@ -2,6 +2,7 @@ package waf
2
2
3
3
import (
4
4
"context"
5
+ "encoding/base64"
5
6
"fmt"
6
7
"log"
7
8
"strings"
@@ -437,12 +438,16 @@ func resourceTencentCloudWafBotSceneUCBRuleCreate(d *schema.ResourceData, meta i
437
438
for _ , item := range v .([]interface {}) {
438
439
if ruleMap , ok := item .(map [string ]interface {}); ok && ruleMap != nil {
439
440
inOutputUCBRuleEntry := waf.InOutputUCBRuleEntry {}
441
+ var base46Flag bool
440
442
if v , ok := ruleMap ["key" ]; ok {
441
443
inOutputUCBRuleEntry .Key = helper .String (v .(string ))
442
444
}
443
445
444
446
if v , ok := ruleMap ["op" ]; ok {
445
447
inOutputUCBRuleEntry .Op = helper .String (v .(string ))
448
+ if v .(string ) == "rematch" {
449
+ base46Flag = true
450
+ }
446
451
}
447
452
448
453
if valueMap , ok := helper .InterfaceToMap (ruleMap , "value" ); ok {
@@ -471,10 +476,20 @@ func resourceTencentCloudWafBotSceneUCBRuleCreate(d *schema.ResourceData, meta i
471
476
472
477
if v , ok := valueMap ["multi_value" ]; ok {
473
478
multiValueSet := v .(* schema.Set ).List ()
474
- for i := range multiValueSet {
475
- if multiValueSet [i ] != nil {
476
- multiValue := multiValueSet [i ].(string )
477
- uCBEntryValue .MultiValue = append (uCBEntryValue .MultiValue , & multiValue )
479
+ if base46Flag {
480
+ for i := range multiValueSet {
481
+ if multiValueSet [i ] != nil {
482
+ multiValue := multiValueSet [i ].(string )
483
+ bs64Str := helper .String (base64 .URLEncoding .EncodeToString ([]byte (multiValue )))
484
+ uCBEntryValue .MultiValue = append (uCBEntryValue .MultiValue , bs64Str )
485
+ }
486
+ }
487
+ } else {
488
+ for i := range multiValueSet {
489
+ if multiValueSet [i ] != nil {
490
+ multiValue := multiValueSet [i ].(string )
491
+ uCBEntryValue .MultiValue = append (uCBEntryValue .MultiValue , & multiValue )
492
+ }
478
493
}
479
494
}
480
495
}
@@ -767,12 +782,16 @@ func resourceTencentCloudWafBotSceneUCBRuleRead(d *schema.ResourceData, meta int
767
782
tmpList := make ([]map [string ]interface {}, 0 , len (respData .Rule ))
768
783
for _ , item := range respData .Rule {
769
784
dMap := make (map [string ]interface {})
785
+ var base46Flag bool
770
786
if item .Key != nil {
771
787
dMap ["key" ] = item .Key
772
788
}
773
789
774
790
if item .Op != nil {
775
791
dMap ["op" ] = item .Op
792
+ if * item .Op == "rematch" {
793
+ base46Flag = true
794
+ }
776
795
}
777
796
778
797
if item .Value != nil {
@@ -795,7 +814,21 @@ func resourceTencentCloudWafBotSceneUCBRuleRead(d *schema.ResourceData, meta int
795
814
}
796
815
797
816
if item .Value .MultiValue != nil {
798
- valueMap ["multi_value" ] = item .Value .MultiValue
817
+ if base46Flag {
818
+ tmpMvList := make ([]string , 0 , len (item .Value .MultiValue ))
819
+ for _ , item := range item .Value .MultiValue {
820
+ decoded , e := base64 .StdEncoding .DecodeString (* item )
821
+ if e != nil {
822
+ return fmt .Errorf ("[%s] base64 decode error: %s" , * item , e .Error ())
823
+ }
824
+
825
+ tmpMvList = append (tmpMvList , string (decoded ))
826
+ }
827
+
828
+ valueMap ["multi_value" ] = tmpMvList
829
+ } else {
830
+ valueMap ["multi_value" ] = item .Value .MultiValue
831
+ }
799
832
}
800
833
801
834
valueList = append (valueList , valueMap )
@@ -1028,12 +1061,16 @@ func resourceTencentCloudWafBotSceneUCBRuleUpdate(d *schema.ResourceData, meta i
1028
1061
for _ , item := range v .([]interface {}) {
1029
1062
if ruleMap , ok := item .(map [string ]interface {}); ok && ruleMap != nil {
1030
1063
inOutputUCBRuleEntry := waf.InOutputUCBRuleEntry {}
1064
+ var base46Flag bool
1031
1065
if v , ok := ruleMap ["key" ]; ok {
1032
1066
inOutputUCBRuleEntry .Key = helper .String (v .(string ))
1033
1067
}
1034
1068
1035
1069
if v , ok := ruleMap ["op" ]; ok {
1036
1070
inOutputUCBRuleEntry .Op = helper .String (v .(string ))
1071
+ if v .(string ) == "rematch" {
1072
+ base46Flag = true
1073
+ }
1037
1074
}
1038
1075
1039
1076
if valueMap , ok := helper .InterfaceToMap (ruleMap , "value" ); ok {
@@ -1062,10 +1099,20 @@ func resourceTencentCloudWafBotSceneUCBRuleUpdate(d *schema.ResourceData, meta i
1062
1099
1063
1100
if v , ok := valueMap ["multi_value" ]; ok {
1064
1101
multiValueSet := v .(* schema.Set ).List ()
1065
- for i := range multiValueSet {
1066
- if multiValueSet [i ] != nil {
1067
- multiValue := multiValueSet [i ].(string )
1068
- uCBEntryValue .MultiValue = append (uCBEntryValue .MultiValue , & multiValue )
1102
+ if base46Flag {
1103
+ for i := range multiValueSet {
1104
+ if multiValueSet [i ] != nil {
1105
+ multiValue := multiValueSet [i ].(string )
1106
+ bs64Str := helper .String (base64 .URLEncoding .EncodeToString ([]byte (multiValue )))
1107
+ uCBEntryValue .MultiValue = append (uCBEntryValue .MultiValue , bs64Str )
1108
+ }
1109
+ }
1110
+ } else {
1111
+ for i := range multiValueSet {
1112
+ if multiValueSet [i ] != nil {
1113
+ multiValue := multiValueSet [i ].(string )
1114
+ uCBEntryValue .MultiValue = append (uCBEntryValue .MultiValue , & multiValue )
1115
+ }
1069
1116
}
1070
1117
}
1071
1118
}
0 commit comments