You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by ab...@apache.org on 2023/05/22 10:09:23 UTC
[incubator-devlake] branch main updated: feat: add proxy api to sonarqube plugin (#5167)
This is an automated email from the ASF dual-hosted git repository.
abeizn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/main by this push:
new 53083ff44 feat: add proxy api to sonarqube plugin (#5167)
53083ff44 is described below
commit 53083ff44372cd0f828b7656ffc0c2e1972f3c85
Author: Leric Zhang <li...@merico.dev>
AuthorDate: Mon May 22 18:09:18 2023 +0800
feat: add proxy api to sonarqube plugin (#5167)
---
backend/plugins/sonarqube/api/proxy.go | 51 ++++++++++++++++++++++++++++++++++
backend/plugins/sonarqube/impl/impl.go | 3 ++
2 files changed, 54 insertions(+)
diff --git a/backend/plugins/sonarqube/api/proxy.go b/backend/plugins/sonarqube/api/proxy.go
new file mode 100644
index 000000000..381907ece
--- /dev/null
+++ b/backend/plugins/sonarqube/api/proxy.go
@@ -0,0 +1,51 @@
+/*
+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"
+)
+
+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/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,
+ },
}
}