Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
fixup! feat: add slug property to app, use in URLs
  • Loading branch information
deansheather committed Oct 17, 2022
commit e6ddf3c358cd2a1c401b1c2892a332ccb2748d41
4 changes: 2 additions & 2 deletions coderd/provisionerdaemons.go
Original file line number Diff line number Diff line change
Expand Up @@ -814,8 +814,8 @@ func insertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
if slug == "" {
return xerrors.Errorf("app must have a slug or name set")
}
if !provisioner.ValidAppNameRegex.MatchString(slug) {
return xerrors.Errorf("app slug %q does not match regex %q", slug, provisioner.ValidAppNameRegex.String())
if !provisioner.ValidAppSlugRegex.MatchString(slug) {
return xerrors.Errorf("app slug %q does not match regex %q", slug, provisioner.ValidAppSlugRegex.String())
}

health := database.WorkspaceAppHealthDisabled
Expand Down
14 changes: 0 additions & 14 deletions provisioner/appname.go

This file was deleted.

15 changes: 15 additions & 0 deletions provisioner/appslug.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package provisioner

import "regexp"

var (
// ValidAppSlugRegex is the regex used to validate the slug of a coder_app
// resource. It must be a valid hostname and cannot contain two consecutive
// hyphens or start/end with a hyphen.
//
// This regex is duplicated in the terraform provider code, so make sure to
// update it there as well.
//
// There are test cases for this regex in appslug_test.go.
ValidAppSlugRegex = regexp.MustCompile(`^[a-z0-9](-?[a-z0-9])*$`)
)
6 changes: 3 additions & 3 deletions provisioner/appname_test.go → provisioner/appslug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/coder/coder/provisioner"
)

func TestValidAppNameRegex(t *testing.T) {
func TestValidAppSlugRegex(t *testing.T) {
t.Parallel()

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

for _, s := range validStrings {
require.True(t, provisioner.ValidAppNameRegex.MatchString(s), s)
require.True(t, provisioner.ValidAppSlugRegex.MatchString(s), s)
}
})

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

for _, s := range invalidStrings {
require.False(t, provisioner.ValidAppNameRegex.MatchString(s), s)
require.False(t, provisioner.ValidAppSlugRegex.MatchString(s), s)
}
})
}
4 changes: 2 additions & 2 deletions provisioner/terraform/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ func ConvertResources(module *tfjson.StateModule, rawGraph string) ([]*proto.Res
}

slug := resource.Name
if !provisioner.ValidAppNameRegex.MatchString(slug) {
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)
if !provisioner.ValidAppSlugRegex.MatchString(slug) {
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)
}

var attrs agentAppAttributes
Expand Down
Loading