mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
7a9d57cd87
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.
36 lines
833 B
Go
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
|
|
}
|