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

Commite96423b

Browse files
authored
Merge branch 'main' into dogfood-gateway-external
2 parents9173f97 +4ebf490 commite96423b

File tree

65 files changed

+1809
-692
lines changed

Some content is hidden

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

65 files changed

+1809
-692
lines changed

‎coderd/apikey.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (api *API) postToken(rw http.ResponseWriter, r *http.Request) {
9191
TokenName:tokenName,
9292
})
9393
iferr!=nil {
94-
ifdatabase.IsUniqueViolation(err,database.UniqueIndexApiKeyName) {
94+
ifdatabase.IsUniqueViolation(err,database.UniqueIndexAPIKeyName) {
9595
httpapi.Write(ctx,rw,http.StatusConflict, codersdk.Response{
9696
Message:fmt.Sprintf("A token with name %q already exists.",tokenName),
9797
Validations: []codersdk.ValidationError{{

‎coderd/database/errors.go‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,28 @@ func IsUniqueViolation(err error, uniqueConstraints ...UniqueConstraint) bool {
3737
returnfalse
3838
}
3939

40+
// IsForeignKeyViolation checks if the error is due to a foreign key violation.
41+
// If one or more specific foreign key constraints are given as arguments,
42+
// the error must be caused by one of them. If no constraints are given,
43+
// this function returns true for any foreign key violation.
44+
funcIsForeignKeyViolation(errerror,foreignKeyConstraints...ForeignKeyConstraint)bool {
45+
varpqErr*pq.Error
46+
iferrors.As(err,&pqErr) {
47+
ifpqErr.Code.Name()=="foreign_key_violation" {
48+
iflen(foreignKeyConstraints)==0 {
49+
returntrue
50+
}
51+
for_,fc:=rangeforeignKeyConstraints {
52+
ifpqErr.Constraint==string(fc) {
53+
returntrue
54+
}
55+
}
56+
}
57+
}
58+
59+
returnfalse
60+
}
61+
4062
// IsQueryCanceledError checks if the error is due to a query being canceled.
4163
funcIsQueryCanceledError(errerror)bool {
4264
varpqErr*pq.Error

‎coderd/database/foreign_key_constraint.go‎

Lines changed: 49 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/unique_constraint.go‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/httpapi/url.go‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package httpapi
22

33
import (
44
"fmt"
5+
"hash/crc32"
56
"net"
67
"regexp"
78
"strings"
@@ -18,6 +19,8 @@ var (
1819
nameRegex))
1920

2021
validHostnameLabelRegex=regexp.MustCompile(`^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`)
22+
23+
crcTable=crc32.MakeTable(crc32.IEEE)
2124
)
2225

2326
// ApplicationURL is a parsed application URL hostname.
@@ -39,7 +42,12 @@ func (a ApplicationURL) String() string {
3942
_,_=appURL.WriteString(a.WorkspaceName)
4043
_,_=appURL.WriteString("--")
4144
_,_=appURL.WriteString(a.Username)
42-
returnappURL.String()
45+
hostname:=appURL.String()
46+
47+
iflen(hostname)<64 {// max length for the subdomain level
48+
returnhostname
49+
}
50+
returnfmt.Sprintf("app-%08x",crc32.Checksum([]byte(hostname),crcTable))
4351
}
4452

4553
// ParseSubdomainAppURL parses an ApplicationURL from the given subdomain. If

‎coderd/httpapi/url_test.go‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ func TestApplicationURLString(t *testing.T) {
4242
},
4343
Expected:"8080--agent--workspace--user",
4444
},
45+
{
46+
Name:"LongAppName",
47+
URL: httpapi.ApplicationURL{
48+
AppSlugOrPort:"0123456789012345678901234567890123456789",
49+
AgentName:"agent",
50+
WorkspaceName:"workspace",
51+
Username:"user",
52+
},
53+
Expected:"app-90667f72",
54+
},
4555
}
4656

4757
for_,c:=rangetestCases {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp