|
1 | 1 | // |
2 | | -// Copyright 2023 The Chainloop Authors. |
| 2 | +// Copyright 2023-2026 The Chainloop Authors. |
3 | 3 | // |
4 | 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | // you may not use this file except in compliance with the License. |
@@ -40,36 +40,62 @@ type ReferrerItem struct { |
40 | 40 | Annotations map[string]string `json:"annotations,omitempty"` |
41 | 41 | } |
42 | 42 |
|
| 43 | +type ReferrerDiscoverResult struct { |
| 44 | + Item *ReferrerItem `json:"result"` |
| 45 | + NextCursor string `json:"nextCursor,omitempty"` |
| 46 | +} |
| 47 | + |
43 | 48 | func NewReferrerDiscoverPrivate(cfg *ActionsOpts) *ReferrerDiscover { |
44 | 49 | return &ReferrerDiscover{cfg} |
45 | 50 | } |
46 | 51 |
|
47 | | -func (action *ReferrerDiscover) Run(ctx context.Context, digest, kind string) (*ReferrerItem, error) { |
| 52 | +func (action *ReferrerDiscover) Run(ctx context.Context, digest, kind string, p *PaginationOpts) (*ReferrerDiscoverResult, error) { |
48 | 53 | client := pb.NewReferrerServiceClient(action.cfg.CPConnection) |
49 | 54 | resp, err := client.DiscoverPrivate(ctx, &pb.ReferrerServiceDiscoverPrivateRequest{ |
50 | | - Digest: digest, Kind: kind, |
| 55 | + Digest: digest, |
| 56 | + Kind: kind, |
| 57 | + Pagination: paginationOptsToPb(p), |
51 | 58 | }) |
52 | 59 | if err != nil { |
53 | 60 | return nil, err |
54 | 61 | } |
55 | 62 |
|
56 | | - return pbReferrerItemToAction(resp.Result), nil |
| 63 | + return newReferrerDiscoverResult(resp.Result, resp.GetPagination()), nil |
57 | 64 | } |
58 | 65 |
|
59 | 66 | func NewReferrerDiscoverPublicIndex(cfg *ActionsOpts) *ReferrerDiscoverPublic { |
60 | 67 | return &ReferrerDiscoverPublic{cfg} |
61 | 68 | } |
62 | 69 |
|
63 | | -func (action *ReferrerDiscoverPublic) Run(ctx context.Context, digest, kind string) (*ReferrerItem, error) { |
| 70 | +func (action *ReferrerDiscoverPublic) Run(ctx context.Context, digest, kind string, p *PaginationOpts) (*ReferrerDiscoverResult, error) { |
64 | 71 | client := pb.NewReferrerServiceClient(action.cfg.CPConnection) |
65 | 72 | resp, err := client.DiscoverPublicShared(ctx, &pb.DiscoverPublicSharedRequest{ |
66 | | - Digest: digest, Kind: kind, |
| 73 | + Digest: digest, |
| 74 | + Kind: kind, |
| 75 | + Pagination: paginationOptsToPb(p), |
67 | 76 | }) |
68 | 77 | if err != nil { |
69 | 78 | return nil, err |
70 | 79 | } |
71 | 80 |
|
72 | | - return pbReferrerItemToAction(resp.Result), nil |
| 81 | + return newReferrerDiscoverResult(resp.Result, resp.GetPagination()), nil |
| 82 | +} |
| 83 | + |
| 84 | +func paginationOptsToPb(p *PaginationOpts) *pb.CursorPaginationRequest { |
| 85 | + if p == nil { |
| 86 | + return nil |
| 87 | + } |
| 88 | + return &pb.CursorPaginationRequest{ |
| 89 | + Limit: int32(p.Limit), |
| 90 | + Cursor: p.NextCursor, |
| 91 | + } |
| 92 | +} |
| 93 | + |
| 94 | +func newReferrerDiscoverResult(item *pb.ReferrerItem, p *pb.CursorPaginationResponse) *ReferrerDiscoverResult { |
| 95 | + return &ReferrerDiscoverResult{ |
| 96 | + Item: pbReferrerItemToAction(item), |
| 97 | + NextCursor: p.GetNextCursor(), |
| 98 | + } |
73 | 99 | } |
74 | 100 |
|
75 | 101 | func pbReferrerItemToAction(in *pb.ReferrerItem) *ReferrerItem { |
|
0 commit comments