| /* |
| 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" |
| "io" |
| "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/jira/models" |
| ) |
| |
| func Proxy(input *core.ApiResourceInput) (*core.ApiResourceOutput, errors.Error) { |
| connection := &models.JiraConnection{} |
| err := connectionHelper.First(connection, input.Params) |
| if err != nil { |
| return nil, err |
| } |
| headers := map[string]string{ |
| "Authorization": fmt.Sprintf("Basic %v", connection.GetEncodedToken()), |
| } |
| if connection.Username == "_BEARER_TOKEN_" { |
| headers["Authorization"] = fmt.Sprintf("Bearer %v", connection.Password) |
| } |
| apiClient, err := helper.NewApiClient( |
| context.TODO(), |
| connection.Endpoint, |
| headers, |
| 30*time.Second, |
| connection.Proxy, |
| basicRes, |
| ) |
| if err != nil { |
| return nil, err |
| } |
| resp, err := apiClient.Get(input.Params["path"], input.Query, nil) |
| if err != nil { |
| return nil, err |
| } |
| defer resp.Body.Close() |
| |
| body, err := errors.Convert01(io.ReadAll(resp.Body)) |
| if err != nil { |
| return nil, err |
| } |
| return &core.ApiResourceOutput{Status: resp.StatusCode, ContentType: resp.Header.Get("Content-Type"), Body: body}, nil |
| } |