MCPcopy
hub / github.com/apache/devlake / testConnection

Function testConnection

backend/plugins/asana/api/connection_api.go:36–65  ·  view source on GitHub ↗
(ctx context.Context, connection models.AsanaConn)

Source from the content-addressed store, hash-verified

34}
35
36func testConnection(ctx context.Context, connection models.AsanaConn) (*AsanaTestConnResponse, errors.Error) {
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 if connection.GetEndpoint() == "" {
43 connection.Endpoint = defaultAsanaEndpoint
44 }
45 apiClient, err := helper.NewApiClientFromConnection(ctx, basicRes, &connection)
46 if err != nil {
47 return nil, err
48 }
49 res, err := apiClient.Get("users/me", nil, nil)
50 if err != nil {
51 return nil, errors.BadInput.Wrap(err, "verify token failed")
52 }
53 if res.StatusCode == http.StatusUnauthorized {
54 return nil, errors.HttpStatus(http.StatusBadRequest).New("StatusUnauthorized error while testing connection")
55 }
56 if res.StatusCode != http.StatusOK {
57 return nil, errors.HttpStatus(res.StatusCode).New("unexpected status code while testing connection")
58 }
59 connection = connection.Sanitize()
60 body := AsanaTestConnResponse{}
61 body.Success = true
62 body.Message = "success"
63 body.Connection = &connection
64 return &body, nil
65}
66
67func TestConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
68 var connection models.AsanaConn

Callers 2

TestConnectionFunction · 0.70
TestExistingConnectionFunction · 0.70

Calls 5

WrapMethod · 0.80
GetEndpointMethod · 0.65
GetMethod · 0.65
NewMethod · 0.65
SanitizeMethod · 0.45

Tested by 2

TestConnectionFunction · 0.56
TestExistingConnectionFunction · 0.56