Skip to content

Commit e6ddf3c

Browse files
committed
fixup! feat: add slug property to app, use in URLs
1 parent ec5ecfe commit e6ddf3c

12 files changed

+534
-140
lines changed

coderd/provisionerdaemons.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -814,8 +814,8 @@ func insertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
814814
if slug == "" {
815815
return xerrors.Errorf("app must have a slug or name set")
816816
}
817-
if !provisioner.ValidAppNameRegex.MatchString(slug) {
818-
return xerrors.Errorf("app slug %q does not match regex %q", slug, provisioner.ValidAppNameRegex.String())
817+
if !provisioner.ValidAppSlugRegex.MatchString(slug) {
818+
return xerrors.Errorf("app slug %q does not match regex %q", slug, provisioner.ValidAppSlugRegex.String())
819819
}
820820

821821
health := database.WorkspaceAppHealthDisabled

provisioner/appname.go

Lines changed: 0 additions & 14 deletions
This file was deleted.

provisioner/appslug.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package provisioner
2+
3+
import "regexp"
4+
5+
var (
6+
// ValidAppSlugRegex is the regex used to validate the slug of a coder_app
7+
// resource. It must be a valid hostname and cannot contain two consecutive
8+
// hyphens or start/end with a hyphen.
9+
//
10+
// This regex is duplicated in the terraform provider code, so make sure to
11+
// update it there as well.
12+
//
13+
// There are test cases for this regex in appslug_test.go.
14+
ValidAppSlugRegex = regexp.MustCompile(`^[a-z0-9](-?[a-z0-9])*$`)
15+
)

provisioner/appname_test.go renamed to provisioner/appslug_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/coder/coder/provisioner"
99
)
1010

11-
func TestValidAppNameRegex(t *testing.T) {
11+
func TestValidAppSlugRegex(t *testing.T) {
1212
t.Parallel()
1313

1414
t.Run("Valid", func(t *testing.T) {
@@ -32,7 +32,7 @@ func TestValidAppNameRegex(t *testing.T) {
3232
}
3333

3434
for _, s := range validStrings {
35-
require.True(t, provisioner.ValidAppNameRegex.MatchString(s), s)
35+
require.True(t, provisioner.ValidAppSlugRegex.MatchString(s), s)
3636
}
3737
})
3838

@@ -58,7 +58,7 @@ func TestValidAppNameRegex(t *testing.T) {
5858
}
5959

6060
for _, s := range invalidStrings {
61-
require.False(t, provisioner.ValidAppNameRegex.MatchString(s), s)
61+
require.False(t, provisioner.ValidAppSlugRegex.MatchString(s), s)
6262
}
6363
})
6464
}

provisioner/terraform/resources.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ func ConvertResources(module *tfjson.StateModule, rawGraph string) ([]*proto.Res
221221
}
222222

223223
slug := resource.Name
224-
if !provisioner.ValidAppNameRegex.MatchString(slug) {
225-
return nil, xerrors.Errorf("invalid app name, must be a valid hostname (%q, cannot contain two consecutive hyphens or start/end with a hyphen): %q", provisioner.ValidAppNameRegex.String(), slug)
224+
if !provisioner.ValidAppSlugRegex.MatchString(slug) {
225+
return nil, xerrors.Errorf("invalid app slug, must be a valid hostname (%q, cannot contain two consecutive hyphens or start/end with a hyphen): %q", provisioner.ValidAppSlugRegex.String(), slug)
226226
}
227227

228228
var attrs agentAppAttributes

0 commit comments

Comments
 (0)