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

Function testConnection

backend/plugins/argocd/api/connection_api.go:38–72  ·  view source on GitHub ↗
(ctx context.Context, connection models.ArgocdConn)

Source from the content-addressed store, hash-verified

36}
37
38func testConnection(ctx context.Context, connection models.ArgocdConn) (*ArgocdTestConnResponse, errors.Error) {
39 // validate
40 if vld != nil {
41 if err := vld.Struct(connection); err != nil {
42 return nil, errors.Default.Wrap(err, "error validating target")
43 }
44 }
45 apiClient, err := api.NewApiClientFromConnection(ctx, basicRes, &connection)
46 if err != nil {
47 return nil, err
48 }
49
50 // Test ArgoCD API by listing applications
51 query := url.Values{}
52 res, err := apiClient.Get("applications", query, nil)
53 if err != nil {
54 return nil, err
55 }
56
57 if res.StatusCode == http.StatusUnauthorized {
58 return nil, errors.HttpStatus(http.StatusBadRequest).New("StatusUnauthorized error - check your token")
59 }
60
61 if res.StatusCode == http.StatusForbidden {
62 return nil, errors.BadInput.New("token lacks required permissions")
63 }
64
65 connection = connection.Sanitize()
66 body := ArgocdTestConnResponse{}
67 body.Success = true
68 body.Message = "success"
69 body.Connection = &connection
70
71 return &body, nil
72}
73
74// TestConnection test argocd connection
75// @Summary test argocd connection

Callers 2

TestConnectionFunction · 0.70
TestExistingConnectionFunction · 0.70

Calls 4

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

Tested by 2

TestConnectionFunction · 0.56
TestExistingConnectionFunction · 0.56