Skip to content

Commit 3532ef0

Browse files
committed
feat: support proxy request body amend in mock
1 parent b46114c commit 3532ef0

File tree

3 files changed

+46
-31
lines changed

3 files changed

+46
-31
lines changed

console/atest-ui/src/views/DataManager.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const loadingStores = ref(true)
1717
1818
const tablesTree = ref([])
1919
watch(store, (s) => {
20+
kind.value = ''
2021
stores.value.forEach((e: Store) => {
2122
if (e.name === s) {
2223
kind.value = e.kind.name
@@ -39,7 +40,8 @@ watch(kind, (k) => {
3940
queryTip.value = 'Enter SQL query'
4041
executeQuery()
4142
break;
42-
case 'atest-store-etcd', 'atest-store-redis':
43+
case 'atest-store-etcd':
44+
case 'atest-store-redis':
4345
sqlQuery.value = ''
4446
queryTip.value = 'Enter key'
4547
break;

pkg/mock/in_memory.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,15 @@ func (s *inMemoryServer) Load() (err error) {
120120
}
121121
memLogger.Info("redirect to", "target", api)
122122

123-
targetReq, err := http.NewRequestWithContext(req.Context(), req.Method, api, req.Body)
123+
var requestBody []byte
124+
if requestBody, err = io.ReadAll(req.Body); err != nil {
125+
w.WriteHeader(http.StatusInternalServerError)
126+
}
127+
128+
if proxy.RequestAmend.BodyPatch != "" {
129+
}
130+
131+
targetReq, err := http.NewRequestWithContext(req.Context(), req.Method, api, bytes.NewBuffer(requestBody))
124132
if err != nil {
125133
w.WriteHeader(http.StatusInternalServerError)
126134
memLogger.Error(err, "failed to create proxy request")

pkg/mock/types.go

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,54 +16,59 @@ limitations under the License.
1616
package mock
1717

1818
type Object struct {
19-
Name string `yaml:"name" json:"name"`
20-
InitCount *int `yaml:"initCount" json:"initCount"`
21-
Sample string `yaml:"sample" json:"sample"`
19+
Name string `yaml:"name" json:"name"`
20+
InitCount *int `yaml:"initCount" json:"initCount"`
21+
Sample string `yaml:"sample" json:"sample"`
2222
}
2323

2424
type Item struct {
25-
Name string `yaml:"name" json:"name"`
26-
Request Request `yaml:"request" json:"request"`
27-
Response Response `yaml:"response" json:"response"`
28-
Param map[string]string
25+
Name string `yaml:"name" json:"name"`
26+
Request Request `yaml:"request" json:"request"`
27+
Response Response `yaml:"response" json:"response"`
28+
Param map[string]string
2929
}
3030

3131
type Request struct {
32-
Path string `yaml:"path" json:"path"`
33-
Method string `yaml:"method" json:"method"`
34-
Header map[string]string `yaml:"header" json:"header"`
35-
Body string `yaml:"body" json:"body"`
32+
Path string `yaml:"path" json:"path"`
33+
Method string `yaml:"method" json:"method"`
34+
Header map[string]string `yaml:"header" json:"header"`
35+
Body string `yaml:"body" json:"body"`
3636
}
3737

3838
type RequestWithAuth struct {
39-
Request `yaml:",inline"`
40-
BearerAPI string `yaml:"bearerAPI" json:"bearerAPI"`
41-
Username string `yaml:"username" json:"username"`
42-
Password string `yaml:"password" json:"password"`
39+
Request `yaml:",inline"`
40+
BearerAPI string `yaml:"bearerAPI" json:"bearerAPI"`
41+
Username string `yaml:"username" json:"username"`
42+
Password string `yaml:"password" json:"password"`
4343
}
4444

4545
type Response struct {
46-
Encoder string `yaml:"encoder" json:"encoder"`
47-
Body string `yaml:"body" json:"body"`
48-
Header map[string]string `yaml:"header" json:"header"`
49-
StatusCode int `yaml:"statusCode" json:"statusCode"`
50-
BodyData []byte
46+
Encoder string `yaml:"encoder" json:"encoder"`
47+
Body string `yaml:"body" json:"body"`
48+
Header map[string]string `yaml:"header" json:"header"`
49+
StatusCode int `yaml:"statusCode" json:"statusCode"`
50+
BodyData []byte
5151
}
5252

5353
type Webhook struct {
54-
Name string `yaml:"name" json:"name"`
55-
Timer string `yaml:"timer" json:"timer"`
56-
Request RequestWithAuth `yaml:"request" json:"request"`
54+
Name string `yaml:"name" json:"name"`
55+
Timer string `yaml:"timer" json:"timer"`
56+
Request RequestWithAuth `yaml:"request" json:"request"`
5757
}
5858

5959
type Proxy struct {
60-
Path string `yaml:"path" json:"path"`
61-
Target string `yaml:"target" json:"target"`
60+
Path string `yaml:"path" json:"path"`
61+
Target string `yaml:"target" json:"target"`
62+
RequestAmend RequestAmend `yaml:"requestAmend" json:"requestAmend"`
63+
}
64+
65+
type RequestAmend struct {
66+
BodyPatch string `yaml:"bodyPatch" json:"bodyPatch"`
6267
}
6368

6469
type Server struct {
65-
Objects []Object `yaml:"objects" json:"objects"`
66-
Items []Item `yaml:"items" json:"items"`
67-
Proxies []Proxy `yaml:"proxies" json:"proxies"`
68-
Webhooks []Webhook `yaml:"webhooks" json:"webhooks"`
70+
Objects []Object `yaml:"objects" json:"objects"`
71+
Items []Item `yaml:"items" json:"items"`
72+
Proxies []Proxy `yaml:"proxies" json:"proxies"`
73+
Webhooks []Webhook `yaml:"webhooks" json:"webhooks"`
6974
}

0 commit comments

Comments
 (0)