keon94 commented on code in PR #3096: URL: https://github.com/apache/incubator-devlake/pull/3096#discussion_r974838080
########## plugins/linear/api/connection.go: ########## @@ -0,0 +1,149 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package api + +import ( + "context" + "fmt" + "net/http" + "time" + + "github.com/apache/incubator-devlake/errors" + "github.com/apache/incubator-devlake/plugins/core" + "github.com/apache/incubator-devlake/plugins/helper" + "github.com/apache/incubator-devlake/plugins/linear/models" +) + +// TODO Please modify the following code to fit your needs +func TestConnection(input *core.ApiResourceInput) (*core.ApiResourceOutput, errors.Error) { + // decode + var err errors.Error + var connection models.TestConnectionRequest + if err = helper.Decode(input.Body, &connection, vld); err != nil { + return nil, err + } + // test connection + apiClient, err := helper.NewApiClient( + context.TODO(), + connection.Endpoint, + map[string]string{ + "Authorization": fmt.Sprintf("Bearer %v", connection.Token), + }, + 3*time.Second, + connection.Proxy, + basicRes, + ) + if err != nil { + return nil, err + } + + res, err := apiClient.Get("user", nil, nil) + if err != nil { + return nil, err + } + resBody := &models.ApiUserResponse{} + err = helper.UnmarshalResponse(res, resBody) + if err != nil { + return nil, err + } + + if res.StatusCode != http.StatusOK { + return nil, errors.HttpStatus(res.StatusCode).New(fmt.Sprintf("unexpected status code: %d", res.StatusCode)) + } + return nil, nil +} + +//TODO Please modify the folowing code to adapt to your plugin +/* +POST /plugins/linear/connections +{ + "name": "Linear data connection name", + "endpoint": "Linear api endpoint, i.e. https://example.com", + "username": "username, usually should be email address", + "password": "Linear api access token" +} +*/ +func PostConnections(input *core.ApiResourceInput) (*core.ApiResourceOutput, errors.Error) { Review Comment: This is the API you need to hit to create a connection object for Linear. You will need to pass in a JSON struct as part of the body of the http call, and this JSON struct should take the structure of your ```models.LinearConnection``` struct as key-value pairs. -- 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]
