MCPcopy Create free account
hub / github.com/OpenCSGs/csghub-server / ListServerless

Method ListServerless

component/user.go:600–643  ·  view source on GitHub ↗
(ctx context.Context, req types.DeployReq)

Source from the content-addressed store, hash-verified

598}
599
600func (c *UserComponent) ListServerless(ctx context.Context, req types.DeployReq) ([]types.DeployRepo, int, error) {
601 user, err := c.us.FindByUsername(ctx, req.CurrentUser)
602 if err != nil {
603 newError := fmt.Errorf("failed to check for the presence of the user:%s, error:%w", req.CurrentUser, err)
604 return nil, 0, newError
605 }
606 isAdmin := c.repoComponent.isAdminRole(user)
607 if !isAdmin {
608 return nil, 0, fmt.Errorf("user %s does not have admin privileges", req.CurrentUser)
609 }
610 deploys, total, err := c.deploy.ListServerless(ctx, req)
611 if err != nil {
612 newError := fmt.Errorf("failed to get user serverless for %s with error:%w", req.RepoType, err)
613 return nil, 0, newError
614 }
615
616 var resDeploys []types.DeployRepo
617 for _, deploy := range deploys {
618 repoPath := strings.TrimPrefix(deploy.GitPath, string(req.RepoType)+"s_")
619 resDeploys = append(resDeploys, types.DeployRepo{
620 DeployID: deploy.ID,
621 DeployName: deploy.DeployName,
622 Path: repoPath,
623 RepoID: deploy.RepoID,
624 SvcName: deploy.SvcName,
625 Status: deployStatusCodeToString(deploy.Status),
626 Hardware: deploy.Hardware,
627 Env: deploy.Env,
628 RuntimeFramework: deploy.RuntimeFramework,
629 ImageID: deploy.ImageID,
630 MinReplica: deploy.MinReplica,
631 MaxReplica: deploy.MaxReplica,
632 GitPath: deploy.GitPath,
633 GitBranch: deploy.GitBranch,
634 ClusterID: deploy.ClusterID,
635 SecureLevel: deploy.SecureLevel,
636 CreatedAt: deploy.CreatedAt,
637 UpdatedAt: deploy.UpdatedAt,
638 Type: deploy.Type,
639 SKU: deploy.SKU,
640 })
641 }
642 return resDeploys, total, nil
643}

Callers 1

GetRunServerlessMethod · 0.45

Calls 3

deployStatusCodeToStringFunction · 0.85
FindByUsernameMethod · 0.80
isAdminRoleMethod · 0.80

Tested by

no test coverage detected