MCPcopy Index your code
hub / github.com/coder/coder / domainKey

Function domainKey

coderd/provisionerdserver/acquirer.go:410–437  ·  view source on GitHub ↗

domainKey generates a canonical map key for the given provisioner types and tags. It uses the null byte (0x00) as a delimiter because it is an unprintable control character and won't show up in any "reasonable" set of string tags, even in non-Latin scripts. It is important that Tags are validated

(orgID uuid.UUID, pt []database.ProvisionerType, tags Tags)

Source from the content-addressed store, hash-verified

408// string tags, even in non-Latin scripts. It is important that Tags are
409// validated not to contain this control character prior to use.
410func domainKey(orgID uuid.UUID, pt []database.ProvisionerType, tags Tags) dKey {
411 sb := strings.Builder{}
412 _, _ = sb.WriteString(orgID.String())
413 _ = sb.WriteByte(0x00)
414
415 // make a copy of pt before sorting, so that we don't mutate the original
416 // slice or underlying array.
417 pts := make([]database.ProvisionerType, len(pt))
418 copy(pts, pt)
419 slices.Sort(pts)
420 for _, t := range pts {
421 _, _ = sb.WriteString(string(t))
422 _ = sb.WriteByte(0x00)
423 }
424 _ = sb.WriteByte(0x00)
425 var keys []string
426 for k := range tags {
427 keys = append(keys, k)
428 }
429 slices.Sort(keys)
430 for _, k := range keys {
431 _, _ = sb.WriteString(k)
432 _ = sb.WriteByte(0x00)
433 _, _ = sb.WriteString(tags[k])
434 _ = sb.WriteByte(0x00)
435 }
436 return dKey(sb.String())
437}
438
439// acquiree represents a specific client of Acquirer that wants to acquire a job
440type acquiree struct {

Callers 2

AcquireJobMethod · 0.85
wantMethod · 0.85

Calls 3

dKeyTypeAlias · 0.85
WriteStringMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected