Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Add satellite commands #387

Merged
merged 8 commits into from
Jul 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
lint and docs
  • Loading branch information
f0ssel committed Jul 16, 2021
commit 84c723169870f9e875133ee207e281e7d850f183
6 changes: 3 additions & 3 deletions coder-sdk/satellite.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
)

type Satellite struct {
ID string `json:"id"`
Name string `json:"name"`
Fingerprint string `json:"fingerprint"`
ID string `json:"id"`
Name string `json:"name"`
Fingerprint string `json:"fingerprint"`
}

type Satellites struct {
Expand Down
1 change: 1 addition & 0 deletions docs/coder.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ coder provides a CLI for working with an existing Coder installation
* [coder images](coder_images.md) - Manage Coder images
* [coder login](coder_login.md) - Authenticate this client for future operations
* [coder logout](coder_logout.md) - Remove local authentication credentials if any exist
* [coder satellites](coder_satellites.md) - Interact with Coder satellite deployments
* [coder ssh](coder_ssh.md) - Enter a shell of execute a command over SSH into a Coder workspace
* [coder sync](coder_sync.md) - Establish a one way directory sync to a Coder workspace
* [coder tokens](coder_tokens.md) - manage Coder API tokens for the active user
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func Make() *cobra.Command {
genDocsCmd(app),
agentCmd(),
tunnelCmd(),
satellitesCmd(),
)
app.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "show verbose output")
return app
Expand Down
31 changes: 14 additions & 17 deletions internal/cmd/satellites.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

const (
satelliteKeyPath = "/api/private/satellites/key"
satelliteKeyPath = "/api/private/satellites/key"
)

type satelliteKeyResponse struct {
Expand All @@ -28,10 +28,9 @@ type satelliteKeyResponse struct {

func satellitesCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "satellites",
Short: "Interact with Coder satellite deployments",
Long: "Perform operations on the Coder satellites for the platform.",
Hidden: true,
Use: "satellites",
Short: "Interact with Coder satellite deployments",
Long: "Perform operations on the Coder satellites for the platform.",
}

cmd.AddCommand(
Expand All @@ -53,19 +52,19 @@ func createSatelliteCmd() *cobra.Command {
coder satellites create eu-west https://eu-west-coder.com`,
RunE: func(cmd *cobra.Command, args []string) error {
var (
ctx = cmd.Context()
name = args[0]
ctx = cmd.Context()
name = args[0]
accessURL = args[1]
)

client, err := newClient(ctx, true)
if err != nil {
return xerrors.Errorf("making coder client", err)
return xerrors.Errorf("making coder client: %w", err)
}

sURL, err := url.Parse(accessURL)
if err != nil {
return xerrors.Errorf("parsing satellite access url", err)
return xerrors.Errorf("parsing satellite access url: %w", err)
}
sURL.Path = satelliteKeyPath

Expand All @@ -90,10 +89,10 @@ coder satellites create eu-west https://eu-west-coder.com`,
}

if keyRes.Key == "" {
return xerrors.Errorf("key field empty in response")
return xerrors.New("key field empty in response")
}
if keyRes.Fingerprint == "" {
return xerrors.Errorf("fingerprint field empty in response")
return xerrors.New("fingerprint field empty in response")
}

fmt.Printf(`The following satellite will be created:
Expand Down Expand Up @@ -156,12 +155,12 @@ coder satellites ls`,

client, err := newClient(ctx, true)
if err != nil {
return xerrors.Errorf("making coder client", err)
return xerrors.Errorf("making coder client: %w", err)
}

sats, err := client.Satellites(ctx)
if err != nil {
return xerrors.Errorf("get satellites request", err)
return xerrors.Errorf("get satellites request: %w", err)
}

err = tablewriter.WriteTable(cmd.OutOrStdout(), len(sats.Data), func(i int) interface{} {
Expand Down Expand Up @@ -196,14 +195,14 @@ coder satellites rm my-satellite`,

sats, err := client.Satellites(ctx)
if err != nil {
return xerrors.Errorf("get satellites request", err)
return xerrors.Errorf("get satellites request: %w", err)
}

for _, sat := range sats.Data {
if sat.Name == name {
err = client.DeleteSatelliteByID(ctx, sat.ID)
if err != nil {
return xerrors.Errorf("delete satellites request", err)
return xerrors.Errorf("delete satellites request: %w", err)
}
clog.LogSuccess(fmt.Sprintf("satellite %s successfully deleted", name))

Expand All @@ -216,5 +215,3 @@ coder satellites rm my-satellite`,
}
return cmd
}