Skip to content

Commit 555c636

Browse files
author
Katie Horne
committed
Merge branch 'main' into cli-ui-copyedits
2 parents 9400b2f + 29c9c1d commit 555c636

13 files changed

+203
-50
lines changed

cli/parameters.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package cli
2+
3+
import (
4+
"github.com/jedib0t/go-pretty/v6/table"
5+
"github.com/spf13/cobra"
6+
7+
"github.com/coder/coder/cli/cliui"
8+
"github.com/coder/coder/codersdk"
9+
)
10+
11+
func parameters() *cobra.Command {
12+
cmd := &cobra.Command{
13+
Short: "List parameters for a given scope",
14+
Example: "coder parameters list workspace my-workspace",
15+
Use: "parameters",
16+
// Currently hidden as this shows parameter values, not parameter
17+
// schemes. Until we have a good way to distinguish the two, it's better
18+
// not to add confusion or lock ourselves into a certain api.
19+
// This cmd is still valuable debugging tool for devs to avoid
20+
// constructing curl requests.
21+
Hidden: true,
22+
Aliases: []string{"params"},
23+
}
24+
cmd.AddCommand(
25+
parameterList(),
26+
)
27+
return cmd
28+
}
29+
30+
// displayParameters will return a table displaying all parameters passed in.
31+
// filterColumns must be a subset of the parameter fields and will determine which
32+
// columns to display
33+
func displayParameters(filterColumns []string, params ...codersdk.Parameter) string {
34+
tableWriter := cliui.Table()
35+
header := table.Row{"id", "scope", "scope id", "name", "source scheme", "destination scheme", "created at", "updated at"}
36+
tableWriter.AppendHeader(header)
37+
tableWriter.SetColumnConfigs(cliui.FilterTableColumns(header, filterColumns))
38+
tableWriter.SortBy([]table.SortBy{{
39+
Name: "name",
40+
}})
41+
for _, param := range params {
42+
tableWriter.AppendRow(table.Row{
43+
param.ID.String(),
44+
param.Scope,
45+
param.ScopeID.String(),
46+
param.Name,
47+
param.SourceScheme,
48+
param.DestinationScheme,
49+
param.CreatedAt,
50+
param.UpdatedAt,
51+
})
52+
}
53+
return tableWriter.Render()
54+
}

cli/parameterslist.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package cli
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/google/uuid"
7+
"github.com/spf13/cobra"
8+
"golang.org/x/xerrors"
9+
10+
"github.com/coder/coder/codersdk"
11+
)
12+
13+
func parameterList() *cobra.Command {
14+
var (
15+
columns []string
16+
)
17+
cmd := &cobra.Command{
18+
Use: "list",
19+
Aliases: []string{"ls"},
20+
Args: cobra.ExactArgs(2),
21+
RunE: func(cmd *cobra.Command, args []string) error {
22+
scope, name := args[0], args[1]
23+
24+
client, err := createClient(cmd)
25+
if err != nil {
26+
return err
27+
}
28+
29+
organization, err := currentOrganization(cmd, client)
30+
if err != nil {
31+
return xerrors.Errorf("get current organization: %w", err)
32+
}
33+
34+
var scopeID uuid.UUID
35+
switch codersdk.ParameterScope(scope) {
36+
case codersdk.ParameterWorkspace:
37+
workspace, err := namedWorkspace(cmd, client, name)
38+
if err != nil {
39+
return err
40+
}
41+
scopeID = workspace.ID
42+
case codersdk.ParameterTemplate:
43+
template, err := client.TemplateByName(cmd.Context(), organization.ID, name)
44+
if err != nil {
45+
return xerrors.Errorf("get workspace template: %w", err)
46+
}
47+
scopeID = template.ID
48+
49+
case codersdk.ParameterScopeImportJob, "template_version":
50+
scope = string(codersdk.ParameterScopeImportJob)
51+
scopeID, err = uuid.Parse(name)
52+
if err != nil {
53+
return xerrors.Errorf("%q must be a uuid for this scope type", name)
54+
}
55+
default:
56+
return xerrors.Errorf("%q is an unsupported scope, use %v", scope, []codersdk.ParameterScope{
57+
codersdk.ParameterWorkspace, codersdk.ParameterTemplate, codersdk.ParameterScopeImportJob,
58+
})
59+
}
60+
61+
params, err := client.Parameters(cmd.Context(), codersdk.ParameterScope(scope), scopeID)
62+
if err != nil {
63+
return xerrors.Errorf("fetch params: %w", err)
64+
}
65+
66+
_, err = fmt.Fprintln(cmd.OutOrStdout(), displayParameters(columns, params...))
67+
return err
68+
},
69+
}
70+
cmd.Flags().StringArrayVarP(&columns, "column", "c", []string{"name", "source_scheme", "destination_scheme"},
71+
"Specify a column to filter in the table.")
72+
return cmd
73+
}

