Skip to content

Commit e96423b

Browse files
authored
Merge branch 'main' into dogfood-gateway-external
2 parents 9173f97 + 4ebf490 commit e96423b

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
if err != nil {
94-
if database.IsUniqueViolation(err, database.UniqueIndexApiKeyName) {
94+
if database.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
return false
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+
func IsForeignKeyViolation(err error, foreignKeyConstraints ...ForeignKeyConstraint) bool {
45+
var pqErr *pq.Error
46+
if errors.As(err, &pqErr) {
47+
if pqErr.Code.Name() == "foreign_key_violation" {
48+
if len(foreignKeyConstraints) == 0 {
49+
return true
50+
}
51+
for _, fc := range foreignKeyConstraints {
52+
if pqErr.Constraint == string(fc) {
53+
return true
54+
}
55+
}
56+
}
57+
}
58+
59+
return false
60+
}
61+
4062
// IsQueryCanceledError checks if the error is due to a query being canceled.
4163
func IsQueryCanceledError(err error) bool {
4264
var pqErr *pq.Error

coderd/database/foreign_key_constraint.go

Lines changed: 49 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing 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 about customizing 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-
return appURL.String()
45+
hostname := appURL.String()
46+
47+
if len(hostname) < 64 { // max length for the subdomain level
48+
return hostname
49+
}
50+
return fmt.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 := range testCases {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy