File tree 2 files changed +40
-0
lines changed
2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change 4
4
"crypto/sha256"
5
5
"encoding/hex"
6
6
"strings"
7
+
8
+ "github.com/smartcontractkit/chainlink-common/pkg/logger"
7
9
)
8
10
9
11
func EncodeExecutionID (workflowID , eventID string ) (string , error ) {
@@ -84,3 +86,14 @@ func HashTruncateName(name string) [10]byte {
84
86
85
87
return result
86
88
}
89
+
90
+ // HexDecodeWorkflowName makes the best effort to decode the hex workflow name.
91
+ // In case of failure it will log the error and return the input name.
92
+ func HexDecodeWorkflowName (encoded string , logger logger.Logger ) string {
93
+ decoded , err := hex .DecodeString (encoded )
94
+ if err != nil {
95
+ logger .Errorf ("failed to decode WorkflowName %q: %v" , encoded , err )
96
+ return encoded
97
+ }
98
+ return string (decoded )
99
+ }
Original file line number Diff line number Diff line change 5
5
"encoding/hex"
6
6
"testing"
7
7
8
+ "github.com/smartcontractkit/chainlink-common/pkg/logger"
8
9
"github.com/stretchr/testify/assert"
9
10
"github.com/stretchr/testify/require"
10
11
)
@@ -99,3 +100,29 @@ func TestNormalizeWorkflowName(t *testing.T) {
99
100
})
100
101
}
101
102
}
103
+
104
+ func TestHexDecodeWorkflowName (t * testing.T ) {
105
+ tt := []struct {
106
+ name string
107
+ input string
108
+ expected string
109
+ }{
110
+ {
111
+ name : "OK-correct_workflow_name" ,
112
+ input : "776f726b666c6f772d6e616d65" ,
113
+ expected : "workflow-name" ,
114
+ },
115
+ {
116
+ name : "NOK-incorrect_workflow_name" ,
117
+ input : "776f726b666c6f772d6e616d65!" ,
118
+ expected : "776f726b666c6f772d6e616d65!" ,
119
+ },
120
+ }
121
+
122
+ for _ , tc := range tt {
123
+ t .Run (tc .name , func (t * testing.T ) {
124
+ result := HexDecodeWorkflowName (tc .input , logger .TestSugared (t ))
125
+ require .Equal (t , tc .expected , result )
126
+ })
127
+ }
128
+ }
You can’t perform that action at this time.
0 commit comments