Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: validate fields as per coderd#85

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall commits
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
7 changes: 6 additions & 1 deletioninternal/provider/group_resource.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -77,13 +77,18 @@ func (r *GroupResource) Schema(ctx context.Context, req resource.SchemaRequest,
"name": schema.StringAttribute{
MarkdownDescription: "The unique name of the group.",
Required: true,
Validators: []validator.String{
stringvalidator.LengthBetween(1, 36),
stringvalidator.RegexMatches(nameValidRegex, "Group names must be alpahnumeric with hyphens."),
},
},
"display_name": schema.StringAttribute{
MarkdownDescription: "The display name of the group. Defaults to the group name.",
Computed: true,
Optional: true,
Validators: []validator.String{
stringvalidator.LengthAtLeast(1),
stringvalidator.LengthBetween(1, 64),
stringvalidator.RegexMatches(displayNameRegex, "Group display names must be alphanumeric with spaces"),
},
Default: stringdefault.StaticString(""),
},
Expand Down
8 changes: 7 additions & 1 deletioninternal/provider/template_resource.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -248,12 +248,17 @@ func (r *TemplateResource) Schema(ctx context.Context, req resource.SchemaReques
Required: true,
Validators: []validator.String{
stringvalidator.LengthBetween(1, 32),
stringvalidator.RegexMatches(nameValidRegex, "Template names must be alphanumeric with hyphens."),
},
},
"display_name": schema.StringAttribute{
MarkdownDescription: "The display name of the template. Defaults to the template name.",
Optional: true,
Computed: true,
Validators: []validator.String{
stringvalidator.LengthBetween(1, 64),
stringvalidator.RegexMatches(displayNameRegex, "Template display names must be alphanumeric with spaces."),
},
},
"description": schema.StringAttribute{
MarkdownDescription: "A description of the template.",
Expand DownExpand Up@@ -394,7 +399,8 @@ func (r *TemplateResource) Schema(ctx context.Context, req resource.SchemaReques
Optional: true,
Computed: true,
Validators: []validator.String{
stringvalidator.LengthAtLeast(1),
stringvalidator.LengthBetween(1, 64),
stringvalidator.RegexMatches(templateVersionNameRegex, "Template version names must be alphanumeric with underscores and dots."),
},
},
"message": schema.StringAttribute{
Expand Down
7 changes: 7 additions & 0 deletionsinternal/provider/user_resource.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -71,11 +71,18 @@ func (r *UserResource) Schema(ctx context.Context, req resource.SchemaRequest, r
"username": schema.StringAttribute{
MarkdownDescription: "Username of the user.",
Required: true,
Validators: []validator.String{
stringvalidator.LengthBetween(1, 32),
stringvalidator.RegexMatches(nameValidRegex, "Username must be alphanumeric with hyphens."),
},
},
"name": schema.StringAttribute{
MarkdownDescription: "Display name of the user. Defaults to username.",
Computed: true,
Optional: true,
Validators: []validator.String{
stringvalidator.LengthBetween(1, 128),
},
},
"email": schema.StringAttribute{
MarkdownDescription: "Email address of the user.",
Expand Down
7 changes: 7 additions & 0 deletionsinternal/provider/util.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,10 +6,17 @@ import (
"fmt"
"os"
"path/filepath"
"regexp"

"github.com/google/uuid"
)

var (
nameValidRegex = regexp.MustCompile("^[a-zA-Z0-9]+(?:-[a-zA-Z0-9]+)*$")
templateVersionNameRegex = regexp.MustCompile(`^[a-zA-Z0-9]+(?:[_.-]{1}[a-zA-Z0-9]+)*$`)
displayNameRegex = regexp.MustCompile(`^[^\s](.*[^\s])?$`)
)

func PtrTo[T any](v T) *T {
return &v
}
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp