MCPcopy
hub / github.com/apache/devlake / NewApiClientFromConnection

Function NewApiClientFromConnection

backend/helpers/pluginhelper/api/api_client.go:73–102  ·  view source on GitHub ↗

NewApiClientFromConnection creates ApiClient based on given connection.

(
	ctx gocontext.Context,
	br context.BasicRes,
	connection plugin.ApiConnection,
)

Source from the content-addressed store, hash-verified

71
72// NewApiClientFromConnection creates ApiClient based on given connection.
73func NewApiClientFromConnection(
74 ctx gocontext.Context,
75 br context.BasicRes,
76 connection plugin.ApiConnection,
77) (*ApiClient, errors.Error) {
78 if reflect.ValueOf(connection).Kind() != reflect.Ptr {
79 panic(fmt.Errorf("connection is not a pointer"))
80 }
81 apiClient, err := NewApiClient(ctx, connection.GetEndpoint(), nil, 0, connection.GetProxy(), br)
82 if err != nil {
83 return nil, err
84 }
85
86 // if connection needs to prepare the ApiClient, i.e. fetch token for future requests
87 if prepareApiClient, ok := connection.(plugin.PrepareApiClient); ok {
88 err = prepareApiClient.PrepareApiClient(apiClient)
89 if err != nil {
90 return nil, err
91 }
92 }
93
94 // if connection requires authorization
95 if authenticator, ok := connection.(plugin.ApiAuthenticator); ok {
96 apiClient.SetAuthFunction(func(req *http.Request) errors.Error {
97 return authenticator.SetupAuthentication(req)
98 })
99 }
100
101 return apiClient, nil
102}
103
104// NewApiClient creates a new synchronize ApiClient
105func NewApiClient(

Callers 2

getApiClientMethod · 0.85
GetApiClientMethod · 0.85

Calls 6

SetAuthFunctionMethod · 0.95
NewApiClientFunction · 0.85
GetEndpointMethod · 0.65
GetProxyMethod · 0.65
PrepareApiClientMethod · 0.65
SetupAuthenticationMethod · 0.65

Tested by

no test coverage detected