Skip to content

Commit

Permalink
client: Runbooks add an opt to fetch all runbooks or just runbooks owned
Browse files Browse the repository at this point in the history
by a user
  • Loading branch information
joshi4 committed Nov 7, 2024
1 parent efb70e5 commit b58c262
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
11 changes: 9 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 17,7 @@ import (

type RunbookClient interface {
RunbookByID(ctx context.Context, id string) (*Runbook, error)
Runbooks(ctx context.Context) ([]RunbookInfo, error)
Runbooks(ctx context.Context, opts RunbooksOpt) ([]RunbookInfo, error)
}

type RunbookSaver interface {
Expand Down Expand Up @@ -292,9 292,16 @@ func (c *client) RunbookByID(ctx context.Context, id string) (*Runbook, error) {
return &runbook, nil
}

func (c *client) Runbooks(ctx context.Context) ([]RunbookInfo, error) {
type RunbooksOpt struct {
ExcludeTeamRunbooks bool
}

func (c *client) Runbooks(ctx context.Context, opts RunbooksOpt) ([]RunbookInfo, error) {
cl := c.cl
req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.apiURL("/api/v1/list_runbooks/all"), nil)
if opts.ExcludeTeamRunbooks {
req, err = http.NewRequestWithContext(ctx, http.MethodGet, c.apiURL("/api/v1/list_runbooks"), nil)
}
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions client/guest.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 116,12 @@ func (g *guest) RunbookByID(ctx context.Context, id string) (*Runbook, error) {
return &runbook, nil
}

func (g *guest) Runbooks(ctx context.Context) ([]RunbookInfo, error) {
func (g *guest) Runbooks(ctx context.Context, opt RunbooksOpt) ([]RunbookInfo, error) {
cl, err := getLoggedInClient()
if err != nil {
return nil, err
}
return cl.Runbooks(ctx)
return cl.Runbooks(ctx, opt)
}

func (g *guest) Ask(ctx context.Context, question QuestionInfo) (*Runbook, error) {
Expand Down
3 changes: 2 additions & 1 deletion client/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 31,8 @@ func (l *local) RunbookByID(ctx context.Context, id string) (*client.Runbook, er
return rb, nil
}

func (l *local) Runbooks(ctx context.Context) ([]client.RunbookInfo, error) {
// Runbooks returns all runbooks stored in the local storage
func (l *local) Runbooks(ctx context.Context, _ client.RunbooksOpt) ([]client.RunbookInfo, error) {

rbs, err := storage.Read()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 218,7 @@ type selectableRunbook struct {

func allowUserToSelectRunbook(ctx context.Context, logger *slog.Logger, cl client.RunbookClient) (string, error) {
l := logger.With("func", "allowsUserToSelectRunbook")
runbooks, err := cl.Runbooks(ctx)
runbooks, err := cl.Runbooks(ctx, client.RunbooksOpt{})
if err != nil {
l.Debug("failed to fetch runbooks", "error", err)
return "", err
Expand Down
4 changes: 3 additions & 1 deletion cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 32,9 @@ func syncRunbooks(cmd *cobra.Command, args []string) {
return
}

runbookInfo, err := cl.Runbooks(ctx)
runbookInfo, err := cl.Runbooks(ctx, client.RunbooksOpt{
ExcludeTeamRunbooks: true,
})
if err != nil {
logger.Error("failed to fetch runbooks", "error", err)
return
Expand Down

0 comments on commit b58c262

Please sign in to comment.