You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by wa...@apache.org on 2023/02/17 06:30:42 UTC
[incubator-devlake] branch main updated: fix(bamboo): simplify test connectino and use json instead of xml (#4440)
This is an automated email from the ASF dual-hosted git repository.
warren 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 ba76400b1 fix(bamboo): simplify test connectino and use json instead of xml (#4440)
ba76400b1 is described below
commit ba76400b18c497497d0330b9bea7072e415cc9f2
Author: Warren Chen <yi...@merico.dev>
AuthorDate: Fri Feb 17 14:30:38 2023 +0800
fix(bamboo): simplify test connectino and use json instead of xml (#4440)
---
backend/plugins/bamboo/api/connection.go | 2 +-
backend/plugins/bamboo/models/connection.go | 61 ++++++-----------------------
2 files changed, 13 insertions(+), 50 deletions(-)
diff --git a/backend/plugins/bamboo/api/connection.go b/backend/plugins/bamboo/api/connection.go
index c516c3206..ca627af97 100644
--- a/backend/plugins/bamboo/api/connection.go
+++ b/backend/plugins/bamboo/api/connection.go
@@ -40,7 +40,7 @@ type BambooTestConnResponse struct {
// @Success 200 {object} BambooTestConnResponse "Success"
// @Failure 400 {string} errcode.Error "Bad Request"
// @Failure 500 {string} errcode.Error "Internal Error"
-// @Router /plugins/Bamboo/test [POST]
+// @Router /plugins/bamboo/test [POST]
func TestConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
// decode
var err errors.Error
diff --git a/backend/plugins/bamboo/models/connection.go b/backend/plugins/bamboo/models/connection.go
index 88520d463..87486dec1 100644
--- a/backend/plugins/bamboo/models/connection.go
+++ b/backend/plugins/bamboo/models/connection.go
@@ -18,9 +18,9 @@ limitations under the License.
package models
import (
- "encoding/xml"
"fmt"
"net/http"
+ "time"
"github.com/apache/incubator-devlake/core/errors"
"github.com/apache/incubator-devlake/helpers/pluginhelper/api"
@@ -45,31 +45,11 @@ func (conn *BambooConn) PrepareApiClient(apiClient apihelperabstract.ApiClientAb
header := http.Header{}
header.Set("Authorization", fmt.Sprintf("Bearer %v", conn.Token))
- res, err := apiClient.Get("", nil, header)
+ res, err := apiClient.Get("info.json", nil, header)
if err != nil {
return errors.HttpStatus(400).New(fmt.Sprintf("Get failed %s", err.Error()))
}
- resources := &ApiXMLResourcesResponse{}
-
- if res.StatusCode != http.StatusOK {
- return errors.HttpStatus(res.StatusCode).New(fmt.Sprintf("unexpected status code: %d", res.StatusCode))
- }
-
- err = api.UnmarshalResponseXML(res, resources)
-
- if err != nil {
- return errors.HttpStatus(500).New(fmt.Sprintf("UnmarshalResponse failed %s", err.Error()))
- }
-
- if resources.Link.Href != conn.Endpoint {
- return errors.HttpStatus(400).New(fmt.Sprintf("Response Data error for connection endpoint: %s, it should like: http://{domain}/rest/api/latest/", conn.Endpoint))
- }
-
- res, err = apiClient.Get("repository", nil, header)
- if err != nil {
- return errors.HttpStatus(400).New(fmt.Sprintf("Get failed %s", err.Error()))
- }
- repo := &ApiRepository{}
+ repo := &ApiBambooServerInfo{}
if res.StatusCode != http.StatusOK {
return errors.HttpStatus(res.StatusCode).New(fmt.Sprintf("unexpected status code: %d", res.StatusCode))
@@ -78,7 +58,7 @@ func (conn *BambooConn) PrepareApiClient(apiClient apihelperabstract.ApiClientAb
err = api.UnmarshalResponse(res, repo)
if err != nil {
- return errors.HttpStatus(400).New(fmt.Sprintf("UnmarshalResponse repository failed %s", err.Error()))
+ return errors.BadInput.New(fmt.Sprintf("UnmarshalResponse repository failed %s", err.Error()))
}
return nil
@@ -91,6 +71,14 @@ type BambooResponse struct {
BambooConnection
}
+type ApiBambooServerInfo struct {
+ Version string `json:"version"`
+ Edition string `json:"edition"`
+ BuildDate time.Time `json:"buildDate"`
+ BuildNumber string `json:"buildNumber"`
+ State string `json:"state"`
+}
+
type ApiRepository struct {
Size int `json:"size"`
SearchResults interface{} `json:"searchResults"`
@@ -98,31 +86,6 @@ type ApiRepository struct {
MaxResult int `json:"max-result"`
}
-type ApiXMLLink struct {
- XMLName xml.Name `json:"xml_name" xml:"link"`
- Href string `json:"href" xml:"href,attr"`
-}
-
-type ApiXMLResource struct {
- XMLName xml.Name `json:"xml_name" xml:"resource"`
- Name string `json:"name" xml:"name,attr"`
-}
-
-type ApiXMLResources struct {
- XMLName xml.Name `json:"xml_name" xml:"resources"`
- Size string `json:"size" xml:"size,attr"`
- Resources []ApiXMLResource `json:"resource" xml:"resource"`
-}
-
-// Using User because it requires authentication.
-type ApiXMLResourcesResponse struct {
- XMLName xml.Name `json:"xml_name" xml:"resources"`
- Expand string `json:"expand" xml:"expand,attr"`
-
- Link ApiXMLLink `json:"link" xml:"link"`
- Resources ApiXMLResources `json:"resources" xml:"resources"`
-}
-
func (BambooConnection) TableName() string {
return "_tool_bamboo_connections"
}