Skip to content

Commit de52b05

Browse files
committed
chore(service): update subscription endpoints
1 parent bc622bc commit de52b05

File tree

3 files changed

+61
-3
lines changed

3 files changed

+61
-3
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ require (
1414
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0
1515
github.com/iancoleman/strcase v0.2.0
1616
github.com/influxdata/influxdb-client-go/v2 v2.12.3
17-
github.com/instill-ai/protogen-go v0.3.3-alpha.0.20231208161503-706306fd242e
17+
github.com/instill-ai/protogen-go v0.3.3-alpha.0.20231210131526-67e990838339
1818
github.com/instill-ai/usage-client v0.2.4-alpha.0.20231206035716-4c05f872df97
1919
github.com/instill-ai/x v0.3.0-alpha
2020
github.com/knadh/koanf v1.4.4

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,8 +1105,8 @@ github.com/influxdata/line-protocol/v2 v2.0.0-20210312151457-c52fdecb625a/go.mod
11051105
github.com/influxdata/line-protocol/v2 v2.1.0/go.mod h1:QKw43hdUBg3GTk2iC3iyCxksNj7PX9aUSeYOYE/ceHY=
11061106
github.com/influxdata/line-protocol/v2 v2.2.1 h1:EAPkqJ9Km4uAxtMRgUubJyqAr6zgWM0dznKMLRauQRE=
11071107
github.com/influxdata/line-protocol/v2 v2.2.1/go.mod h1:DmB3Cnh+3oxmG6LOBIxce4oaL4CPj3OmMPgvauXh+tM=
1108-
github.com/instill-ai/protogen-go v0.3.3-alpha.0.20231208161503-706306fd242e h1:dnZvLQnuUqpAozwj59sQRpeTF4tg+qeIkLvHKuMc788=
1109-
github.com/instill-ai/protogen-go v0.3.3-alpha.0.20231208161503-706306fd242e/go.mod h1:q/YL5TZXD9nvmJ7Rih4gY3/B2HT2+GiFdxeZp9D+yE4=
1108+
github.com/instill-ai/protogen-go v0.3.3-alpha.0.20231210131526-67e990838339 h1:Q48Mm+0i6gL4ZYMiHPddMfBQaslk83y3jmPg9T1T7IQ=
1109+
github.com/instill-ai/protogen-go v0.3.3-alpha.0.20231210131526-67e990838339/go.mod h1:q/YL5TZXD9nvmJ7Rih4gY3/B2HT2+GiFdxeZp9D+yE4=
11101110
github.com/instill-ai/usage-client v0.2.4-alpha.0.20231206035716-4c05f872df97 h1:WycXqzJP1ihjJwrkxlNP2TQc1DSUxUtfl/PtCpLBa3Y=
11111111
github.com/instill-ai/usage-client v0.2.4-alpha.0.20231206035716-4c05f872df97/go.mod h1:Da8RdKakfxy1iNdvI5FSTcL1lSDtda+b9jOgOEEO68E=
11121112
github.com/instill-ai/x v0.3.0-alpha h1:z9fedROOG2dVHhswBfVwU/hzHuq8/JKSUON7inF+FH8=

pkg/service/service.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/redis/go-redis/v9"
1111
"go.einride.tech/aip/filtering"
1212
"golang.org/x/crypto/bcrypt"
13+
"google.golang.org/grpc/metadata"
1314

1415
"github.com/instill-ai/mgmt-backend/internal/resource"
1516
"github.com/instill-ai/mgmt-backend/pkg/acl"
@@ -65,6 +66,8 @@ type Service interface {
6566
CheckUserPassword(ctx context.Context, uid uuid.UUID, password string) error
6667
UpdateUserPassword(ctx context.Context, uid uuid.UUID, newPassword string) error
6768

69+
ListUserPipelines(ctx context.Context, id string) ([]*pipelinePB.Pipeline, error)
70+
ListOrganizationPipelines(ctx context.Context, id string) ([]*pipelinePB.Pipeline, error)
6871
ListPipelineTriggerRecords(ctx context.Context, owner *mgmtPB.User, pageSize int64, pageToken string, filter filtering.Filter) ([]*mgmtPB.PipelineTriggerRecord, int64, string, error)
6972
ListPipelineTriggerTableRecords(ctx context.Context, owner *mgmtPB.User, pageSize int64, pageToken string, filter filtering.Filter) ([]*mgmtPB.PipelineTriggerTableRecord, int64, string, error)
7073
ListPipelineTriggerChartRecords(ctx context.Context, owner *mgmtPB.User, aggregationWindow int64, filter filtering.Filter) ([]*mgmtPB.PipelineTriggerChartRecord, error)
@@ -802,3 +805,58 @@ func (s *service) DeleteOrganizationMembership(ctx context.Context, ctxUserUID u
802805
}
803806
return nil
804807
}
808+
func (s *service) ListUserPipelines(ctx context.Context, id string) ([]*pipelinePB.Pipeline, error) {
809+
810+
pageToken := ""
811+
pageSize := int32(100)
812+
813+
pipelines := []*pipelinePB.Pipeline{}
814+
for {
815+
resp, err := s.pipelinePublicServiceClient.ListUserPipelines(
816+
metadata.AppendToOutgoingContext(ctx, "Jwt-Sub", resource.GetRequestSingleHeader(ctx, constant.HeaderUserUIDKey)),
817+
&pipelinePB.ListUserPipelinesRequest{
818+
PageSize: &pageSize,
819+
PageToken: &pageToken,
820+
Parent: fmt.Sprintf("users/%s", id),
821+
},
822+
)
823+
if err != nil {
824+
return nil, err
825+
}
826+
pipelines = append(pipelines, resp.Pipelines...)
827+
pageToken = resp.NextPageToken
828+
if pageToken == "" {
829+
break
830+
}
831+
}
832+
833+
return pipelines, nil
834+
}
835+
836+
func (s *service) ListOrganizationPipelines(ctx context.Context, id string) ([]*pipelinePB.Pipeline, error) {
837+
838+
pageToken := ""
839+
pageSize := int32(100)
840+
841+
pipelines := []*pipelinePB.Pipeline{}
842+
for {
843+
resp, err := s.pipelinePublicServiceClient.ListOrganizationPipelines(
844+
metadata.AppendToOutgoingContext(ctx, "Jwt-Sub", resource.GetRequestSingleHeader(ctx, constant.HeaderUserUIDKey)),
845+
&pipelinePB.ListOrganizationPipelinesRequest{
846+
PageSize: &pageSize,
847+
PageToken: &pageToken,
848+
Parent: fmt.Sprintf("organizations/%s", id),
849+
},
850+
)
851+
if err != nil {
852+
return nil, err
853+
}
854+
pipelines = append(pipelines, resp.Pipelines...)
855+
pageToken = resp.NextPageToken
856+
if pageToken == "" {
857+
break
858+
}
859+
}
860+
861+
return pipelines, nil
862+
}

0 commit comments

Comments
 (0)