(err error, account, scopes string)
| 113 | } |
| 114 | |
| 115 | func wrapAdminDirectoryErrorWithScopes(err error, account, scopes string) error { |
| 116 | errStr := err.Error() |
| 117 | if strings.Contains(errStr, "accessNotConfigured") || |
| 118 | strings.Contains(errStr, "Admin SDK API has not been used") { |
| 119 | return errfmt.NewUserFacingError("Admin SDK API is not enabled; enable it at: https://console.developers.google.com/apis/api/admin.googleapis.com/overview", err) |
| 120 | } |
| 121 | if strings.Contains(errStr, "insufficientPermissions") || |
| 122 | strings.Contains(errStr, "insufficient authentication scopes") || |
| 123 | strings.Contains(errStr, "Not Authorized") { |
| 124 | return errfmt.NewUserFacingError("Insufficient permissions for Admin SDK API; ensure your service account has domain-wide delegation enabled with "+scopes, err) |
| 125 | } |
| 126 | if strings.Contains(errStr, "domain_wide_delegation") || |
| 127 | strings.Contains(errStr, "invalid_grant") { |
| 128 | return errfmt.NewUserFacingError("Domain-wide delegation not configured or invalid; ensure your service account has domain-wide delegation enabled in Google Workspace Admin Console", err) |
| 129 | } |
| 130 | if isConsumerAccount(account) { |
| 131 | return errfmt.NewUserFacingError("Admin SDK Directory API requires a Google Workspace account with domain-wide delegation; consumer accounts (gmail.com/googlemail.com) are not supported.", err) |
| 132 | } |
| 133 | return err |
| 134 | } |
no test coverage detected