MCPcopy Index your code
hub / github.com/rilldata/rill / SearchProjectNames

Method SearchProjectNames

admin/server/projects.go:402–447  ·  view source on GitHub ↗
(ctx context.Context, req *adminv1.SearchProjectNamesRequest)

Source from the content-addressed store, hash-verified

400}
401
402func (s *Server) SearchProjectNames(ctx context.Context, req *adminv1.SearchProjectNamesRequest) (*adminv1.SearchProjectNamesResponse, error) {
403 observability.AddRequestAttributes(ctx,
404 attribute.String("args.pattern", req.NamePattern),
405 attribute.Int("args.annotations", len(req.Annotations)),
406 )
407
408 claims := auth.GetClaims(ctx)
409 if !claims.Superuser(ctx) {
410 return nil, status.Error(codes.PermissionDenied, "only superusers can search projects")
411 }
412
413 token, err := unmarshalPageToken(req.PageToken)
414 if err != nil {
415 return nil, err
416 }
417 pageSize := validPageSize(req.PageSize)
418
419 var projectNames []string
420 if len(req.Annotations) > 0 {
421 // If an annotation is set to "*", we just check for key presence (instead of exact key-value match)
422 var annotationKeys []string
423 for k, v := range req.Annotations {
424 if v == "*" {
425 annotationKeys = append(annotationKeys, k)
426 delete(req.Annotations, k)
427 }
428 }
429
430 projectNames, err = s.admin.DB.FindProjectPathsByPatternAndAnnotations(ctx, req.NamePattern, token.Val, annotationKeys, req.Annotations, pageSize)
431 } else {
432 projectNames, err = s.admin.DB.FindProjectPathsByPattern(ctx, req.NamePattern, token.Val, pageSize)
433 }
434 if err != nil {
435 return nil, err
436 }
437
438 nextToken := ""
439 if len(projectNames) >= pageSize {
440 nextToken = marshalPageToken(projectNames[len(projectNames)-1])
441 }
442
443 return &adminv1.SearchProjectNamesResponse{
444 Names: projectNames,
445 NextPageToken: nextToken,
446 }, nil
447}
448
449func (s *Server) CreateProject(ctx context.Context, req *adminv1.CreateProjectRequest) (*adminv1.CreateProjectResponse, error) {
450 observability.AddRequestAttributes(ctx,

Callers

nothing calls this directly

Calls 10

AddRequestAttributesFunction · 0.92
GetClaimsFunction · 0.92
unmarshalPageTokenFunction · 0.85
validPageSizeFunction · 0.85
marshalPageTokenFunction · 0.85
StringMethod · 0.65
SuperuserMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected