Skip to content

Commit dd0e5b9

Browse files
committed
Merge origin/main
2 parents 4e6bda0 + e0165c5 commit dd0e5b9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1551
-328
lines changed

.goreleaser.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ docker_manifests:
153153

154154
release:
155155
ids: [coder-linux, coder-darwin, coder-windows, packages]
156+
footer: |
157+
## Container Image
158+
- `docker pull ghcr.io/coder/coder:{{ .Tag }}`
156159
157160
signs:
158161
- ids: [coder-darwin]

cli/cliui/parameter.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/coder/coder/codersdk"
1111
)
1212

13-
func ParameterSchema(cmd *cobra.Command, parameterSchema codersdk.TemplateVersionParameterSchema) (string, error) {
13+
func ParameterSchema(cmd *cobra.Command, parameterSchema codersdk.ParameterSchema) (string, error) {
1414
_, _ = fmt.Fprintln(cmd.OutOrStdout(), Styles.Bold.Render("var."+parameterSchema.Name))
1515
if parameterSchema.Description != "" {
1616
_, _ = fmt.Fprintln(cmd.OutOrStdout(), " "+strings.TrimSpace(strings.Join(strings.Split(parameterSchema.Description, "\n"), "\n "))+"\n")
@@ -30,16 +30,32 @@ func ParameterSchema(cmd *cobra.Command, parameterSchema codersdk.TemplateVersio
3030
_, _ = fmt.Fprint(cmd.OutOrStdout(), "\033[1A")
3131
value, err = Select(cmd, SelectOptions{
3232
Options: options,
33+
Default: parameterSchema.DefaultSourceValue,
3334
HideSearch: true,
3435
})
3536
if err == nil {
3637
_, _ = fmt.Fprintln(cmd.OutOrStdout())
3738
_, _ = fmt.Fprintln(cmd.OutOrStdout(), " "+Styles.Prompt.String()+Styles.Field.Render(value))
3839
}
3940
} else {
41+
text := "Enter a value"
42+
if parameterSchema.DefaultSourceValue != "" {
43+
text += fmt.Sprintf(" (default: %q)", parameterSchema.DefaultSourceValue)
44+
}
45+
text += ":"
46+
4047
value, err = Prompt(cmd, PromptOptions{
41-
Text: Styles.Bold.Render("Enter a value:"),
48+
Text: Styles.Bold.Render(text),
4249
})
4350
}
44-
return value, err
51+
if err != nil {
52+
return "", err
53+
}
54+
55+
// If they didn't specify anything, use the default value if set.
56+
if len(options) == 0 && value == "" {
57+
value = parameterSchema.DefaultSourceValue
58+
}
59+
60+
return value, nil
4561
}

cli/cliui/select.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ func init() {
3535
}
3636

3737
type SelectOptions struct {
38-
Options []string
38+
Options []string
39+
// Default will be highlighted first if it's a valid option.
40+
Default string
3941
Size int
4042
HideSearch bool
4143
}
@@ -50,9 +52,16 @@ func Select(cmd *cobra.Command, opts SelectOptions) (string, error) {
5052
if flag.Lookup("test.v") != nil {
5153
return opts.Options[0], nil
5254
}
55+
56+
var defaultOption interface{}
57+
if opts.Default != "" {
58+
defaultOption = opts.Default
59+
}
60+
5361
var value string
5462
err := survey.AskOne(&survey.Select{
5563
Options: opts.Options,
64+
Default: defaultOption,
5665
PageSize: opts.Size,
5766
}, &value, survey.WithIcons(func(is *survey.IconSet) {
5867
is.Help.Text = "Type to search"

cli/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func create() *cobra.Command {
135135
Name: parameterSchema.Name,
136136
SourceValue: value,
137137
SourceScheme: database.ParameterSourceSchemeData,
138-
DestinationScheme: parameterSchema.DefaultDestinationScheme,
138+
DestinationScheme: database.ParameterDestinationScheme(parameterSchema.DefaultDestinationScheme),
139139
})
140140
}
141141
_, _ = fmt.Fprintln(cmd.OutOrStdout())

cli/create_test.go

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cli_test
22

33
import (
4+
"fmt"
45
"testing"
56

67
"github.com/stretchr/testify/require"
@@ -44,6 +45,7 @@ func TestCreate(t *testing.T) {
4445
}
4546
<-doneChan
4647
})
48+
4749
t.Run("CreateFromList", func(t *testing.T) {
4850
t.Parallel()
4951
client := coderdtest.New(t, nil)
@@ -74,6 +76,7 @@ func TestCreate(t *testing.T) {
7476
}
7577
<-doneChan
7678
})
79+
7780
t.Run("FromNothing", func(t *testing.T) {
7881
t.Parallel()
7982
client := coderdtest.New(t, nil)
@@ -105,33 +108,52 @@ func TestCreate(t *testing.T) {
105108
}
106109
<-doneChan
107110
})
111+
108112
t.Run("WithParameter", func(t *testing.T) {
109113
t.Parallel()
110114
client := coderdtest.New(t, nil)
111115
user := coderdtest.CreateFirstUser(t, client)
112116
coderdtest.NewProvisionerDaemon(t, client)
117+
118+
defaultValue := "something"
113119
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
114120
Parse: []*proto.Parse_Response{{
115121
Type: &proto.Parse_Response_Complete{
116122
Complete: &proto.Parse_Complete{
117-
ParameterSchemas: []*proto.ParameterSchema{{
118-
AllowOverrideSource: true,
119-
Name: "region",
120-
Description: "description",
121-
DefaultSource: &proto.ParameterSource{
122-
Scheme: proto.ParameterSource_DATA,
123-
Value: "something",
123+
ParameterSchemas: []*proto.ParameterSchema{
124+
{
125+
AllowOverrideSource: true,
126+
Name: "region",
127+
Description: "description 1",
128+
DefaultSource: &proto.ParameterSource{
129+
Scheme: proto.ParameterSource_DATA,
130+
Value: defaultValue,
131+
},
132+
DefaultDestination: &proto.ParameterDestination{
133+
Scheme: proto.ParameterDestination_PROVISIONER_VARIABLE,
134+
},
124135
},
125-
DefaultDestination: &proto.ParameterDestination{
126-
Scheme: proto.ParameterDestination_PROVISIONER_VARIABLE,
136+
{
137+
AllowOverrideSource: true,
138+
Name: "username",
139+
Description: "description 2",
140+
DefaultSource: &proto.ParameterSource{
141+
Scheme: proto.ParameterSource_DATA,
142+
// No default value
143+
Value: "",
144+
},
145+
DefaultDestination: &proto.ParameterDestination{
146+
Scheme: proto.ParameterDestination_PROVISIONER_VARIABLE,
147+
},
127148
},
128-
}},
149+
},
129150
},
130151
},
131152
}},
132153
Provision: echo.ProvisionComplete,
133154
ProvisionDryRun: echo.ProvisionComplete,
134155
})
156+
135157
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
136158
_ = coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
137159
cmd, root := clitest.New(t, "create", "")
@@ -145,9 +167,11 @@ func TestCreate(t *testing.T) {
145167
err := cmd.Execute()
146168
require.NoError(t, err)
147169
}()
170+
148171
matches := []string{
149172
"Specify a name", "my-workspace",
150-
"Enter a value", "bananas",
173+
fmt.Sprintf("Enter a value (default: %q):", defaultValue), "bingo",
174+
"Enter a value:", "boingo",
151175
"Confirm create?", "yes",
152176
}
153177
for i := 0; i < len(matches); i += 2 {

cli/login.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func login() *cobra.Command {
164164
cliui.Styles.Paragraph.Render(fmt.Sprintf("Welcome to Coder, %s! You're authenticated.", cliui.Styles.Keyword.Render(username)))+"\n")
165165

166166
_, _ = fmt.Fprintf(cmd.OutOrStdout(),
167-
cliui.Styles.Paragraph.Render("Get started by creating a template: "+cliui.Styles.Code.Render("coder templates create"))+"\n")
167+
cliui.Styles.Paragraph.Render("Get started by creating a template: "+cliui.Styles.Code.Render("coder templates init"))+"\n")
168168
return nil
169169
}
170170

cli/templatecreate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func createValidTemplateVersion(cmd *cobra.Command, client *codersdk.Client, org
175175
sort.Slice(parameterSchemas, func(i, j int) bool {
176176
return parameterSchemas[i].Name < parameterSchemas[j].Name
177177
})
178-
missingSchemas := make([]codersdk.TemplateVersionParameterSchema, 0)
178+
missingSchemas := make([]codersdk.ParameterSchema, 0)
179179
for _, parameterSchema := range parameterSchemas {
180180
_, ok := valuesBySchemaID[parameterSchema.ID.String()]
181181
if ok {
@@ -193,7 +193,7 @@ func createValidTemplateVersion(cmd *cobra.Command, client *codersdk.Client, org
193193
Name: parameterSchema.Name,
194194
SourceValue: value,
195195
SourceScheme: database.ParameterSourceSchemeData,
196-
DestinationScheme: parameterSchema.DefaultDestinationScheme,
196+
DestinationScheme: database.ParameterDestinationScheme(parameterSchema.DefaultDestinationScheme),
197197
})
198198
_, _ = fmt.Fprintln(cmd.OutOrStdout())
199199
}

coderd/autobuild/executor/lifecycle_executor_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"os"
7+
"strings"
78
"testing"
89
"time"
910

@@ -470,6 +471,9 @@ func mustTransitionWorkspace(t *testing.T, client *codersdk.Client, workspaceID
470471
func mustWorkspace(t *testing.T, client *codersdk.Client, workspaceID uuid.UUID) codersdk.Workspace {
471472
ctx := context.Background()
472473
ws, err := client.Workspace(ctx, workspaceID)
474+
if err != nil && strings.Contains(err.Error(), "status code 410") {
475+
ws, err = client.DeletedWorkspace(ctx, workspaceID)
476+
}
473477
require.NoError(t, err, "no workspace found with id %s", workspaceID)
474478
return ws
475479
}

coderd/coderd.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func New(options *Options) (http.Handler, func()) {
149149
r.Get("/", api.workspacesByOrganization)
150150
r.Route("/{user}", func(r chi.Router) {
151151
r.Use(httpmw.ExtractUserParam(options.Database))
152-
r.Get("/{workspace}", api.workspaceByOwnerAndName)
152+
r.Get("/{workspacename}", api.workspaceByOwnerAndName)
153153
r.Get("/", api.workspacesByOwner)
154154
})
155155
})
@@ -237,8 +237,6 @@ func New(options *Options) (http.Handler, func()) {
237237
r.Route("/password", func(r chi.Router) {
238238
r.Put("/", api.putUserPassword)
239239
})
240-
r.Get("/organizations", api.organizationsByUser)
241-
r.Post("/organizations", api.postOrganizationsByUser)
242240
// These roles apply to the site wide permissions.
243241
r.Put("/roles", api.putUserRoles)
244242
r.Get("/roles", api.userRoles)
@@ -310,11 +308,13 @@ func New(options *Options) (http.Handler, func()) {
310308
r.Route("/autostop", func(r chi.Router) {
311309
r.Put("/", api.putWorkspaceAutostop)
312310
})
311+
r.Get("/watch", api.watchWorkspace)
313312
})
314313
})
315314
r.Route("/workspacebuilds/{workspacebuild}", func(r chi.Router) {
316315
r.Use(
317316
apiKeyMiddleware,
317+
authRolesMiddleware,
318318
httpmw.ExtractWorkspaceBuildParam(options.Database),
319319
httpmw.ExtractWorkspaceParam(options.Database),
320320
)

0 commit comments

Comments
 (0)