GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — coder/coderd/httpapi/chatlabels.go at main · coder/coder

Expand file tree

/

chatlabels.go

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
78 lines (66 loc) · 2.15 KB
/

chatlabels.go

Copy path

File metadata and controls

78 lines (66 loc) · 2.15 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package httpapi
import (
"fmt"
"regexp"
"github.com/coder/coder/v2/codersdk"
)
const (
// maxLabelsPerChat is the maximum number of labels allowed on a
// single chat.
maxLabelsPerChat = 50
// maxLabelKeyLength is the maximum length of a label key in bytes.
maxLabelKeyLength = 64
// maxLabelValueLength is the maximum length of a label value in
// bytes.
maxLabelValueLength = 256
)
// labelKeyRegex validates that a label key starts with an alphanumeric
// character and is followed by alphanumeric characters, dots, hyphens,
// underscores, or forward slashes.
var labelKeyRegex = regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9._/-]*$`)
// ValidateChatLabels checks that the provided labels map conforms to the
// labeling constraints for chats. It returns a list of validation
// errors, one per violated constraint.
func ValidateChatLabels(labels map[string]string) []codersdk.ValidationError {
var errs []codersdk.ValidationError
if len(labels) > maxLabelsPerChat {
errs = append(errs, codersdk.ValidationError{
Field: "labels",
Detail: fmt.Sprintf("too many labels (%d); maximum is %d", len(labels), maxLabelsPerChat),
})
}
for k, v := range labels {
if k == "" {
errs = append(errs, codersdk.ValidationError{
Field: "labels",
Detail: "label key must not be empty",
})
continue
}
if len(k) > maxLabelKeyLength {
errs = append(errs, codersdk.ValidationError{
Field: "labels",
Detail: fmt.Sprintf("label key %q exceeds maximum length of %d bytes", k, maxLabelKeyLength),
})
}
if !labelKeyRegex.MatchString(k) {
errs = append(errs, codersdk.ValidationError{
Field: "labels",
Detail: fmt.Sprintf("label key %q contains invalid characters; must match %s", k, labelKeyRegex.String()),
})
}
if v == "" {
errs = append(errs, codersdk.ValidationError{
Field: "labels",
Detail: fmt.Sprintf("label value for key %q must not be empty", k),
})
}
if len(v) > maxLabelValueLength {
errs = append(errs, codersdk.ValidationError{
Field: "labels",
Detail: fmt.Sprintf("label value for key %q exceeds maximum length of %d bytes", k, maxLabelValueLength),
})
}
}
return errs
}
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.