Returns the IDs of all users and roles using syncDocs index
(ctx context.Context)
| 1149 | |
| 1150 | // Returns the IDs of all users and roles using syncDocs index |
| 1151 | func (db *DatabaseContext) getAllPrincipalIDsSyncDocs(ctx context.Context) (users, roles []string, err error) { |
| 1152 | |
| 1153 | startKey := "" |
| 1154 | limit := db.Options.QueryPaginationLimit |
| 1155 | if limit == 0 { |
| 1156 | limit = DefaultQueryPaginationLimit |
| 1157 | } |
| 1158 | |
| 1159 | dbUserPrefix := db.MetadataKeys.UserKeyPrefix() |
| 1160 | dbRolePrefix := db.MetadataKeys.RoleKeyPrefix() |
| 1161 | lenDbUserPrefix := len(dbUserPrefix) |
| 1162 | lenDbRolePrefix := len(dbRolePrefix) |
| 1163 | |
| 1164 | userRe, err := regexp.Compile(`^` + dbUserPrefix + `[^:]*$`) |
| 1165 | if err != nil { |
| 1166 | return nil, nil, err |
| 1167 | } |
| 1168 | roleRe, err := regexp.Compile(`^` + dbRolePrefix + `[^:]*$`) |
| 1169 | if err != nil { |
| 1170 | return nil, nil, err |
| 1171 | } |
| 1172 | anyPrincipalRe, err := regexp.Compile(fmt.Sprintf(`^(%s|%s).*$`, base.DefaultMetadataKeys.UserKeyPrefix(), base.DefaultMetadataKeys.RoleKeyPrefix())) |
| 1173 | if err != nil { |
| 1174 | return nil, nil, err |
| 1175 | } |
| 1176 | users = []string{} |
| 1177 | roles = []string{} |
| 1178 | |
| 1179 | outerLoop: |
| 1180 | for { |
| 1181 | results, err := db.QueryPrincipals(ctx, startKey, limit) |
| 1182 | if err != nil { |
| 1183 | return nil, nil, err |
| 1184 | } |
| 1185 | |
| 1186 | var isDbUser, isDbRole bool |
| 1187 | var principalName string |
| 1188 | |
| 1189 | resultCount := 0 |
| 1190 | |
| 1191 | for { |
| 1192 | // startKey is inclusive for views, so need to skip first result if using non-empty startKey, as this results in an overlapping result |
| 1193 | var skipAddition bool |
| 1194 | if resultCount == 0 && startKey != "" { |
| 1195 | skipAddition = true |
| 1196 | } |
| 1197 | |
| 1198 | var rowID string |
| 1199 | if db.Options.UseViews { |
| 1200 | var viewRow principalsViewRow |
| 1201 | found := results.Next(ctx, &viewRow) |
| 1202 | if !found { |
| 1203 | break |
| 1204 | } |
| 1205 | rowID = viewRow.ID |
| 1206 | //isUser = viewRow.Value |
| 1207 | //principalName = viewRow.Key |
| 1208 | startKey = viewRow.Key |
no test coverage detected