MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / CheckRoles

Function CheckRoles

rest/server_context.go:2081–2103  ·  view source on GitHub ↗
(ctx context.Context, httpClient *http.Client, managementEndpoints []string, username, password string, requestedRoles []RouteRole, bucketName string)

Source from the content-addressed store, hash-verified

2079}
2080
2081func 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
2105func 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

Callers 2

checkAdminAuthFunction · 0.85
TestCheckRolesFunction · 0.85

Calls 1

cbRBACWhoAmIFunction · 0.85

Tested by 1

TestCheckRolesFunction · 0.68