diff --git a/autocomplete/cached_cloud_client.go b/autocomplete/cached_cloud_client.go index ec82d7ce..5318402a 100644 --- a/autocomplete/cached_cloud_client.go +++ b/autocomplete/cached_cloud_client.go @@ -17,7 +17,7 @@ import ( type cloudListClient interface { ListOrgs(ctx context.Context) ([]*cloud.OrgDetail, error) ListProjects(ctx context.Context, orgName string) ([]*cloud.Project, error) - ListSatellites(ctx context.Context, orgName string, includeHidden bool) ([]cloud.SatelliteInstance, error) + ListSatellites(ctx context.Context, orgName string) ([]cloud.SatelliteInstance, error) } type cachedCloudClient struct { @@ -139,14 +139,13 @@ func (ccc *cachedCloudClient) ListProjects(ctx context.Context, orgName string) return projects, nil } -func (ccc *cachedCloudClient) ListSatellites(ctx context.Context, orgName string, includeHidden bool) ([]cloud.SatelliteInstance, error) { +func (ccc *cachedCloudClient) ListSatellites(ctx context.Context, orgName string) ([]cloud.SatelliteInstance, error) { cached := struct { - Org string - IncludeHidden bool - Satellites []string `json:"satellites"` + Org string + Satellites []string `json:"satellites"` }{} filename := ".autocomplete.satellites" - if err := readJSON(ccc.installationName, filename, &cached); err == nil && cached.Org == orgName && cached.IncludeHidden == includeHidden { + if err := readJSON(ccc.installationName, filename, &cached); err == nil && cached.Org == orgName { res := []cloud.SatelliteInstance{} for _, s := range cached.Satellites { res = append(res, cloud.SatelliteInstance{ @@ -156,7 +155,7 @@ func (ccc *cachedCloudClient) ListSatellites(ctx context.Context, orgName string return res, nil } cached.Satellites = nil - satellites, err := ccc.c.ListSatellites(ctx, orgName, includeHidden) + satellites, err := ccc.c.ListSatellites(ctx, orgName) if err != nil { return nil, err } @@ -164,7 +163,6 @@ func (ccc *cachedCloudClient) ListSatellites(ctx context.Context, orgName string cached.Satellites = append(cached.Satellites, sat.Name) } cached.Org = orgName - cached.IncludeHidden = includeHidden _ = saveJSON(ccc.installationName, filename, &cached) return satellites, nil } diff --git a/autocomplete/cached_cloud_client_test.go b/autocomplete/cached_cloud_client_test.go index 5525f924..7dea1853 100644 --- a/autocomplete/cached_cloud_client_test.go +++ b/autocomplete/cached_cloud_client_test.go @@ -68,7 +68,7 @@ func TestCachedCloudClient(topT *testing.T) { o.Spec("caches satellites", func(tc testCtx) { for i := 0; i < 3; i++ { - projects, err := tc.ccc.ListSatellites(context.Background(), "abba", false) + projects, err := tc.ccc.ListSatellites(context.Background(), "abba") tc.expect(err).To(not(haveOccurred())) tc.expect(len(projects)).To(equal(2)) tc.expect(projects[0].Name).To(equal("sat-one")) @@ -76,7 +76,7 @@ func TestCachedCloudClient(topT *testing.T) { tc.expect(tc.mclc.listSatellitesCallCount).To(equal(1)) } for i := 0; i < 3; i++ { - projects, err := tc.ccc.ListSatellites(context.Background(), "abc", false) + projects, err := tc.ccc.ListSatellites(context.Background(), "abc") tc.expect(err).To(not(haveOccurred())) tc.expect(len(projects)).To(equal(1)) tc.expect(projects[0].Name).To(equal("xyz")) diff --git a/autocomplete/complete.go b/autocomplete/complete.go index c64c35fa..169a0ba7 100644 --- a/autocomplete/complete.go +++ b/autocomplete/complete.go @@ -411,7 +411,7 @@ func GetPotentials(ctx context.Context, resolver *buildcontext.Resolver, gwClien return []string{} } - satellites, err := cloudClient.ListSatellites(ctx, org, false) + satellites, err := cloudClient.ListSatellites(ctx, org) if err != nil { return []string{} } diff --git a/autocomplete/complete_cloud_client_test.go b/autocomplete/complete_cloud_client_test.go index 0c5499ca..6e57d740 100644 --- a/autocomplete/complete_cloud_client_test.go +++ b/autocomplete/complete_cloud_client_test.go @@ -80,7 +80,7 @@ func (mclc *mockCloudListClient) ListProjects(ctx context.Context, orgName strin return []*cloud.Project{}, nil } -func (mclc *mockCloudListClient) ListSatellites(ctx context.Context, orgName string, includeHidden bool) ([]cloud.SatelliteInstance, error) { +func (mclc *mockCloudListClient) ListSatellites(ctx context.Context, orgName string) ([]cloud.SatelliteInstance, error) { mclc.listSatellitesCallCount += 1 if orgName == "abba" { return []cloud.SatelliteInstance{ diff --git a/cloud/pipeline.go b/cloud/pipeline.go deleted file mode 100644 index 5a80e064..00000000 --- a/cloud/pipeline.go +++ /dev/null @@ -1,81 +0,0 @@ -package cloud - -import ( - "context" - pb "github.com/earthly/cloud-api/pipelines" - "github.com/pkg/errors" -) - -type PipelineTrigger struct { - Type string - Modifier string -} - -type PipelineArg struct { - Name string - DefaultValue string -} - -type Pipeline struct { - Repo string - Path string - Name string - Org string - Triggers []*PipelineTrigger - Args []*PipelineArg - RepoId string - Project string - IsPush bool - ID string - PathHash string - ProviderOrg string - SatelliteName string -} - -func (c *Client) ListPipelines(ctx context.Context, project, org, earthfileHash string) ([]Pipeline, error) { - resp, err := c.pipelines.ListPipelines(c.withAuth(ctx), &pb.ListPipelinesRequest{ - Project: project, - Org: org, - EarthfileHash: earthfileHash, - }) - if err != nil { - return nil, errors.Wrap(err, "failed listing pipelines") - } - - pipelines := make([]Pipeline, len(resp.Pipelines)) - for i, p := range resp.Pipelines { - triggers := make([]*PipelineTrigger, len(p.Triggers)) - for i, t := range p.Triggers { - triggers[i] = &PipelineTrigger{ - Type: t.Type.String(), - Modifier: t.Modifier, - } - } - - args := make([]*PipelineArg, len(p.Args)) - for i, a := range p.Args { - args[i] = &PipelineArg{ - Name: a.Name, - DefaultValue: a.DefaultValue, - } - } - - pipelines[i] = Pipeline{ - Repo: p.Repo, - Path: p.Path, - Name: p.Name, - Org: p.Org, - Triggers: triggers, - Args: args, - RepoId: p.RepoId, - Project: p.Project, - IsPush: p.IsPush, - ID: p.Id, - PathHash: p.PathHash, - ProviderOrg: p.ProviderOrg, - SatelliteName: p.SatelliteName, - } - } - - return pipelines, nil -} diff --git a/cloud/satellite.go b/cloud/satellite.go index e293a29f..5ca7defc 100644 --- a/cloud/satellite.go +++ b/cloud/satellite.go @@ -74,7 +74,6 @@ type SatelliteInstance struct { MaintenanceWindowEnd string MaintenanceWeekendsOnly bool RevisionID int32 - Hidden bool LastUsed time.Time CacheRetention time.Duration Address string @@ -83,14 +82,13 @@ type SatelliteInstance struct { CloudName string } -func (c *Client) ListSatellites(ctx context.Context, orgName string, includeHidden bool) ([]SatelliteInstance, error) { +func (c *Client) ListSatellites(ctx context.Context, orgName string) ([]SatelliteInstance, error) { orgID, err := c.GetOrgID(ctx, orgName) if err != nil { return nil, errors.Wrap(err, "failed listing satellites") } resp, err := c.compute.ListSatellites(c.withAuth(ctx), &pb.ListSatellitesRequest{ - OrgId: orgID, - IncludeHidden: includeHidden, + OrgId: orgID, }) if err != nil { return nil, errors.Wrap(err, "failed listing satellites") @@ -104,7 +102,6 @@ func (c *Client) ListSatellites(ctx context.Context, orgName string, includeHidd Size: s.Size, State: satelliteStatus(s.Status), Version: s.Version, - Hidden: s.Hidden, LastUsed: s.LastUsed.AsTime(), CacheRetention: s.CacheRetention.AsDuration(), CloudName: s.CloudName, @@ -138,7 +135,6 @@ func (c *Client) GetSatellite(ctx context.Context, name, orgName string) (*Satel MaintenanceWindowEnd: resp.MaintenanceWindowEnd, MaintenanceWeekendsOnly: resp.MaintenanceWeekendsOnly, RevisionID: resp.RevisionId, - Hidden: resp.Hidden, LastUsed: resp.LastUsed.AsTime(), CacheRetention: resp.CacheRetention.AsDuration(), IsManaged: resp.IsManaged, diff --git a/cmd/earthly/base/buildkit.go b/cmd/earthly/base/buildkit.go index 880ce40d..e7d02af0 100644 --- a/cmd/earthly/base/buildkit.go +++ b/cmd/earthly/base/buildkit.go @@ -175,7 +175,7 @@ func (c *CLI) GetSatelliteOrg(ctx context.Context, cloudClient *cloud.Client) (o } func GetSatelliteName(ctx context.Context, orgName, satelliteName string, cloudClient *cloud.Client) (string, error) { - satellites, err := cloudClient.ListSatellites(ctx, orgName, true) + satellites, err := cloudClient.ListSatellites(ctx, orgName) if err != nil { return "", err } @@ -185,16 +185,6 @@ func GetSatelliteName(ctx context.Context, orgName, satelliteName string, cloudC } } - pipelines, err := GetAllPipelinesForAllProjects(ctx, orgName, cloudClient) - if err != nil { - return "", err - } - for _, p := range pipelines { - if satelliteName == PipelineSatelliteName(&p) { - return p.SatelliteName, nil - } - } - return "", fmt.Errorf("satellite %q not found", satelliteName) } @@ -208,26 +198,3 @@ func (cli *CLI) reserveSatellite(ctx context.Context, cloudClient *cloud.Client, } return nil } - -func GetAllPipelinesForAllProjects(ctx context.Context, orgName string, cloudClient *cloud.Client) ([]cloud.Pipeline, error) { - projects, err := cloudClient.ListProjects(ctx, orgName) - if err != nil { - return nil, err - } - - allPipelines := make([]cloud.Pipeline, 0) - for _, pr := range projects { - pipelines, err := cloudClient.ListPipelines(ctx, pr.Name, orgName, "") - if err != nil { - return nil, err - } - - allPipelines = append(allPipelines, pipelines...) - } - - return allPipelines, nil -} - -func PipelineSatelliteName(p *cloud.Pipeline) string { - return fmt.Sprintf("%s/%s", p.Project, p.Name) -} diff --git a/cmd/earthly/subcmd/satellite_cmds.go b/cmd/earthly/subcmd/satellite_cmds.go index 3d924b4d..ca4b05dc 100644 --- a/cmd/earthly/subcmd/satellite_cmds.go +++ b/cmd/earthly/subcmd/satellite_cmds.go @@ -35,7 +35,6 @@ type Satellite struct { cloudName string force bool printJSON bool - listAll bool dropCache bool } @@ -162,13 +161,6 @@ as well as run builds in native architectures independent of where the Earthly c Required: false, Destination: &a.printJSON, }, - &cli.BoolFlag{ - Name: "all", - Aliases: []string{"a"}, - Usage: "Include hidden satellites in output. These are usually ones generated by Earthly CI.", - Required: false, - Destination: &a.listAll, - }, }, }, { @@ -309,44 +301,6 @@ func (a *Satellite) useSatellite(cliCtx *cli.Context, satelliteName, orgName str return nil } -type satelliteWithPipelineInfo struct { - satellite cloud.SatelliteInstance - pipeline *cloud.Pipeline -} - -func (swp satelliteWithPipelineInfo) satType() string { - if swp.pipeline != nil { - return "Pipe" - } - - return "Sat" -} - -func (swp satelliteWithPipelineInfo) satelliteName() string { - if swp.pipeline != nil { - return base.PipelineSatelliteName(swp.pipeline) - } - - return swp.satellite.Name -} - -func (a *Satellite) toSatellitePipelineInfo(satellites []cloud.SatelliteInstance, pipelines []cloud.Pipeline) []satelliteWithPipelineInfo { - res := make([]satelliteWithPipelineInfo, 0) - for _, s := range satellites { - swp := satelliteWithPipelineInfo{ - satellite: s, - } - for _, p := range pipelines { - if s.Name == p.SatelliteName { - swp.pipeline = &p - break - } - } - res = append(res, swp) - } - return res -} - func printRow(t *tabwriter.Writer, c []color.Attribute, items []string) { sprint := color.New(c...).SprintFunc() @@ -359,29 +313,15 @@ func printRow(t *tabwriter.Writer, c []color.Attribute, items []string) { fmt.Fprint(t, line) } -func (a *Satellite) printSatellitesTable(satellites []satelliteWithPipelineInfo, isOrgSelected bool) { - slices.SortStableFunc(satellites, func(a, b satelliteWithPipelineInfo) int { - // satellites with associated pipelines group together at the top of the list, - // otherwise sort alphabetically - if a.pipeline != nil && b.pipeline != nil { - return strings.Compare(a.pipeline.Name, b.pipeline.Name) - } else if a.pipeline == nil && b.pipeline != nil { - return +1 - } else if a.pipeline != nil && b.pipeline == nil { - return -1 - } - return strings.Compare(a.satellite.Name, b.satellite.Name) +func (a *Satellite) printSatellitesTable(satellites []cloud.SatelliteInstance, isOrgSelected bool) { + slices.SortStableFunc(satellites, func(a, b cloud.SatelliteInstance) int { + return strings.Compare(a.Name, b.Name) }) - includeTypeColumn := false includeCloudColumn := false cloudNames := make(map[string]bool) for _, s := range satellites { - if s.pipeline != nil { - includeTypeColumn = true - break - } - if n := s.satellite.CloudName; n != "" { + if n := s.CloudName; n != "" { cloudNames[n] = true } } @@ -391,41 +331,26 @@ func (a *Satellite) printSatellitesTable(satellites []satelliteWithPipelineInfo, t := tabwriter.NewWriter(os.Stdout, 1, 2, 2, ' ', 0) headerRow := []string{" ", "NAME", "PLATFORM", "SIZE", "VERSION", "STATE"} // The leading space is for the selection marker, leave it alone - if includeTypeColumn { - headerRow = slices.Insert(headerRow, 2, "TYPE") - } if includeCloudColumn { headerRow = append(headerRow, "CLOUD") } - if a.listAll { - headerRow = append(headerRow, "LAST USED", "CACHE") - } printRow(t, []color.Attribute{color.Reset}, headerRow) for _, s := range satellites { var selected = "" - if s.satelliteName() == a.cli.Cfg().Satellite.Name && isOrgSelected { + if s.Name == a.cli.Cfg().Satellite.Name && isOrgSelected { selected = "*" } - row := []string{selected, s.satelliteName(), s.satellite.Platform, s.satellite.Size, s.satellite.Version, strings.ToLower(s.satellite.State)} + row := []string{selected, s.Name, s.Platform, s.Size, s.Version, strings.ToLower(s.State)} c := []color.Attribute{color.Reset} - if s.pipeline != nil { - c = []color.Attribute{color.Faint} - } - if includeTypeColumn { - row = slices.Insert(row, 2, s.satType()) - } if includeCloudColumn { - name := s.satellite.CloudName + name := s.CloudName if name == "" { name = "-" } row = append(row, name) } - if a.listAll { - row = append(row, humanize.Time(s.satellite.LastUsed), durationWithDaysPart(s.satellite.CacheRetention)) - } printRow(t, c, row) } @@ -457,33 +382,26 @@ type satelliteJSON struct { Size string `json:"size"` Version string `json:"version"` Selected bool `json:"selected"` - Type string `json:"type"` Project string `json:"project"` - Pipeline string `json:"pipeline"` LastUsed string `json:"last_used"` CacheRetention string `json:"cache_retention"` CloudName string `json:"cloud_name"` } -func (a *Satellite) printSatellitesJSON(satellites []satelliteWithPipelineInfo, isOrgSelected bool) { +func (a *Satellite) printSatellitesJSON(satellites []cloud.SatelliteInstance, isOrgSelected bool) { jsonSats := make([]satelliteJSON, len(satellites)) for i, s := range satellites { - selected := s.satellite.Name == a.cli.Cfg().Satellite.Name && isOrgSelected + selected := s.Name == a.cli.Cfg().Satellite.Name && isOrgSelected jsonSats[i] = satelliteJSON{ - Name: s.satellite.Name, - Size: s.satellite.Size, - State: s.satellite.State, - Platform: s.satellite.Platform, - Version: s.satellite.Version, + Name: s.Name, + Size: s.Size, + State: s.State, + Platform: s.Platform, + Version: s.Version, Selected: selected, - Type: s.satType(), - LastUsed: s.satellite.LastUsed.String(), - CacheRetention: s.satellite.CacheRetention.String(), - CloudName: s.satellite.CloudName, - } - if s.pipeline != nil { - jsonSats[i].Project = s.pipeline.Project - jsonSats[i].Pipeline = s.pipeline.Name + LastUsed: s.LastUsed.String(), + CacheRetention: s.CacheRetention.String(), + CloudName: s.CloudName, } } b, err := json.MarshalIndent(jsonSats, "", " ") @@ -595,29 +513,21 @@ func (a *Satellite) actionSatelliteList(cliCtx *cli.Context) error { return err } - satellites, err := cloudClient.ListSatellites(cliCtx.Context, orgName, a.listAll) + satellites, err := cloudClient.ListSatellites(cliCtx.Context, orgName) if err != nil { return err } - pipelines := make([]cloud.Pipeline, 0) - if a.listAll { - pipelines, err = base.GetAllPipelinesForAllProjects(cliCtx.Context, orgName, cloudClient) - if err != nil { - return err - } - } - // a.cli.Cfg().Satellite.Org is deprecated, but we can still check it here for compatability // with config files that may still have it set isOrgSelected := a.cli.Cfg().Satellite.Org == orgName || a.cli.Cfg().Global.Org == orgName - satellitesWithPipelineInfo := a.toSatellitePipelineInfo(satellites, pipelines) if a.printJSON { - a.printSatellitesJSON(satellitesWithPipelineInfo, isOrgSelected) + a.printSatellitesJSON(satellites, isOrgSelected) } else { - a.printSatellitesTable(satellitesWithPipelineInfo, isOrgSelected) + a.printSatellitesTable(satellites, isOrgSelected) } + return nil } @@ -643,7 +553,7 @@ func (a *Satellite) actionRemove(cliCtx *cli.Context) error { return err } - satellites, err := cloudClient.ListSatellites(cliCtx.Context, orgName, true) + satellites, err := cloudClient.ListSatellites(cliCtx.Context, orgName) if err != nil { return err } @@ -652,9 +562,7 @@ func (a *Satellite) actionRemove(cliCtx *cli.Context) error { for _, s := range satellites { if a.cli.Flags().SatelliteName == s.Name { sat = &s - if s.Hidden { - return errors.New("cannot delete hidden satellites") - } + break } } if sat == nil { @@ -850,7 +758,7 @@ func (a *Satellite) actionSelect(cliCtx *cli.Context) error { // after the command was run. Its done this way to save some API calls. found := false satelliteName := "" - satellites, err := cloudClient.ListSatellites(cliCtx.Context, orgName, true) + satellites, err := cloudClient.ListSatellites(cliCtx.Context, orgName) if err != nil { return err } @@ -861,23 +769,6 @@ func (a *Satellite) actionSelect(cliCtx *cli.Context) error { } } - pipelines := make([]cloud.Pipeline, 0) - if !found { - pipelines, err = base.GetAllPipelinesForAllProjects(cliCtx.Context, orgName, cloudClient) - if err != nil { - return err - } - for _, p := range pipelines { - pipelineName := base.PipelineSatelliteName(&p) - if a.cli.Flags().SatelliteName == pipelineName { - found = true - // We use the pipeline name, so you know what it belongs to, instead of a UUID. - // Reverse lookup at use time is handled via base.GetSatelliteName(). - satelliteName = pipelineName - } - } - } - if !found { return fmt.Errorf("no satellite named %q found", a.cli.Flags().SatelliteName) } @@ -887,7 +778,7 @@ func (a *Satellite) actionSelect(cliCtx *cli.Context) error { return errors.Wrapf(err, "could not select satellite %s", a.cli.Flags().SatelliteName) } - a.printSatellitesTable(a.toSatellitePipelineInfo(satellites, pipelines), true) + a.printSatellitesTable(satellites, true) return nil }