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:
@@ -106,3 +106,28 @@ func activeFromStatus(status string) *bool {
|
||||
return &inactive
|
||||
}
|
||||
}
|
||||
|
||||
// ownerMemberRoles maps a provider role to a display label for providers whose
|
||||
// role model is exactly owner/member (e.g. Crisp operators, Scaleway org user
|
||||
// types): "owner" → Owner, "member" → Member. An unknown future value is passed
|
||||
// through verbatim and no role yields an empty slice.
|
||||
func ownerMemberRoles(role string) []string {
|
||||
switch strings.ToLower(strings.TrimSpace(role)) {
|
||||
case "owner":
|
||||
return []string{"Owner"}
|
||||
case "member":
|
||||
return []string{"Member"}
|
||||
default:
|
||||
if r := strings.TrimSpace(role); r != "" {
|
||||
return []string{r}
|
||||
}
|
||||
|
||||
return []string{}
|
||||
}
|
||||
}
|
||||
|
||||
// isOwnerRole reports whether a provider role is the owner, the only role in the
|
||||
// owner/member model that grants administrative access.
|
||||
func isOwnerRole(role string) bool {
|
||||
return strings.EqualFold(strings.TrimSpace(role), "owner")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user