Share PostHog region mapping and tidy pagination

The us/eu host strings lived in the driver and were duplicated in the
connector-settings resolver. Expose drivers.PostHogRegionBaseURL as the
single source and call it from the resolver.

Also parse the base URL only inside the absolute-next branch of
resolveNextURL, where it is actually used for the host check.

Signed-off-by: Aurélien Sibiril <81782+aureliensibiril@users.noreply.github.com>
This commit is contained in:
Aurélien Sibiril
2026-05-29 13:57:37 +02:00
parent 13f9234604
commit e4f247a20d
2 changed files with 22 additions and 20 deletions

View File

@@ -169,12 +169,12 @@ func (d *PostHogDriver) resolveNextURL(next string) (string, error) {
return "", fmt.Errorf("cannot parse posthog next page URL: %w", err)
}
base, err := url.Parse(d.baseURL)
if err != nil {
return "", fmt.Errorf("cannot parse posthog base URL: %w", err)
}
if nextURL.IsAbs() {
base, err := url.Parse(d.baseURL)
if err != nil {
return "", fmt.Errorf("cannot parse posthog base URL: %w", err)
}
// Pin pagination to the resolved data host. The connection's bearer
// token is attached to every request, so an absolute `next` pointing
// at a different host (a compromised or spoofed API response) would
@@ -200,6 +200,21 @@ func (d *PostHogDriver) resolveNextURL(next string) (string, error) {
return baseURL.ResolveReference(nextURL).String(), nil
}
// PostHogRegionBaseURL maps a PostHog Cloud region ("US"/"EU",
// case-insensitive) to its data-API host. It is the single source of truth for
// the regional hosts, shared with the connector-settings resolver so the two
// never drift. Self-hosted instances use a full instance URL instead.
func PostHogRegionBaseURL(region string) (string, bool) {
switch strings.ToLower(region) {
case "us":
return posthogUSBaseURL, true
case "eu":
return posthogEUBaseURL, true
default:
return "", false
}
}
// resolvePostHogRegion probes the PostHog Cloud region hosts with the given
// token-bearing client and returns the first that answers 2xx on the @current
// organization endpoint. OAuth connections authenticate via the region-agnostic