feat: support proxy request body amend in mock

This commit is contained in:
rick 2025-03-04 08:08:31 +00:00
parent b46114cb6f
commit 3532ef05ed
3 changed files with 46 additions and 31 deletions

View File

@ -17,6 +17,7 @@ const loadingStores = ref(true)
const tablesTree = ref([]) const tablesTree = ref([])
watch(store, (s) => { watch(store, (s) => {
kind.value = ''
stores.value.forEach((e: Store) => { stores.value.forEach((e: Store) => {
if (e.name === s) { if (e.name === s) {
kind.value = e.kind.name kind.value = e.kind.name
@ -39,7 +40,8 @@ watch(kind, (k) => {
queryTip.value = 'Enter SQL query' queryTip.value = 'Enter SQL query'
executeQuery() executeQuery()
break; break;
case 'atest-store-etcd', 'atest-store-redis': case 'atest-store-etcd':
case 'atest-store-redis':
sqlQuery.value = '' sqlQuery.value = ''
queryTip.value = 'Enter key' queryTip.value = 'Enter key'
break; break;

View File

@ -120,7 +120,15 @@ func (s *inMemoryServer) Load() (err error) {
} }
memLogger.Info("redirect to", "target", api) memLogger.Info("redirect to", "target", api)
targetReq, err := http.NewRequestWithContext(req.Context(), req.Method, api, req.Body) var requestBody []byte
if requestBody, err = io.ReadAll(req.Body); err != nil {
w.WriteHeader(http.StatusInternalServerError)
}
if proxy.RequestAmend.BodyPatch != "" {
}
targetReq, err := http.NewRequestWithContext(req.Context(), req.Method, api, bytes.NewBuffer(requestBody))
if err != nil { if err != nil {
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
memLogger.Error(err, "failed to create proxy request") memLogger.Error(err, "failed to create proxy request")

View File

@ -16,54 +16,59 @@ limitations under the License.
package mock package mock
type Object struct { type Object struct {
Name string `yaml:"name" json:"name"` Name string `yaml:"name" json:"name"`
InitCount *int `yaml:"initCount" json:"initCount"` InitCount *int `yaml:"initCount" json:"initCount"`
Sample string `yaml:"sample" json:"sample"` Sample string `yaml:"sample" json:"sample"`
} }
type Item struct { type Item struct {
Name string `yaml:"name" json:"name"` Name string `yaml:"name" json:"name"`
Request Request `yaml:"request" json:"request"` Request Request `yaml:"request" json:"request"`
Response Response `yaml:"response" json:"response"` Response Response `yaml:"response" json:"response"`
Param map[string]string Param map[string]string
} }
type Request struct { type Request struct {
Path string `yaml:"path" json:"path"` Path string `yaml:"path" json:"path"`
Method string `yaml:"method" json:"method"` Method string `yaml:"method" json:"method"`
Header map[string]string `yaml:"header" json:"header"` Header map[string]string `yaml:"header" json:"header"`
Body string `yaml:"body" json:"body"` Body string `yaml:"body" json:"body"`
} }
type RequestWithAuth struct { type RequestWithAuth struct {
Request `yaml:",inline"` Request `yaml:",inline"`
BearerAPI string `yaml:"bearerAPI" json:"bearerAPI"` BearerAPI string `yaml:"bearerAPI" json:"bearerAPI"`
Username string `yaml:"username" json:"username"` Username string `yaml:"username" json:"username"`
Password string `yaml:"password" json:"password"` Password string `yaml:"password" json:"password"`
} }
type Response struct { type Response struct {
Encoder string `yaml:"encoder" json:"encoder"` Encoder string `yaml:"encoder" json:"encoder"`
Body string `yaml:"body" json:"body"` Body string `yaml:"body" json:"body"`
Header map[string]string `yaml:"header" json:"header"` Header map[string]string `yaml:"header" json:"header"`
StatusCode int `yaml:"statusCode" json:"statusCode"` StatusCode int `yaml:"statusCode" json:"statusCode"`
BodyData []byte BodyData []byte
} }
type Webhook struct { type Webhook struct {
Name string `yaml:"name" json:"name"` Name string `yaml:"name" json:"name"`
Timer string `yaml:"timer" json:"timer"` Timer string `yaml:"timer" json:"timer"`
Request RequestWithAuth `yaml:"request" json:"request"` Request RequestWithAuth `yaml:"request" json:"request"`
} }
type Proxy struct { type Proxy struct {
Path string `yaml:"path" json:"path"` Path string `yaml:"path" json:"path"`
Target string `yaml:"target" json:"target"` Target string `yaml:"target" json:"target"`
RequestAmend RequestAmend `yaml:"requestAmend" json:"requestAmend"`
}
type RequestAmend struct {
BodyPatch string `yaml:"bodyPatch" json:"bodyPatch"`
} }
type Server struct { type Server struct {
Objects []Object `yaml:"objects" json:"objects"` Objects []Object `yaml:"objects" json:"objects"`
Items []Item `yaml:"items" json:"items"` Items []Item `yaml:"items" json:"items"`
Proxies []Proxy `yaml:"proxies" json:"proxies"` Proxies []Proxy `yaml:"proxies" json:"proxies"`
Webhooks []Webhook `yaml:"webhooks" json:"webhooks"` Webhooks []Webhook `yaml:"webhooks" json:"webhooks"`
} }