Skip to content

Commit 015cf27

Browse files
authored
pdb client: adds root endpoint for custom queries (#84)
1 parent d9e2bb7 commit 015cf27

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

pkg/puppetdb/root.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package puppetdb
2+
3+
import (
4+
"errors"
5+
"fmt"
6+
"io"
7+
)
8+
9+
const (
10+
rootQueryEndpoint = "/pdb/query/v4"
11+
)
12+
13+
func (c *Client) PaginatedRootQuery(query string, pagination *Pagination, orderBy *OrderBy) (*RootQueryCursor, error) {
14+
pc, err := newPageCursor(c, rootQueryEndpoint, query, pagination, orderBy)
15+
if err != nil {
16+
return nil, fmt.Errorf("failed to initialize page cursor: %w", err)
17+
}
18+
19+
cursor := RootQueryCursor{
20+
pageCursor: pc,
21+
}
22+
23+
return &cursor, nil
24+
}
25+
26+
type RootQueryCursor struct {
27+
*pageCursor
28+
}
29+
30+
func (rqc *RootQueryCursor) NextInto(target any) error {
31+
err := rqc.next(target)
32+
if err != nil && !errors.Is(err, io.EOF) {
33+
return err
34+
}
35+
36+
return err
37+
}

0 commit comments

Comments
 (0)