Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/cmd/server/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func runGet(f *cmdutil.Factory, opts *Options) error {

func runGetInteractive(f *cmdutil.Factory, opts *Options) error {
if opts.id == "" {
servers, err := f.ApiClient.ListServers(context.Background())
servers, err := f.ApiClient.ListServers(context.Background(), f.CurrentOwnerID())
if err != nil {
return fmt.Errorf("list servers failed: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/server/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func NewCmdList(f *cmdutil.Factory) *cobra.Command {
}

func runList(f *cmdutil.Factory) error {
servers, err := f.ApiClient.ListServers(context.Background())
servers, err := f.ApiClient.ListServers(context.Background(), f.CurrentOwnerID())
if err != nil {
return fmt.Errorf("list servers failed: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/server/reboot/reboot.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func runReboot(f *cmdutil.Factory, opts *Options) error {

func runRebootInteractive(f *cmdutil.Factory, opts *Options) error {
if opts.id == "" {
servers, err := f.ApiClient.ListServers(context.Background())
servers, err := f.ApiClient.ListServers(context.Background(), f.CurrentOwnerID())
if err != nil {
return fmt.Errorf("list servers failed: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/server/rename/rename.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func runRename(f *cmdutil.Factory, opts *Options) error {

func runRenameInteractive(f *cmdutil.Factory, opts *Options) error {
if opts.id == "" {
servers, err := f.ApiClient.ListServers(context.Background())
servers, err := f.ApiClient.ListServers(context.Background(), f.CurrentOwnerID())
if err != nil {
return fmt.Errorf("list servers failed: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/server/ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func runSSH(f *cmdutil.Factory, opts *Options) error {

func runSSHInteractive(f *cmdutil.Factory, opts *Options) error {
if opts.id == "" {
servers, err := f.ApiClient.ListServers(context.Background())
servers, err := f.ApiClient.ListServers(context.Background(), f.CurrentOwnerID())
if err != nil {
return fmt.Errorf("list servers failed: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/server/sshinfo/sshinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func runSSHInfo(f *cmdutil.Factory, opts *Options) error {
}

func runSSHInfoInteractive(f *cmdutil.Factory, opts *Options) error {
servers, err := f.ApiClient.ListServers(context.Background())
servers, err := f.ApiClient.ListServers(context.Background(), f.CurrentOwnerID())
if err != nil {
return fmt.Errorf("list servers failed: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type (
}

ServerAPI interface {
ListServers(ctx context.Context) (model.ServerListItems, error)
ListServers(ctx context.Context, ownerID string) (model.ServerListItems, error)
GetServer(ctx context.Context, id string) (*model.ServerDetail, error)
RebootServer(ctx context.Context, id string) error
RenameServer(ctx context.Context, id, name string) error
Expand Down
21 changes: 15 additions & 6 deletions pkg/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,25 @@ import (
"github.com/zeabur/cli/pkg/model"
)

func (c *client) ListServers(ctx context.Context) (model.ServerListItems, error) {
var query struct {
Servers model.ServerListItems `graphql:"servers"`
func (c *client) ListServers(ctx context.Context, ownerID string) (model.ServerListItems, error) {
if ownerID == "" {
var query struct {
Servers model.ServerListItems `graphql:"servers"`
}
if err := c.Query(ctx, &query, nil); err != nil {
return nil, err
}
return query.Servers, nil
}

err := c.Query(ctx, &query, nil)
if err != nil {
var query struct {
Servers model.ServerListItems `graphql:"servers(ownerID: $ownerID)"`
}
if err := c.Query(ctx, &query, V{
"ownerID": ObjectID(ownerID),
}); err != nil {
return nil, err
}

return query.Servers, nil
}

Expand Down