MCPcopy Create free account
hub / github.com/cloudbase/garm / GetHTTPClient

Method GetHTTPClient

params/params.go:1137–1201  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

1135}
1136
1137func (g ForgeCredentials) GetHTTPClient(ctx context.Context) (*http.Client, error) {
1138 var roots *x509.CertPool
1139 if g.CABundle != nil {
1140 roots = x509.NewCertPool()
1141 ok := roots.AppendCertsFromPEM(g.CABundle)
1142 if !ok {
1143 return nil, fmt.Errorf("failed to parse CA cert")
1144 }
1145 }
1146
1147 dialer := &net.Dialer{
1148 Timeout: 30 * time.Second,
1149 KeepAlive: 30 * time.Second,
1150 }
1151
1152 httpTransport := &http.Transport{
1153 Proxy: http.ProxyFromEnvironment,
1154 DialContext: dialer.DialContext,
1155 TLSClientConfig: &tls.Config{
1156 RootCAs: roots,
1157 MinVersion: tls.VersionTLS12,
1158 },
1159 ForceAttemptHTTP2: true,
1160 IdleConnTimeout: 90 * time.Second,
1161 TLSHandshakeTimeout: 10 * time.Second,
1162 ExpectContinueTimeout: 1 * time.Second,
1163 }
1164
1165 var tc *http.Client
1166 switch g.AuthType {
1167 case ForgeAuthTypeApp:
1168 var app GithubApp
1169 if err := json.Unmarshal(g.CredentialsPayload, &app); err != nil {
1170 return nil, fmt.Errorf("failed to unmarshal github app credentials: %w", err)
1171 }
1172 if app.AppID == 0 || app.InstallationID == 0 || len(app.PrivateKeyBytes) == 0 {
1173 return nil, fmt.Errorf("github app credentials are missing required fields")
1174 }
1175 itr, err := ghinstallation.New(httpTransport, app.AppID, app.InstallationID, app.PrivateKeyBytes)
1176 if err != nil {
1177 return nil, fmt.Errorf("failed to create github app installation transport: %w", err)
1178 }
1179 itr.BaseURL = g.APIBaseURL
1180
1181 tc = &http.Client{Transport: itr}
1182 default:
1183 var pat GithubPAT
1184 if err := json.Unmarshal(g.CredentialsPayload, &pat); err != nil {
1185 return nil, fmt.Errorf("failed to unmarshal github app credentials: %w", err)
1186 }
1187 httpClient := &http.Client{Transport: httpTransport}
1188 ctx = context.WithValue(ctx, oauth2.HTTPClient, httpClient)
1189
1190 if pat.OAuth2Token == "" {
1191 return nil, fmt.Errorf("github credentials are missing the OAuth2 token")
1192 }
1193
1194 ts := oauth2.StaticTokenSource(

Callers 2

NewRateLimitClientFunction · 0.80
ClientFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected