Skip to content

feat: add provisioner key cli commands #13875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 18, 2024
Merged
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
remove rows type
  • Loading branch information
f0ssel committed Jul 18, 2024
commit 86c0d02bb2c3f7d1d821b41ceb752077d18f9640
30 changes: 2 additions & 28 deletions enterprise/cli/provisionerkeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package cli
import (
"fmt"
"strings"
"time"

"github.com/google/uuid"
"golang.org/x/xerrors"

agpl "github.com/coder/coder/v2/cli"
Expand Down Expand Up @@ -77,34 +75,11 @@ func (r *RootCmd) provisionerKeysCreate() *serpent.Command {
return cmd
}

type provisionerKeysTableRow struct {
// For json output:
Key codersdk.ProvisionerKey `table:"-"`

// For table output:
Name string `json:"-" table:"name,default_sort"`
CreatedAt time.Time `json:"-" table:"created_at"`
OrganizationID uuid.UUID `json:"-" table:"organization_id"`
}

func provisionerKeysToRows(keys ...codersdk.ProvisionerKey) []provisionerKeysTableRow {
rows := make([]provisionerKeysTableRow, 0, len(keys))
for _, key := range keys {
rows = append(rows, provisionerKeysTableRow{
Name: key.Name,
CreatedAt: key.CreatedAt,
OrganizationID: key.OrganizationID,
})
}

return rows
}

func (r *RootCmd) provisionerKeysList() *serpent.Command {
var (
orgContext = agpl.NewOrganizationContext()
formatter = cliui.NewOutputFormatter(
cliui.TableFormat([]provisionerKeysTableRow{}, nil),
cliui.TableFormat([]codersdk.ProvisionerKey{}, nil),
cliui.JSONFormat(),
)
)
Expand Down Expand Up @@ -136,8 +111,7 @@ func (r *RootCmd) provisionerKeysList() *serpent.Command {
return nil
}

rows := provisionerKeysToRows(keys...)
out, err := formatter.Format(inv.Context(), rows)
out, err := formatter.Format(inv.Context(), keys)
if err != nil {
return xerrors.Errorf("display provisioner keys: %w", err)
}
Expand Down
Loading