This is an automated email from the ASF dual-hosted git repository. zhangliang2022 pushed a commit to branch cherry-pick#5869 in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
commit e08da5adbda6ae04efd420def95d0377054bf26d Author: Liang Zhang <[email protected]> AuthorDate: Mon Aug 14 20:37:16 2023 +0800 feat: adding proxy API for the zentao plugin (#5869) --- backend/plugins/zentao/api/proxy.go | 61 +++++++++++++++++++++++++++++++++++++ backend/plugins/zentao/impl/impl.go | 3 ++ 2 files changed, 64 insertions(+) diff --git a/backend/plugins/zentao/api/proxy.go b/backend/plugins/zentao/api/proxy.go new file mode 100644 index 000000000..91da596ee --- /dev/null +++ b/backend/plugins/zentao/api/proxy.go @@ -0,0 +1,61 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package api + +import ( + "context" + "io" + + "github.com/apache/incubator-devlake/core/errors" + "github.com/apache/incubator-devlake/core/plugin" + helper "github.com/apache/incubator-devlake/helpers/pluginhelper/api" + "github.com/apache/incubator-devlake/plugins/zentao/models" +) + +// Proxy is a proxy to Zentao API +// @Summary Proxy to Zentao API +// @Description Proxy to Zentao API +// @Tags plugins/zentao +// @Param connectionId path int true "connection ID" +// @Param path path string true "path to Zentao API" +// @Success 200 {object} ZentaoTestConnResponse "Success" +// @Failure 400 {string} errcode.Error "Bad Request" +// @Failure 500 {string} errcode.Error "Internal Error" +// @Router /plugins/zentao/connections/{connectionId}/proxy/{path} [GET] +func Proxy(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { + connection := &models.ZentaoConnection{} + err := connectionHelper.First(connection, input.Params) + if err != nil { + return nil, err + } + apiClient, err := helper.NewApiClientFromConnection(context.TODO(), basicRes, connection) + if err != nil { + return nil, err + } + resp, err := apiClient.Get(input.Params["path"], input.Query, nil) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + body, err := errors.Convert01(io.ReadAll(resp.Body)) + if err != nil { + return nil, err + } + return &plugin.ApiResourceOutput{Status: resp.StatusCode, ContentType: resp.Header.Get("Content-Type"), Body: body}, nil +} diff --git a/backend/plugins/zentao/impl/impl.go b/backend/plugins/zentao/impl/impl.go index c0a9b41f5..d90652c1b 100644 --- a/backend/plugins/zentao/impl/impl.go +++ b/backend/plugins/zentao/impl/impl.go @@ -278,6 +278,9 @@ func (p Zentao) ApiResources() map[string]map[string]plugin.ApiResourceHandler { "connections/:connectionId/remote-scopes": { "GET": api.RemoteScopes, }, + "connections/:connectionId/proxy/*path": { + "GET": api.Proxy, + }, } }
