MCPcopy Index your code
hub / github.com/apache/devlake / testConnection

Function testConnection

backend/plugins/ae/api/connection.go:35–58  ·  view source on GitHub ↗
(ctx context.Context, connection models.AeConn)

Source from the content-addressed store, hash-verified

33}
34
35func testConnection(ctx context.Context, connection models.AeConn) (*plugin.ApiResourceOutput, errors.Error) {
36 // validate
37 if vld != nil {
38 if err := vld.Struct(connection); err != nil {
39 return nil, errors.Default.Wrap(err, "error validating target")
40 }
41 }
42 apiClient, err := api.NewApiClientFromConnection(ctx, basicRes, &connection)
43 if err != nil {
44 return nil, err
45 }
46 res, err := apiClient.Get("projects", nil, nil)
47 if err != nil {
48 return nil, err
49 }
50 switch res.StatusCode {
51 case 200: // right StatusCode
52 return &plugin.ApiResourceOutput{Body: true, Status: 200}, nil
53 case 401: // error secretKey or nonceStr
54 return &plugin.ApiResourceOutput{Body: false, Status: http.StatusBadRequest}, nil
55 default: // unknown what happen , back to user
56 return &plugin.ApiResourceOutput{Body: res.Body, Status: res.StatusCode}, nil
57 }
58}
59
60// TestConnection test ae connection
61// @Summary test ae connection

Callers 3

TestConnectionFunction · 0.70
TestExistingConnectionFunction · 0.70
handleTestFunction · 0.50

Calls 2

WrapMethod · 0.80
GetMethod · 0.65

Tested by 2

TestConnectionFunction · 0.56
TestExistingConnectionFunction · 0.56