You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by zh...@apache.org on 2023/08/14 12:12:05 UTC
[incubator-devlake] branch add-proxy-to-zentao created (now 7ce6703a3)
This is an automated email from the ASF dual-hosted git repository.
zhangliang2022 pushed a change to branch add-proxy-to-zentao
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
at 7ce6703a3 feat: adding proxy API for the zentao plugin
This branch includes the following new commits:
new 7ce6703a3 feat: adding proxy API for the zentao plugin
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[incubator-devlake] 01/01: feat: adding proxy API for the zentao plugin
Posted by zh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
zhangliang2022 pushed a commit to branch add-proxy-to-zentao
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
commit 7ce6703a3ead51fa2cf09e3bc7b644e496fdb4c9
Author: zhangliang <li...@merico.dev>
AuthorDate: Mon Aug 14 20:11:40 2023 +0800
feat: adding proxy API for the zentao plugin
---
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,
+ },
}
}