| /* |
| 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 ( |
| "github.com/apache/incubator-devlake/config" |
| "github.com/apache/incubator-devlake/plugins/ae/models" |
| "github.com/apache/incubator-devlake/plugins/core" |
| "github.com/apache/incubator-devlake/plugins/helper" |
| "net/http" |
| ) |
| |
| type ApiMeResponse struct { |
| Name string `json:"name"` |
| } |
| |
| /* |
| GET /plugins/ae/test |
| */ |
| func TestConnection(input *core.ApiResourceInput) (*core.ApiResourceOutput, error) { |
| // TODO: implement test connection |
| return &core.ApiResourceOutput{Body: true}, nil |
| } |
| |
| /* |
| PATCH /plugins/ae/connections/:connectionId |
| */ |
| func PatchConnection(input *core.ApiResourceInput) (*core.ApiResourceOutput, error) { |
| v := config.GetConfig() |
| connection := &models.AeConnection{} |
| err := helper.EncodeStruct(v, connection, "env") |
| if err != nil { |
| return nil, err |
| } |
| // update from request and save to .env |
| err = helper.DecodeStruct(v, connection, input.Body, "env") |
| if err != nil { |
| return nil, err |
| } |
| err = config.WriteConfig(v) |
| if err != nil { |
| return nil, err |
| } |
| response := models.AeResponse{ |
| AeConnection: *connection, |
| Name: "Ae", |
| ID: 1, |
| } |
| return &core.ApiResourceOutput{Body: response, Status: http.StatusOK}, nil |
| } |
| |
| /* |
| GET /plugins/ae/connections |
| */ |
| func ListConnections(input *core.ApiResourceInput) (*core.ApiResourceOutput, error) { |
| // RETURN ONLY 1 SOURCE (FROM ENV) until multi-connection is developed. |
| v := config.GetConfig() |
| connection := &models.AeConnection{} |
| |
| err := helper.EncodeStruct(v, connection, "env") |
| if err != nil { |
| return nil, err |
| } |
| response := models.AeResponse{ |
| AeConnection: *connection, |
| Name: "Ae", |
| ID: 1, |
| } |
| |
| return &core.ApiResourceOutput{Body: []models.AeResponse{response}}, nil |
| } |
| |
| /* |
| GET /plugins/ae/connections/:connectionId |
| */ |
| func GetConnection(input *core.ApiResourceInput) (*core.ApiResourceOutput, error) { |
| // RETURN ONLY 1 SOURCE FROM ENV (Ignore ID until multi-connection is developed.) |
| v := config.GetConfig() |
| connection := &models.AeConnection{} |
| err := helper.EncodeStruct(v, connection, "env") |
| if err != nil { |
| return nil, err |
| } |
| response := &models.AeResponse{ |
| AeConnection: *connection, |
| Name: "Ae", |
| ID: 1, |
| } |
| return &core.ApiResourceOutput{Body: response}, nil |
| } |