Deduplicate connector driver request helpers
The Crisp and Railway connectors each repeated their HTTP plumbing across the driver, the name resolver, and (for Crisp) the subscription settings fetcher: the same JoinPath/headers/Do for Crisp GETs and the same marshal/POST/headers for Railway GraphQL. The Crisp and Scaleway drivers also carried byte-identical owner/member role mapping and admin checks. Extract crispGet and railwayPost as package-private request helpers so each call site owns only status handling, and lift the owner/member role mapping into shared ownerMemberRoles/isOwnerRole helpers beside activeFromStatus in driver.go. Name the Crisp base URL and tier header as consts in probe.go's const block rather than inlining the literals, matching the file's existing convention. Behavior is unchanged. Signed-off-by: Aurélien Sibiril <81782+aureliensibiril@users.noreply.github.com>
This commit is contained in:
@@ -40,6 +40,9 @@ const (
|
||||
posthogOrganizationPath = "/api/organizations/@current/"
|
||||
posthogUSBaseURL = "https://us.posthog.com"
|
||||
posthogEUBaseURL = "https://eu.posthog.com"
|
||||
crispAPIBaseURL = "https://api.crisp.chat/v1"
|
||||
crispTierHeader = "X-Crisp-Tier"
|
||||
crispTierValue = "plugin"
|
||||
)
|
||||
|
||||
// ProbeConnection verifies that the connector credential is accepted by the
|
||||
@@ -505,7 +508,7 @@ func probeCrisp(
|
||||
return fmt.Errorf("missing crisp website_id")
|
||||
}
|
||||
|
||||
endpoint, err := url.JoinPath("https://api.crisp.chat/v1", "website", url.PathEscape(s.WebsiteID), "operators", "list")
|
||||
endpoint, err := url.JoinPath(crispAPIBaseURL, "website", url.PathEscape(s.WebsiteID), "operators", "list")
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot build crisp probe URL: %w", err)
|
||||
}
|
||||
@@ -516,7 +519,7 @@ func probeCrisp(
|
||||
}
|
||||
|
||||
req.Header.Set("Accept", "application/json")
|
||||
req.Header.Set("X-Crisp-Tier", "plugin")
|
||||
req.Header.Set(crispTierHeader, crispTierValue)
|
||||
|
||||
return doProbeRequest(httpClient, req, http.StatusNotFound)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user