| 2079 | } |
| 2080 | |
| 2081 | func CheckRoles(ctx context.Context, httpClient *http.Client, managementEndpoints []string, username, password string, requestedRoles []RouteRole, bucketName string) (statusCode int, err error) { |
| 2082 | whoAmIResults, statusCode, err := cbRBACWhoAmI(ctx, httpClient, managementEndpoints, username, password) |
| 2083 | if err != nil || statusCode != http.StatusOK { |
| 2084 | return statusCode, err |
| 2085 | } |
| 2086 | |
| 2087 | for _, roleResult := range whoAmIResults.Roles { |
| 2088 | for _, requireRole := range requestedRoles { |
| 2089 | requireBucketOptions := []string{""} |
| 2090 | if requireRole.DatabaseScoped { |
| 2091 | requireBucketOptions = []string{bucketName, RoleBucketWildcard} |
| 2092 | } |
| 2093 | |
| 2094 | for _, requireBucket := range requireBucketOptions { |
| 2095 | if (roleResult.BucketName == requireBucket) && roleResult.RoleName == requireRole.RoleName { |
| 2096 | return http.StatusOK, nil |
| 2097 | } |
| 2098 | } |
| 2099 | } |
| 2100 | } |
| 2101 | |
| 2102 | return http.StatusForbidden, nil |
| 2103 | } |
| 2104 | |
| 2105 | func doHTTPAuthRequest(ctx context.Context, httpClient *http.Client, username, password, method, path string, endpoints []string, requestBody []byte) (statusCode int, responseBody []byte, err error) { |
| 2106 | retryCount := 0 |