@@ -2,6 +2,7 @@ package waf
22
33import (
44 "context"
5+ "encoding/base64"
56 "fmt"
67 "log"
78 "strings"
@@ -437,12 +438,16 @@ func resourceTencentCloudWafBotSceneUCBRuleCreate(d *schema.ResourceData, meta i
437438 for _ , item := range v .([]interface {}) {
438439 if ruleMap , ok := item .(map [string ]interface {}); ok && ruleMap != nil {
439440 inOutputUCBRuleEntry := waf.InOutputUCBRuleEntry {}
441+ var base46Flag bool
440442 if v , ok := ruleMap ["key" ]; ok {
441443 inOutputUCBRuleEntry .Key = helper .String (v .(string ))
442444 }
443445
444446 if v , ok := ruleMap ["op" ]; ok {
445447 inOutputUCBRuleEntry .Op = helper .String (v .(string ))
448+ if v .(string ) == "rematch" {
449+ base46Flag = true
450+ }
446451 }
447452
448453 if valueMap , ok := helper .InterfaceToMap (ruleMap , "value" ); ok {
@@ -471,10 +476,20 @@ func resourceTencentCloudWafBotSceneUCBRuleCreate(d *schema.ResourceData, meta i
471476
472477 if v , ok := valueMap ["multi_value" ]; ok {
473478 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+ }
478493 }
479494 }
480495 }
@@ -767,12 +782,16 @@ func resourceTencentCloudWafBotSceneUCBRuleRead(d *schema.ResourceData, meta int
767782 tmpList := make ([]map [string ]interface {}, 0 , len (respData .Rule ))
768783 for _ , item := range respData .Rule {
769784 dMap := make (map [string ]interface {})
785+ var base46Flag bool
770786 if item .Key != nil {
771787 dMap ["key" ] = item .Key
772788 }
773789
774790 if item .Op != nil {
775791 dMap ["op" ] = item .Op
792+ if * item .Op == "rematch" {
793+ base46Flag = true
794+ }
776795 }
777796
778797 if item .Value != nil {
@@ -795,7 +814,21 @@ func resourceTencentCloudWafBotSceneUCBRuleRead(d *schema.ResourceData, meta int
795814 }
796815
797816 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+ }
799832 }
800833
801834 valueList = append (valueList , valueMap )
@@ -1028,12 +1061,16 @@ func resourceTencentCloudWafBotSceneUCBRuleUpdate(d *schema.ResourceData, meta i
10281061 for _ , item := range v .([]interface {}) {
10291062 if ruleMap , ok := item .(map [string ]interface {}); ok && ruleMap != nil {
10301063 inOutputUCBRuleEntry := waf.InOutputUCBRuleEntry {}
1064+ var base46Flag bool
10311065 if v , ok := ruleMap ["key" ]; ok {
10321066 inOutputUCBRuleEntry .Key = helper .String (v .(string ))
10331067 }
10341068
10351069 if v , ok := ruleMap ["op" ]; ok {
10361070 inOutputUCBRuleEntry .Op = helper .String (v .(string ))
1071+ if v .(string ) == "rematch" {
1072+ base46Flag = true
1073+ }
10371074 }
10381075
10391076 if valueMap , ok := helper .InterfaceToMap (ruleMap , "value" ); ok {
@@ -1062,10 +1099,20 @@ func resourceTencentCloudWafBotSceneUCBRuleUpdate(d *schema.ResourceData, meta i
10621099
10631100 if v , ok := valueMap ["multi_value" ]; ok {
10641101 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+ }
10691116 }
10701117 }
10711118 }
0 commit comments