This is an automated email from the ASF dual-hosted git repository.

abeizn pushed a commit to branch release-v0.17
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/release-v0.17 by this push:
     new 71ba0a7d9 cp(sonarqube): added proxy api, fixed search-remote-scope 
api (#5260)
71ba0a7d9 is described below

commit 71ba0a7d91da61b5999c4610dbbfbf0f9bd08b13
Author: Leric Zhang <[email protected]>
AuthorDate: Tue May 23 10:54:15 2023 +0800

    cp(sonarqube): added proxy api, fixed search-remote-scope api (#5260)
    
    * feat: add proxy api to sonarqube plugin (#5167)
    
    * fix(sonarqube): fix search-remote-scope api error, fix api document 
(#5259)
---
 .../helpers/pluginhelper/api/remote_api_helper.go  |  7 +--
 backend/plugins/sonarqube/api/connection.go        |  9 ++++
 backend/plugins/sonarqube/api/proxy.go             | 61 ++++++++++++++++++++++
 backend/plugins/sonarqube/api/remote.go            |  6 +--
 backend/plugins/sonarqube/api/scope.go             |  6 +--
 backend/plugins/sonarqube/impl/impl.go             |  3 ++
 6 files changed, 83 insertions(+), 9 deletions(-)

diff --git a/backend/helpers/pluginhelper/api/remote_api_helper.go 
b/backend/helpers/pluginhelper/api/remote_api_helper.go
index a34457e38..bc3f13738 100644
--- a/backend/helpers/pluginhelper/api/remote_api_helper.go
+++ b/backend/helpers/pluginhelper/api/remote_api_helper.go
@@ -21,12 +21,13 @@ import (
        "encoding/base64"
        "encoding/json"
        "fmt"
+       "net/http"
+       "strconv"
+
        coreContext "github.com/apache/incubator-devlake/core/context"
        "github.com/apache/incubator-devlake/core/errors"
        "github.com/apache/incubator-devlake/core/plugin"
        "github.com/go-playground/validator/v10"
-       "net/http"
-       "strconv"
 )
 
 type RemoteScopesChild struct {
@@ -160,7 +161,7 @@ func (r *RemoteApiHelper[Conn, Scope, ApiScope, Group]) 
GetScopesFromRemote(inpu
        gid := groupId[0]
        queryData, err := getPageDataFromPageToken(pageToken[0])
        if err != nil {
-               return nil, errors.BadInput.New("failed to get paget token")
+               return nil, errors.BadInput.New("failed to get page token")
        }
 
        outputBody := &RemoteScopesOutput{}
diff --git a/backend/plugins/sonarqube/api/connection.go 
b/backend/plugins/sonarqube/api/connection.go
index 8ca67b18e..9dc000e61 100644
--- a/backend/plugins/sonarqube/api/connection.go
+++ b/backend/plugins/sonarqube/api/connection.go
@@ -36,6 +36,7 @@ type SonarqubeTestConnResponse struct {
        Connection *models.SonarqubeConn
 }
 
+// TestConnection test sonarqube connection options
 // @Summary test sonarqube connection
 // @Description Test sonarqube Connection
 // @Tags plugins/sonarqube
@@ -82,6 +83,7 @@ func TestConnection(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutput,
        }
 }
 
+// PostConnections create sonarqube connection
 // @Summary create sonarqube connection
 // @Description Create sonarqube connection
 // @Tags plugins/sonarqube
@@ -100,10 +102,12 @@ func PostConnections(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutput,
        return &plugin.ApiResourceOutput{Body: connection, Status: 
http.StatusOK}, nil
 }
 
+// PatchConnection patch sonarqube connection
 // @Summary patch sonarqube connection
 // @Description Patch sonarqube connection
 // @Tags plugins/sonarqube
 // @Param body body models.SonarqubeConnection true "json body"
+// @Param connectionId path int false "connection ID"
 // @Success 200  {object} models.SonarqubeConnection
 // @Failure 400  {string} errcode.Error "Bad Request"
 // @Failure 500  {string} errcode.Error "Internal Error"
@@ -117,9 +121,11 @@ func PatchConnection(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutput,
        return &plugin.ApiResourceOutput{Body: connection}, nil
 }
 
+// DeleteConnection delete a sonarqube connection
 // @Summary delete a sonarqube connection
 // @Description Delete a sonarqube connection
 // @Tags plugins/sonarqube
+// @Param connectionId path int false "connection ID"
 // @Success 200  {object} models.SonarqubeConnection
 // @Failure 400  {string} errcode.Error "Bad Request"
 // @Failure 500  {string} errcode.Error "Internal Error"
@@ -134,6 +140,7 @@ func DeleteConnection(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutput
        return &plugin.ApiResourceOutput{Body: connection}, err
 }
 
+// ListConnections get all sonarqube connections
 // @Summary get all sonarqube connections
 // @Description Get all sonarqube connections
 // @Tags plugins/sonarqube
@@ -150,9 +157,11 @@ func ListConnections(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutput,
        return &plugin.ApiResourceOutput{Body: connections, Status: 
http.StatusOK}, nil
 }
 
+// GetConnection get sonarqube connection detail
 // @Summary get sonarqube connection detail
 // @Description Get sonarqube connection detail
 // @Tags plugins/sonarqube
+// @Param connectionId path int false "connection ID"
 // @Success 200  {object} models.SonarqubeConnection
 // @Failure 400  {string} errcode.Error "Bad Request"
 // @Failure 500  {string} errcode.Error "Internal Error"
diff --git a/backend/plugins/sonarqube/api/proxy.go 
b/backend/plugins/sonarqube/api/proxy.go
new file mode 100644
index 000000000..ed5b0a4a2
--- /dev/null
+++ b/backend/plugins/sonarqube/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/sonarqube/models"
+)
+
+// Proxy proxy api request to upstream sonarqube
+// @Summary proxy api request to upstream sonarqube
+// @Description Proxy HTTP GET request to the sonarqube behind this connection.
+// @Tags plugins/sonarqube
+// @Param connectionId path int false "connection ID"
+// @Param path path string false "API Path"
+// @Success 200  {object} interface{} "Success"
+// @Failure 400  {string} errcode.Error "Bad Request"
+// @Failure 500  {string} errcode.Error "Internal Error"
+// @Router /plugins/sonarqube/connections/{connectionId}/proxy/rest/{*path} 
[GET]
+func Proxy(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, 
errors.Error) {
+       connection := &models.SonarqubeConnection{}
+       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/sonarqube/api/remote.go 
b/backend/plugins/sonarqube/api/remote.go
index 5e29e4615..7d885e9bc 100644
--- a/backend/plugins/sonarqube/api/remote.go
+++ b/backend/plugins/sonarqube/api/remote.go
@@ -73,6 +73,7 @@ func RemoteScopes(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutput, er
 // @Tags plugins/sonarqube
 // @Accept application/json
 // @Param connectionId path int false "connection ID"
+// @Param search query string false "search keyword"
 // @Param page query int false "page number"
 // @Param pageSize query int false "page size per page"
 // @Success 200  {object} api.SearchRemoteScopesOutput
@@ -80,9 +81,8 @@ func RemoteScopes(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutput, er
 // @Failure 500  {object} shared.ApiBody "Internal Error"
 // @Router /plugins/sonarqube/connections/{connectionId}/search-remote-scopes 
[GET]
 func SearchRemoteScopes(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutput, errors.Error) {
-       return remoteHelper.GetScopesFromRemote(input,
-               nil,
-               func(basicRes context2.BasicRes, gid string, queryData 
*api.RemoteQueryData, connection models.SonarqubeConnection) 
([]models.SonarqubeApiProject, errors.Error) {
+       return remoteHelper.SearchRemoteScopes(input,
+               func(basicRes context2.BasicRes, queryData 
*api.RemoteQueryData, connection models.SonarqubeConnection) 
([]models.SonarqubeApiProject, errors.Error) {
                        query := initialQuery(queryData)
                        query.Set("q", queryData.Search[0])
                        // create api client
diff --git a/backend/plugins/sonarqube/api/scope.go 
b/backend/plugins/sonarqube/api/scope.go
index 3d46b2ef7..e2946eec3 100644
--- a/backend/plugins/sonarqube/api/scope.go
+++ b/backend/plugins/sonarqube/api/scope.go
@@ -67,10 +67,12 @@ func UpdateScope(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutput, err
 // @Description get Sonarqube projects
 // @Tags plugins/sonarqube
 // @Param connectionId path int false "connection ID"
+// @Param pageSize query int false "page size, default 50"
+// @Param page query int false "page size, default 1"
 // @Success 200  {object} []ScopeRes
 // @Failure 400  {object} shared.ApiBody "Bad Request"
 // @Failure 500  {object} shared.ApiBody "Internal Error"
-// @Router /plugins/sonarqube/connections/{connectionId}/scopes/ [GET]
+// @Router /plugins/sonarqube/connections/{connectionId}/scopes [GET]
 func GetScopeList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, 
errors.Error) {
        return scopeHelper.GetScopeList(input)
 }
@@ -81,8 +83,6 @@ func GetScopeList(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutput, er
 // @Tags plugins/sonarqube
 // @Param connectionId path int false "connection ID"
 // @Param scopeId path string false "project key"
-// @Param pageSize query int false "page size, default 50"
-// @Param page query int false "page size, default 1"
 // @Success 200  {object} ScopeRes
 // @Failure 400  {object} shared.ApiBody "Bad Request"
 // @Failure 500  {object} shared.ApiBody "Internal Error"
diff --git a/backend/plugins/sonarqube/impl/impl.go 
b/backend/plugins/sonarqube/impl/impl.go
index 92359d6dd..0457685e3 100644
--- a/backend/plugins/sonarqube/impl/impl.go
+++ b/backend/plugins/sonarqube/impl/impl.go
@@ -180,6 +180,9 @@ func (p Sonarqube) ApiResources() 
map[string]map[string]plugin.ApiResourceHandle
                        "GET": api.GetScopeList,
                        "PUT": api.PutScope,
                },
+               "connections/:connectionId/proxy/rest/*path": {
+                       "GET": api.Proxy,
+               },
        }
 }
 

Reply via email to