2024-11-06 03:31:52 -06:00
|
|
|
package repolist
|
|
|
|
|
|
|
|
// attempt to make a golang 'interface' for a 'view' of git repos
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
2024-11-08 06:43:45 -06:00
|
|
|
|
2024-11-06 03:31:52 -06:00
|
|
|
"go.wit.com/lib/protobuf/virtbuf"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ViewRepoManager is a concrete implementation of the RepoManager interface.
|
|
|
|
type ViewRepoManager struct {
|
|
|
|
// client represents a hypothetical API client for interacting with the cloud.
|
|
|
|
client ViewAPIClient
|
|
|
|
}
|
|
|
|
|
|
|
|
// ViewAPIClient defines the methods required from the API client.
|
|
|
|
// This is useful if you want to mock this client for testing.
|
|
|
|
type ViewAPIClient interface {
|
2024-11-07 05:16:16 -06:00
|
|
|
GetRepoByName(ctx context.Context, name string) (*virtbuf.Cluster, error)
|
2024-11-06 03:31:52 -06:00
|
|
|
StartRepo(ctx context.Context, clusterID string) error
|
|
|
|
StopRepo(ctx context.Context, clusterID string) error
|
2024-11-07 05:16:16 -06:00
|
|
|
ListRepos(ctx context.Context) ([]*virtbuf.Cluster, error)
|
2024-11-06 03:31:52 -06:00
|
|
|
GetRepoStatus(ctx context.Context, clusterID string) (string, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewViewRepoManager creates a new ViewRepoManager with the provided API client.
|
|
|
|
func NewViewRepoManager(client ViewAPIClient) *ViewRepoManager {
|
|
|
|
return &ViewRepoManager{client: client}
|
|
|
|
}
|
|
|
|
|
|
|
|
// FindByName retrieves a cluster by name.
|
2024-11-07 05:16:16 -06:00
|
|
|
func (m *ViewRepoManager) FindByName(ctx context.Context, name string) (*virtbuf.Cluster, error) {
|
2024-11-06 03:31:52 -06:00
|
|
|
cluster, err := m.client.GetRepoByName(ctx, name)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error finding cluster by name %q: %w", name, err)
|
|
|
|
}
|
|
|
|
return cluster, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start initiates the startup process for the specified cluster.
|
2024-11-07 05:16:16 -06:00
|
|
|
func (m *ViewRepoManager) Start(ctx context.Context, cluster *virtbuf.Cluster) error {
|
2024-11-06 03:31:52 -06:00
|
|
|
if cluster == nil {
|
|
|
|
return errors.New("cluster cannot be nil")
|
|
|
|
}
|
|
|
|
/*
|
2024-11-08 06:43:45 -06:00
|
|
|
err := m.client.StartRepo(ctx, cluster.Id)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("error starting cluster %q: %w", cluster.Id, err)
|
|
|
|
}
|
2024-11-06 03:31:52 -06:00
|
|
|
*/
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stop halts the specified cluster.
|
2024-11-07 05:16:16 -06:00
|
|
|
func (m *ViewRepoManager) Stop(ctx context.Context, cluster *virtbuf.Cluster) error {
|
2024-11-06 03:31:52 -06:00
|
|
|
if cluster == nil {
|
|
|
|
return errors.New("cluster cannot be nil")
|
|
|
|
}
|
|
|
|
/*
|
2024-11-08 06:43:45 -06:00
|
|
|
err := m.client.StopRepo(ctx, cluster.Id)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("error stopping cluster %q: %w", cluster.Id, err)
|
|
|
|
}
|
2024-11-06 03:31:52 -06:00
|
|
|
*/
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// List retrieves all available clusters.
|
2024-11-07 05:16:16 -06:00
|
|
|
func (m *ViewRepoManager) List(ctx context.Context) ([]*virtbuf.Cluster, error) {
|
2024-11-06 03:31:52 -06:00
|
|
|
/*
|
2024-11-08 06:43:45 -06:00
|
|
|
clusters, err := m.client.ListRepos(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error listing clusters: %w", err)
|
|
|
|
}
|
|
|
|
return clusters, nil
|
2024-11-06 03:31:52 -06:00
|
|
|
*/
|
|
|
|
return nil, errors.New("List not done yet")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Status checks the current status of a specified cluster.
|
2024-11-07 05:16:16 -06:00
|
|
|
func (m *ViewRepoManager) Status(ctx context.Context, cluster *virtbuf.Cluster) (string, error) {
|
2024-11-06 03:31:52 -06:00
|
|
|
if cluster == nil {
|
|
|
|
return "", errors.New("cluster cannot be nil")
|
|
|
|
}
|
|
|
|
/*
|
2024-11-08 06:43:45 -06:00
|
|
|
status, err := m.client.GetRepoStatus(ctx, cluster.Id)
|
|
|
|
if err != nil {
|
|
|
|
return "", fmt.Errorf("error getting status of cluster %q: %w", cluster.Id, err)
|
|
|
|
}
|
2024-11-06 03:31:52 -06:00
|
|
|
*/
|
|
|
|
return "", nil
|
|
|
|
}
|