MCPcopy Index your code
hub / github.com/bytebase/bytebase / newClient

Function newClient

action/command/api.go:79–126  ·  view source on GitHub ↗

newClient creates a client using either access-token or service-account authentication.

(url, accessToken, serviceAccount, serviceAccountSecret string, opts clientOptions)

Source from the content-addressed store, hash-verified

77
78// newClient creates a client using either access-token or service-account authentication.
79func newClient(url, accessToken, serviceAccount, serviceAccountSecret string, opts clientOptions) (*client, error) {
80 if opts.pageSize <= 0 {
81 opts.pageSize = 100
82 }
83 if opts.pageSize > 1000 {
84 opts.pageSize = 1000
85 }
86
87 httpClient := opts.httpClient
88 if httpClient == nil {
89 timeout := opts.timeout
90 if timeout == 0 {
91 timeout = 120 * time.Second
92 }
93 httpClient = &http.Client{Timeout: timeout}
94 }
95 if len(opts.customHeaders) > 0 {
96 copiedClient := *httpClient
97 httpClient = &copiedClient
98 httpClient.Transport = newCustomHeaderTransport(httpClient.Transport, opts.customHeaders)
99 }
100
101 var tokenRefresher func(ctx context.Context) (string, error)
102 if accessToken != "" {
103 // Use the provided access token directly; no refresh needed.
104 tokenRefresher = func(_ context.Context) (string, error) {
105 return accessToken, nil
106 }
107 } else {
108 tokenRefresher = getTokenRefresher(httpClient, serviceAccount, serviceAccountSecret, url)
109 }
110
111 // Create unified interceptor.
112 unifiedInt := newUnifiedInterceptor(opts.retryConfig, tokenRefresher)
113 interceptors := connect.WithInterceptors(unifiedInt)
114
115 return &client{
116 httpClient: httpClient,
117 url: url,
118 serviceAccount: serviceAccount,
119 serviceAccountSecret: serviceAccountSecret,
120 options: opts,
121 releaseClient: v1connect.NewReleaseServiceClient(httpClient, url, interceptors),
122 planClient: v1connect.NewPlanServiceClient(httpClient, url, interceptors),
123 rolloutClient: v1connect.NewRolloutServiceClient(httpClient, url, interceptors),
124 actuatorClient: v1connect.NewActuatorServiceClient(httpClient, url, interceptors),
125 }, nil
126}
127
128type customHeaderTransport struct {
129 base http.RoundTripper

Calls 7

NewReleaseServiceClientFunction · 0.92
NewPlanServiceClientFunction · 0.92
NewRolloutServiceClientFunction · 0.92
NewActuatorServiceClientFunction · 0.92
newCustomHeaderTransportFunction · 0.85
getTokenRefresherFunction · 0.85
newUnifiedInterceptorFunction · 0.85