cli/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ func Root() *cobra.Command {
9090
portForward(),
9191
workspaceAgent(),
9292
versionCmd(),
93+
parameters(),
9394
)
9495

9596
cmd.SetUsageTemplate(usageTemplate())

cli/templatelist.go

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import (
44
"fmt"
55

66
"github.com/fatih/color"
7-
"github.com/jedib0t/go-pretty/v6/table"
87
"github.com/spf13/cobra"
9-
10-
"github.com/coder/coder/cli/cliui"
118
)
129

1310
func templateList() *cobra.Command {
14-
return &cobra.Command{
11+
var (
12+
columns []string
13+
)
14+
cmd := &cobra.Command{
1515
Use: "list",
1616
Aliases: []string{"ls"},
1717
RunE: func(cmd *cobra.Command, args []string) error {
@@ -34,22 +34,11 @@ func templateList() *cobra.Command {
3434
return nil
3535
}
3636

37-
tableWriter := cliui.Table()
38-
tableWriter.AppendHeader(table.Row{"Name", "Last updated", "Used by"})
39-
40-
for _, template := range templates {
41-
suffix := ""
42-
if template.WorkspaceOwnerCount != 1 {
43-
suffix = "s"
44-
}
45-
tableWriter.AppendRow(table.Row{
46-
template.Name,
47-
template.UpdatedAt.Format("January 2, 2006"),
48-
cliui.Styles.Fuschia.Render(fmt.Sprintf("%d developer%s", template.WorkspaceOwnerCount, suffix)),
49-
})
50-
}
51-
_, err = fmt.Fprintln(cmd.OutOrStdout(), tableWriter.Render())
37+
_, err = fmt.Fprintln(cmd.OutOrStdout(), displayTemplates(columns, templates...))
5238
return err
5339
},
5440
}
41+
cmd.Flags().StringArrayVarP(&columns, "column", "c", []string{"name", "last_updated", "used_by"},
42+
"Specify a column to filter in the table.")
43+
return cmd
5544
}

cli/templates.go

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
package cli
22

33
import (
4+
"fmt"
5+
"time"
6+
7+
"github.com/jedib0t/go-pretty/v6/table"
48
"github.com/spf13/cobra"
59

610
"github.com/coder/coder/cli/cliui"
11+
"github.com/coder/coder/codersdk"
712
)
813

914
func templates() *cobra.Command {
@@ -17,7 +22,7 @@ func templates() *cobra.Command {
1722
` + cliui.Styles.Code.Render("$ coder templates create") + `
1823
1924
- Make changes to your template, and plan the changes
20-
25+
2126
` + cliui.Styles.Code.Render("$ coder templates plan <name>") + `
2227
2328
- Update the template. Your developers can update their workspaces
@@ -38,3 +43,36 @@ func templates() *cobra.Command {
3843

3944
return cmd
4045
}
46+
47+
// displayTemplates will return a table displaying all templates passed in.
48+
// filterColumns must be a subset of the template fields and will determine which
49+
// columns to display
50+
func displayTemplates(filterColumns []string, templates ...codersdk.Template) string {
51+
tableWriter := cliui.Table()
52+
header := table.Row{
53+
"Name", "Created At", "Last Updated", "Organization ID", "Provisioner",
54+
"Active Version ID", "Used By", "Max TTL", "Min Autostart"}
55+
tableWriter.AppendHeader(header)
56+
tableWriter.SetColumnConfigs(cliui.FilterTableColumns(header, filterColumns))
57+
tableWriter.SortBy([]table.SortBy{{
58+
Name: "name",
59+
}})
60+
for _, template := range templates {
61+
suffix := ""
62+
if template.WorkspaceOwnerCount != 1 {
63+
suffix = "s"
64+
}
65+
tableWriter.AppendRow(table.Row{
66+
template.Name,
67+
template.CreatedAt.Format("January 2, 2006"),
68+
template.UpdatedAt.Format("January 2, 2006"),
69+
template.OrganizationID.String(),
70+
template.Provisioner,
71+
template.ActiveVersionID.String(),
72+
cliui.Styles.Fuschia.Render(fmt.Sprintf("%d developer%s", template.WorkspaceOwnerCount, suffix)),
73+
(time.Duration(template.MaxTTLMillis) * time.Millisecond).String(),
74+
(time.Duration(template.MinAutostartIntervalMillis) * time.Millisecond).String(),
75+
})
76+
}
77+
return tableWriter.Render()
78+
}

cli/users.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func users() *cobra.Command {
3030
// columns to display
3131
func displayUsers(filterColumns []string, users ...codersdk.User) string {
3232
tableWriter := cliui.Table()
33-
header := table.Row{"id", "username", "email", "created_at", "status"}
33+
header := table.Row{"id", "username", "email", "created at", "status"}
3434
tableWriter.AppendHeader(header)
3535
tableWriter.SetColumnConfigs(cliui.FilterTableColumns(header, filterColumns))
3636
tableWriter.SortBy([]table.SortBy{{

codersdk/parameters.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ import (
1414
type ParameterScope string
1515

1616
const (
17-
ParameterTemplate ParameterScope = "template"
18-
ParameterWorkspace ParameterScope = "workspace"
17+
ParameterTemplate ParameterScope = "template"
18+
ParameterWorkspace ParameterScope = "workspace"
19+
ParameterScopeImportJob ParameterScope = "import_job"
1920
)
2021

2122
type ParameterSourceScheme string

docs/SECURITY.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Security Policy
22

3-
Keeping your code secure is central to what we do. If you find a vulnerability,
4-
please send an email to security@coder.com.
3+
If you find a vulnerability, **DO NOT FILE AN ISSUE**.
4+
Instead, send an email to security@coder.com.

docs/install.md

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,21 @@
11
# Install
22

3-
This article walks you through the various ways of installing and deploying Coder.
4-
53
## install.sh
64

7-
The easiest way to install Coder is to use our [install script](https://github.com/coder/coder/blob/main/install.sh) for Linux and macOS. The install script
8-
attempts to use the system package manager detection-reference if possible.
5+
The easiest way to install Coder is to use our [install script](https://github.com/coder/coder/blob/main/install.sh) for Linux and macOS.
96

10-
You can preview what occurs during the install process:
7+
To install, run:
118

129
```bash
13-
curl -L https://coder.com/install.sh | sh -s -- --dry-run
10+
curl -L https://coder.com/install.sh | sh
1411
```
1512

16-
To install, run:
13+
You can preview what occurs during the install process:
1714

1815
```bash
19-
curl -L https://coder.com/install.sh | sh
16+
curl -L https://coder.com/install.sh | sh -s -- --dry-run
2017
```
2118

22-
> If you're concerned about the install script's use of `curl | sh` and the
23-
> security implications, please see [this blog
24-
> post](https://sandstorm.io/news/2015-09-24-is-curl-bash-insecure-pgp-verified-install)
25-
> by [sandstorm.io](https://sandstorm.io).
26-
2719
You can modify the installation process by including flags. Run the help command for reference:
2820

2921
```bash

docs/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"path": "./CODE_OF_CONDUCT.md"
4444
},
4545
{
46-
"title": "Security policy",
46+
"title": "Security",
4747
"description": "How to report vulnerabilities in Coder",
4848
"path": "./SECURITY.md"
4949
}

install.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,15 @@ $1 package has been installed.
112112
To run Coder as a system service:
113113
114114
# Set up an external access URL or enable CODER_TUNNEL
115-
sudo vim /etc/coder.d/coder.env
115+
$ sudo vim /etc/coder.d/coder.env
116116
# Use systemd to start Coder now and on reboot
117-
sudo systemctl enable --now coder
117+
$ sudo systemctl enable --now coder
118118
# View the logs to ensure a successful start
119-
journalctl -u coder.service -b
119+
$ journalctl -u coder.service -b
120+
121+
Or, just run the server directly:
122+
123+
$ coder server
120124
121125
EOF
122126
}
@@ -329,7 +333,7 @@ install_deb() {
329333

330334
fetch "https://github.com/coder/coder/releases/download/v$VERSION/coder_${VERSION}_${OS}_${ARCH}.deb" \
331335
"$CACHE_DIR/coder_${VERSION}_$ARCH.deb"
332-
sudo_sh_c dpkg -i "$CACHE_DIR/coder_${VERSION}_$ARCH.deb"
336+
sudo_sh_c dpkg --force-confdef --force-confold -i "$CACHE_DIR/coder_${VERSION}_$ARCH.deb"
333337

334338
echo_systemd_postinstall deb
335339
}

preinstall.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ USER="coder"
66
# Add a Coder user to run as in systemd.
77
if ! id -u $USER >/dev/null 2>&1; then
88
useradd \
9+
--create-home \
910
--system \
1011
--user-group \
1112
--shell /bin/false \

site/src/api/typesGenerated.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export interface CreateOrganizationRequest {
4949
readonly name: string
5050
}
5151

52-
// From codersdk/parameters.go:79:6
52+
// From codersdk/parameters.go:80:6
5353
export interface CreateParameterRequest {
5454
readonly name: string
5555
readonly source_value: string
@@ -160,7 +160,7 @@ export interface Pagination {
160160
readonly offset?: number
161161
}
162162

163-
// From codersdk/parameters.go:44:6
163+
// From codersdk/parameters.go:45:6
164164
export interface Parameter {
165165
readonly id: string
166166
readonly created_at: string
@@ -172,7 +172,7 @@ export interface Parameter {
172172
readonly destination_scheme: ParameterDestinationScheme
173173
}
174174

175-
// From codersdk/parameters.go:55:6
175+
// From codersdk/parameters.go:56:6
176176
export interface ParameterSchema {
177177
readonly id: string
178178
readonly created_at: string
@@ -494,16 +494,16 @@ export type LogLevel = "debug" | "error" | "info" | "trace" | "warn"
494494
// From codersdk/provisionerdaemons.go:16:6
495495
export type LogSource = "provisioner" | "provisioner_daemon"
496496

497-
// From codersdk/parameters.go:28:6
497+
// From codersdk/parameters.go:29:6
498498
export type ParameterDestinationScheme = "environment_variable" | "none" | "provisioner_variable"
499499

500500
// From codersdk/parameters.go:14:6
501-
export type ParameterScope = "template" | "workspace"
501+
export type ParameterScope = "import_job" | "template" | "workspace"
502502

503-
// From codersdk/parameters.go:21:6
503+
// From codersdk/parameters.go:22:6
504504
export type ParameterSourceScheme = "data" | "none"
505505

506-
// From codersdk/parameters.go:36:6
506+
// From codersdk/parameters.go:37:6
507507
export type ParameterTypeSystem = "hcl" | "none"
508508

509509
// From codersdk/provisionerdaemons.go:42:6

0 commit comments

Comments
 (0)