MCPcopy Create free account
hub / github.com/PostHog/duckgres / handleConnectionInProcess

Method handleConnectionInProcess

server/server.go:2421–2467  ·  view source on GitHub ↗

handleConnectionInProcess handles a connection in the current process (non-isolated mode).

(conn net.Conn, remoteAddr net.Addr)

Source from the content-addressed store, hash-verified

2419 if err != nil {
2420 return aws.Credentials{}, fmt.Errorf("failed to retrieve AWS credentials: %w", err)
2421 }
2422 return creds, nil
2423}
2424
2425// buildAWSSdkSecret fetches credentials via the Go AWS SDK and builds a
2426// CREATE SECRET statement with PROVIDER config using the explicit temporary credentials.
2427func buildAWSSdkSecret(ctx context.Context, dlCfg DuckLakeConfig) (string, error) {
2428 creds, err := fetchAWSSDKCredentials(ctx, dlCfg.S3Region)
2429 if err != nil {
2430 return "", err
2431 }
2432
2433 region := dlCfg.S3Region
2434 if region == "" {
2435 region = "us-east-1"
2436 }
2437
2438 secret := fmt.Sprintf(`
2439 CREATE OR REPLACE SECRET ducklake_s3 (
2440 TYPE s3,
2441 PROVIDER config,
2442 KEY_ID '%s',
2443 SECRET '%s',
2444 REGION '%s'`,
2445 creds.AccessKeyID,
2446 creds.SecretAccessKey,
2447 region,
2448 )
2449
2450 if creds.SessionToken != "" {
2451 secret += fmt.Sprintf(",\n\t\t\tSESSION_TOKEN '%s'", creds.SessionToken)
2452 }
2453
2454 if dlCfg.S3Endpoint != "" || dlCfg.HTTPProxy != "" {
2455 if dlCfg.S3Endpoint != "" {
2456 secret += fmt.Sprintf(",\n\t\t\tENDPOINT '%s'", dlCfg.S3Endpoint)
2457 }
2458 urlStyle, useSSL := resolveS3SecretTransport(dlCfg)
2459 secret += fmt.Sprintf(",\n\t\t\tURL_STYLE '%s'", urlStyle)
2460 secret += fmt.Sprintf(",\n\t\t\tUSE_SSL %s", useSSL)
2461 }
2462
2463 secret += "\n\t\t)"
2464 return secret, nil
2465}
2466
2467// credentialRefreshInterval is how often to refresh S3 credentials for long-lived connections.
2468// EC2 instance role credentials typically expire after 6 hours. Refreshing every 5 minutes
2469// ensures fresh credentials are always available without excessive IMDS calls.
2470var credentialRefreshInterval = 5 * time.Minute

Callers 1

handleConnectionMethod · 0.95

Calls 7

serveMethod · 0.95
IncrementOpenConnectionsFunction · 0.92
DecrementOpenConnectionsFunction · 0.92
UnregisterConnectionMethod · 0.80
CloseMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected