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:
@@ -96,9 +96,9 @@ func (d *ScalewayDriver) ListAccounts(ctx context.Context) ([]AccountRecord, err
|
||||
record := AccountRecord{
|
||||
Email: email,
|
||||
FullName: scalewayFullName(u, email),
|
||||
Roles: scalewayRoles(u.Type),
|
||||
Roles: ownerMemberRoles(u.Type),
|
||||
Active: scalewayActive(u.Status, u.Locked),
|
||||
IsAdmin: scalewayIsAdmin(u.Type),
|
||||
IsAdmin: isOwnerRole(u.Type),
|
||||
MFAStatus: scalewayMFAStatus(u),
|
||||
AuthMethod: coredata.AccessReviewEntryAuthMethodUnknown,
|
||||
AccountType: coredata.AccessReviewEntryAccountTypeUser,
|
||||
@@ -176,30 +176,6 @@ func scalewayFullName(u scalewayUser, fallback string) string {
|
||||
return fallback
|
||||
}
|
||||
|
||||
// scalewayRoles maps the Scaleway org-level user type to a display label. The
|
||||
// users endpoint exposes only owner/member; an unknown future value is passed
|
||||
// through verbatim and no type yields an empty slice.
|
||||
func scalewayRoles(userType string) []string {
|
||||
switch strings.ToLower(strings.TrimSpace(userType)) {
|
||||
case "owner":
|
||||
return []string{"Owner"}
|
||||
case "member":
|
||||
return []string{"Member"}
|
||||
default:
|
||||
if t := strings.TrimSpace(userType); t != "" {
|
||||
return []string{t}
|
||||
}
|
||||
|
||||
return []string{}
|
||||
}
|
||||
}
|
||||
|
||||
// scalewayIsAdmin reports whether a Scaleway user type grants administrative
|
||||
// access. Only the organization owner is an administrator; members are not.
|
||||
func scalewayIsAdmin(userType string) bool {
|
||||
return strings.EqualFold(strings.TrimSpace(userType), "owner")
|
||||
}
|
||||
|
||||
// scalewayActive maps the Scaleway user status to the three-valued Active
|
||||
// signal. A locked account is always inactive; otherwise only the documented
|
||||
// "activated"/"invitation_pending" values are an explicit signal and any other
|
||||
|
||||
Reference in New Issue
Block a user