Files
coder/coderd/util/xjson/xjson.go
T
Cian Johnston 7a9d57cd87 fix(coderd): actually wire the chat template allowlist into tools (#23626)
Problem: previously, the deployment-wide chat template allowlist was never actually wired in from `chatd.go`

- Extracts `parseChatTemplateAllowlist` into shared `coderd/util/xjson.ParseUUIDList`
- Adds `Server.chatTemplateAllowlist()` method that reads the allowlist from DB
- Passes `AllowedTemplateIDs` callback to `ListTemplates`, `ReadTemplate`, and `CreateWorkspace` tool constructors

> 🤖 Created by Coder Agents and reviewed by a human.
2026-03-25 22:15:27 +00:00

36 lines
833 B
Go

package xjson
import (
"encoding/json"
"strings"
"github.com/google/uuid"
"golang.org/x/xerrors"
)
// ParseUUIDList parses a JSON-encoded array of UUID strings
// (e.g. `["uuid1","uuid2"]`) and returns the corresponding
// slice of uuid.UUID values. An empty input (including
// whitespace-only) returns an empty (non-nil) slice.
func ParseUUIDList(raw string) ([]uuid.UUID, error) {
raw = strings.TrimSpace(raw)
if raw == "" {
return []uuid.UUID{}, nil
}
var strs []string
if err := json.Unmarshal([]byte(raw), &strs); err != nil {
return nil, xerrors.Errorf("unmarshal uuid list: %w", err)
}
ids := make([]uuid.UUID, 0, len(strs))
for _, s := range strs {
id, err := uuid.Parse(s)
if err != nil {
return nil, xerrors.Errorf("parse uuid %q: %w", s, err)
}
ids = append(ids, id)
}
return ids, nil
}