feat: support proxy request body amend in mock
This commit is contained in:
parent
b46114cb6f
commit
3532ef05ed
|
@ -17,6 +17,7 @@ const loadingStores = ref(true)
|
|||
|
||||
const tablesTree = ref([])
|
||||
watch(store, (s) => {
|
||||
kind.value = ''
|
||||
stores.value.forEach((e: Store) => {
|
||||
if (e.name === s) {
|
||||
kind.value = e.kind.name
|
||||
|
@ -39,7 +40,8 @@ watch(kind, (k) => {
|
|||
queryTip.value = 'Enter SQL query'
|
||||
executeQuery()
|
||||
break;
|
||||
case 'atest-store-etcd', 'atest-store-redis':
|
||||
case 'atest-store-etcd':
|
||||
case 'atest-store-redis':
|
||||
sqlQuery.value = ''
|
||||
queryTip.value = 'Enter key'
|
||||
break;
|
||||
|
|
|
@ -120,7 +120,15 @@ func (s *inMemoryServer) Load() (err error) {
|
|||
}
|
||||
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 {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
memLogger.Error(err, "failed to create proxy request")
|
||||
|
|
|
@ -16,54 +16,59 @@ limitations under the License.
|
|||
package mock
|
||||
|
||||
type Object struct {
|
||||
Name string `yaml:"name" json:"name"`
|
||||
InitCount *int `yaml:"initCount" json:"initCount"`
|
||||
Sample string `yaml:"sample" json:"sample"`
|
||||
Name string `yaml:"name" json:"name"`
|
||||
InitCount *int `yaml:"initCount" json:"initCount"`
|
||||
Sample string `yaml:"sample" json:"sample"`
|
||||
}
|
||||
|
||||
type Item struct {
|
||||
Name string `yaml:"name" json:"name"`
|
||||
Request Request `yaml:"request" json:"request"`
|
||||
Response Response `yaml:"response" json:"response"`
|
||||
Param map[string]string
|
||||
Name string `yaml:"name" json:"name"`
|
||||
Request Request `yaml:"request" json:"request"`
|
||||
Response Response `yaml:"response" json:"response"`
|
||||
Param map[string]string
|
||||
}
|
||||
|
||||
type Request struct {
|
||||
Path string `yaml:"path" json:"path"`
|
||||
Method string `yaml:"method" json:"method"`
|
||||
Header map[string]string `yaml:"header" json:"header"`
|
||||
Body string `yaml:"body" json:"body"`
|
||||
Path string `yaml:"path" json:"path"`
|
||||
Method string `yaml:"method" json:"method"`
|
||||
Header map[string]string `yaml:"header" json:"header"`
|
||||
Body string `yaml:"body" json:"body"`
|
||||
}
|
||||
|
||||
type RequestWithAuth struct {
|
||||
Request `yaml:",inline"`
|
||||
BearerAPI string `yaml:"bearerAPI" json:"bearerAPI"`
|
||||
Username string `yaml:"username" json:"username"`
|
||||
Password string `yaml:"password" json:"password"`
|
||||
Request `yaml:",inline"`
|
||||
BearerAPI string `yaml:"bearerAPI" json:"bearerAPI"`
|
||||
Username string `yaml:"username" json:"username"`
|
||||
Password string `yaml:"password" json:"password"`
|
||||
}
|
||||
|
||||
type Response struct {
|
||||
Encoder string `yaml:"encoder" json:"encoder"`
|
||||
Body string `yaml:"body" json:"body"`
|
||||
Header map[string]string `yaml:"header" json:"header"`
|
||||
StatusCode int `yaml:"statusCode" json:"statusCode"`
|
||||
BodyData []byte
|
||||
Encoder string `yaml:"encoder" json:"encoder"`
|
||||
Body string `yaml:"body" json:"body"`
|
||||
Header map[string]string `yaml:"header" json:"header"`
|
||||
StatusCode int `yaml:"statusCode" json:"statusCode"`
|
||||
BodyData []byte
|
||||
}
|
||||
|
||||
type Webhook struct {
|
||||
Name string `yaml:"name" json:"name"`
|
||||
Timer string `yaml:"timer" json:"timer"`
|
||||
Request RequestWithAuth `yaml:"request" json:"request"`
|
||||
Name string `yaml:"name" json:"name"`
|
||||
Timer string `yaml:"timer" json:"timer"`
|
||||
Request RequestWithAuth `yaml:"request" json:"request"`
|
||||
}
|
||||
|
||||
type Proxy struct {
|
||||
Path string `yaml:"path" json:"path"`
|
||||
Target string `yaml:"target" json:"target"`
|
||||
Path string `yaml:"path" json:"path"`
|
||||
Target string `yaml:"target" json:"target"`
|
||||
RequestAmend RequestAmend `yaml:"requestAmend" json:"requestAmend"`
|
||||
}
|
||||
|
||||
type RequestAmend struct {
|
||||
BodyPatch string `yaml:"bodyPatch" json:"bodyPatch"`
|
||||
}
|
||||
|
||||
type Server struct {
|
||||
Objects []Object `yaml:"objects" json:"objects"`
|
||||
Items []Item `yaml:"items" json:"items"`
|
||||
Proxies []Proxy `yaml:"proxies" json:"proxies"`
|
||||
Webhooks []Webhook `yaml:"webhooks" json:"webhooks"`
|
||||
Objects []Object `yaml:"objects" json:"objects"`
|
||||
Items []Item `yaml:"items" json:"items"`
|
||||
Proxies []Proxy `yaml:"proxies" json:"proxies"`
|
||||
Webhooks []Webhook `yaml:"webhooks" json:"webhooks"`
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue