-
Notifications
You must be signed in to change notification settings - Fork 132
/
list_stages_v1alpha1.go
39 lines (33 loc) · 1.15 KB
/
list_stages_v1alpha1.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package api
import (
"context"
"connectrpc.com/connect"
"github.com/pkg/errors"
"sigs.k8s.io/controller-runtime/pkg/client"
kargoapi "github.com/akuity/kargo/api/v1alpha1"
typesv1alpha1 "github.com/akuity/kargo/internal/api/types/v1alpha1"
svcv1alpha1 "github.com/akuity/kargo/pkg/api/service/v1alpha1"
"github.com/akuity/kargo/pkg/api/v1alpha1"
)
func (s *server) ListStages(
ctx context.Context,
req *connect.Request[svcv1alpha1.ListStagesRequest],
) (*connect.Response[svcv1alpha1.ListStagesResponse], error) {
if req.Msg.GetProject() == "" {
return nil, connect.NewError(connect.CodeInvalidArgument, errors.New("project should not be empty"))
}
if err := s.validateProject(ctx, req.Msg.GetProject()); err != nil {
return nil, err
}
var list kargoapi.StageList
if err := s.client.List(ctx, &list, client.InNamespace(req.Msg.GetProject())); err != nil {
return nil, connect.NewError(connect.CodeInternal, err)
}
stages := make([]*v1alpha1.Stage, len(list.Items))
for idx := range list.Items {
stages[idx] = typesv1alpha1.ToStageProto(list.Items[idx])
}
return connect.NewResponse(&svcv1alpha1.ListStagesResponse{
Stages: stages,
}), nil
}