Skip to content

Commit 38e220d

Browse files
committed
base64 encode compressed data
1 parent 1c0f741 commit 38e220d

File tree

3 files changed

+20
-73
lines changed

3 files changed

+20
-73
lines changed

env_gen.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

env_gen.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,10 @@
287287
| DASHBOARD_PORT | string |3000 | Port for dashboard micro-service | | false |
288288
| DEX_HOST | string |http://localhost | | | false |
289289
| DEX_PORT | string |5556 | | | false |
290-
| GIT_SENSOR_PROTOCOL | string |REST | Protocol to connect with git-sensor micro-service | | false |
290+
| GIT_SENSOR_PROTOCOL | string |GRPC | Protocol to connect with git-sensor micro-service | | false |
291291
| GIT_SENSOR_SERVICE_CONFIG | string |{"loadBalancingPolicy":"pick_first"} | git-sensor grpc service config | | false |
292292
| GIT_SENSOR_TIMEOUT | int |0 | Timeout for getting response from the git-sensor | | false |
293-
| GIT_SENSOR_URL | string |127.0.0.1:7070 | git-sensor micro-service url | | false |
293+
| GIT_SENSOR_URL | string |127.0.0.1:7071 | git-sensor micro-service url | | false |
294294
| HELM_CLIENT_URL | string |127.0.0.1:50051 | Kubelink micro-service url | | false |
295295
| KUBELINK_GRPC_MAX_RECEIVE_MSG_SIZE | int |20 | | | false |
296296
| KUBELINK_GRPC_MAX_SEND_MSG_SIZE | int |4 | | | false |

pkg/workflow/trigger/audit/helper/CompressionHelper.go

Lines changed: 17 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ package helper
1919
import (
2020
"bytes"
2121
"compress/gzip"
22+
"encoding/base64"
2223
"encoding/json"
2324
"io"
2425
)
2526

26-
// CompressJSON marshals and compresses JSON data
27-
func CompressJSON(data interface{}) (string, error) {
27+
// CompressWorkflowRequest compresses WorkflowRequest to bytes
28+
func CompressWorkflowRequest(workflowRequest interface{}) (string, error) {
2829
// Marshal to JSON
29-
jsonData, err := json.Marshal(data)
30+
jsonData, err := json.Marshal(workflowRequest)
3031
if err != nil {
3132
return "", err
3233
}
@@ -45,86 +46,32 @@ func CompressJSON(data interface{}) (string, error) {
4546
return "", err
4647
}
4748

48-
return string(buf.Bytes()), nil
49+
// Encode compressed binary data to Base64 to avoid UTF-8 encoding issues
50+
return base64.StdEncoding.EncodeToString(buf.Bytes()), nil
4951
}
5052

51-
// DecompressJSON decompresses and unmarshals JSON data
52-
func DecompressJSON(compressedData []byte, target interface{}) error {
53-
// Decompress
54-
reader, err := gzip.NewReader(bytes.NewReader(compressedData))
53+
// DecompressWorkflowRequest decompresses bytes to WorkflowRequest
54+
// This function handles both Base64 encoded and legacy raw binary data for backward compatibility
55+
func DecompressWorkflowRequest(compressedData string, target interface{}) error {
56+
// Try Base64 decoding first (new format)
57+
decodedData, err := base64.StdEncoding.DecodeString(compressedData)
5558
if err != nil {
5659
return err
5760
}
58-
defer reader.Close()
5961

60-
// Read decompressed data
61-
decompressedData, err := io.ReadAll(reader)
62+
// Use decoded data for decompression
63+
reader, err := gzip.NewReader(bytes.NewReader(decodedData))
6264
if err != nil {
6365
return err
6466
}
65-
66-
// Unmarshal JSON
67-
return json.Unmarshal(decompressedData, target)
68-
}
69-
70-
// CompressString compresses string data
71-
func CompressString(data string) ([]byte, error) {
72-
var buf bytes.Buffer
73-
gzipWriter := gzip.NewWriter(&buf)
74-
75-
_, err := gzipWriter.Write([]byte(data))
76-
if err != nil {
77-
return nil, err
78-
}
79-
80-
err = gzipWriter.Close()
81-
if err != nil {
82-
return nil, err
83-
}
84-
85-
return buf.Bytes(), nil
86-
}
87-
88-
// DecompressString decompresses string data
89-
func DecompressString(compressedData []byte) (string, error) {
90-
reader, err := gzip.NewReader(bytes.NewReader(compressedData))
91-
if err != nil {
92-
return "", err
93-
}
9467
defer reader.Close()
9568

69+
// Read decompressed data
9670
decompressedData, err := io.ReadAll(reader)
9771
if err != nil {
98-
return "", err
72+
return err
9973
}
10074

101-
return string(decompressedData), nil
102-
}
103-
104-
// Utility functions for backward compatibility
105-
106-
// CompressWorkflowRequest compresses WorkflowRequest to bytes
107-
func CompressWorkflowRequest(workflowRequest interface{}) (string, error) {
108-
return CompressJSON(workflowRequest)
109-
}
110-
111-
// DecompressWorkflowRequest decompresses bytes to WorkflowRequest
112-
func DecompressWorkflowRequest(compressedData string, target interface{}) error {
113-
return DecompressJSON([]byte(compressedData), target)
114-
}
115-
116-
// Example usage:
117-
/*
118-
// Compress before saving
119-
compressedData, err := CompressWorkflowRequest(workflowRequest)
120-
if err != nil {
121-
return err
122-
}
123-
snapshot.WorkflowRequestJson = compressedData
124-
// Decompress when reading
125-
var workflowRequest types.WorkflowRequest
126-
err = DecompressWorkflowRequest(snapshot.WorkflowRequestJson, &workflowRequest)
127-
if err != nil {
128-
return err
75+
// Unmarshal JSON
76+
return json.Unmarshal(decompressedData, target)
12977
}
130-
*/

0 commit comments

Comments
 (0)