klesh commented on code in PR #6494:
URL:
https://github.com/apache/incubator-devlake/pull/6494#discussion_r1402976168
##########
backend/plugins/ae/impl/impl.go:
##########
@@ -139,6 +139,9 @@ func (p AE) ApiResources()
map[string]map[string]plugin.ApiResourceHandler {
"PATCH": api.PatchConnection,
"DELETE": api.DeleteConnection,
},
+ "connections/:connectionId/test": {
+ "POST": api.TestConnectionV2,
Review Comment:
How about naming it as `TestExistingConnection` or `TestEncryptedConnection`
since it can not replace the previous `TestConnection` function and they must
co-exist in the future?
##########
backend/plugins/ae/api/connection.go:
##########
@@ -32,6 +32,33 @@ type ApiMeResponse struct {
Name string `json:"name"`
}
+func testConnection(ctx context.Context, connection models.AeConn)
(*plugin.ApiResourceOutput, errors.Error) {
+ // validate
+ if vld != nil {
+ if err := vld.Struct(connection); err != nil {
+ return nil, errors.Default.Wrap(err, "error validating
target")
+ }
+ }
+ apiClient, err := api.NewApiClientFromConnection(ctx, basicRes,
&connection)
+ if err != nil {
+ return nil, err
+ }
+ res, err := apiClient.Get("projects", nil, nil)
+ if err != nil {
+ return nil, err
+ }
+ switch res.StatusCode {
+ case 200: // right StatusCode
+ return &plugin.ApiResourceOutput{Body: true, Status: 200}, nil
+ case 401: // error secretKey or nonceStr
+ return &plugin.ApiResourceOutput{Body: false, Status:
http.StatusBadRequest}, nil
+ default: // unknow what happen , back to user
+ return &plugin.ApiResourceOutput{Body: res.Body, Status:
res.StatusCode}, nil
+ }
+}
+
+// TestConnection test ae connection
+// Deprecated
Review Comment:
I think this method should be kept because users may want to test the
connection before actually creating it.
##########
backend/plugins/ae/models/connection.go:
##########
@@ -65,6 +65,11 @@ func (AeConnection) TableName() string {
return "_tool_ae_connections"
}
+func (connection AeConnection) CleanUp() AeConnection {
Review Comment:
Will it be better to define a function named `SanatizeEncFields` that will
iterate all fields with tag `gorm:"serializer:encdec"` including those inside
nested structs and set them to empty strings?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]